Android NDK(ARM开发)使用NEON优化 - Fla

Android NDK(ARM开发)使用NEON优化

Fla posted @ 2013年4月05日 11:58 in Android&NDK&ARM with tags ARM NEON NDK , 143307 阅读

从CSDN博客搬家:

http://blog.csdn.net/luofl1992/article/details/8756423

http://blog.csdn.net/luofl1992/article/details/8759145

额外可以参考这篇文章:http://blog.csdn.net/ce123/article/details/8209702 (排版比较舒服)

在进行Android开发时,一般考虑加速某些算法处理速率时,需要使用NDK进行开发,

为了进一步加速程序执行速率,还可以进行汇编级别的优化。

比如采用 NEON 技术进行代码的优化,以实现模块处理效率的成倍增长。

在C/C++中使用内联汇编的用法如下:

    asm(  
    "ADD R0,R0,#1 \n\t"       // 使R0寄存器值增加1,后面加换行符和制表符是为了汇编代码的美观,其中有多条指令时 换行符是必须的  
    "SUB R0,R0,#1 "           // 使R0寄存器的值减少1  
    );  

然后是如何在NDK中编译使用这种指令,需要修改Android.mk和Application.mk两个文件:

LOCAL_PATH := $(call my-dir)    
include $(CLEAR_VARS)    
# 这里填写要编译的源文件路径,这里只列举了一部分    
LOCAL_SRC_FILES := NcHevcDecoder.cpp JNI_OnLoad.cpp TAppDecTop.cpp    
# 默认包含的头文件路径    
LOCAL_C_INCLUDES := \    
$(LOCAL_PATH) \    
$(LOCAL_PATH)/..    
# -g 后面的一系列附加项目添加了才能使用 arm_neon.h 头文件 -mfloat-abi=softfp -mfpu=neon 使用 arm_neon.h 必须
LOCAL_CFLAGS := -D__cpusplus -g -mfloat-abi=softfp -mfpu=neon -march=armv7-a -mtune=cortex-a8
LOCAL_LDLIBS := -lz -llog
TARGET_ARCH_ABI :=armeabi-v7a
LOCAL_ARM_MODE := arm 
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)    
# 采用NEON优化技术    
LOCAL_ARM_NEON := true    
endif
LOCAL_MODULE := avcodecinclude $(BUILD_STATIC_LIBRARY) 
include $(BUILD_SHARED_LIBRARY)

下面是Application.mk,需要指定编译的目标平台类型:

APP_PROJECT_PATH := $(call my-dir)/..    
APP_PLATFORM := android-10    
APP_STL := stlport_static    
APP_ABI := armeabi-v7a 
APP_CPPFLAGS += -fexceptions     

其中APP_ABI这句指定了编译的目标平台类型,可以针对不同平台进行优化。   
当然这样指定了之后,就需要相应的设备支持NEON指令。    
 
我的一个NDK应用,在使用上述配置之后,即NEON优化等,程序的性能提升了近一倍。  
系统的处理延时由原来的 95ms左右降低到了 51ms。  
后续可以使用NEON库进一步优化 NDK 程序代码,实现更加优化的结果。

PS:参考的文章有如下几篇,可能跟我的平台有所不同,所以我都不能完全照搬使用:

http://blog.csdn.net/wuzhong325/article/details/8277703

http://blog.csdn.net/wuzhong325/article/details/8277718

http://blog.chinaunix.net/uid-20715001-id-1234726.html

最后的是NEON优化示例:http://hilbert-space.de/?p=22

1、未使用NEON优化的代码

    void reference_convert (uint8_t * __restrict dest, uint8_t * __restrict src, int n)    
    {    
      int i;    
      for (i=0; i<n; i++)    
      {    
        int r = *src++; // load red    
        int g = *src++; // load green    
        int b = *src++; // load blue     
       
        // build weighted average:    
        int y = (r*77)+(g*151)+(b*28);    
       
        // undo the scale by 256 and write to memory:    
        *dest++ = (y>>8);    
      }    
    }   

2、使用NEON进行优化的代码

    void neon_convert (uint8_t * __restrict dest, uint8_t * __restrict src, int n)    
    {    
      int i;    
      uint8x8_t rfac = vdup_n_u8 (77);       // 转换权值  R    
      uint8x8_t gfac = vdup_n_u8 (151);    // 转换权值  G    
      uint8x8_t bfac = vdup_n_u8 (28);      // 转换权值  B    
      n/=8;    
       
      for (i=0; i<n; i++)    
      {    
        uint16x8_t  temp;    
        uint8x8x3_t rgb  = vld3_u8 (src);    
        uint8x8_t result;    
       
        temp = vmull_u8 (rgb.val[0],      rfac);       // vmull_u8 每个字节(8bit)对应相乘,结果为每个单位2字节(16bit)    
        temp = vmlal_u8 (temp,rgb.val[1], gfac);  // 每个比特对应相乘并加上    
        temp = vmlal_u8 (temp,rgb.val[2], bfac);    
       
        result = vshrn_n_u16 (temp, 8);  // 全部移位8位    
        vst1_u8 (dest, result);   // 转存运算结果    
        src  += 8*3;     
        dest += 8;    
      }    
    }    

3、汇编优化

    // 这里针对生成的目标汇编代码进一步作了优化,优化的代码如下:    
     convert_asm_neon:    
       
          # r0: Ptr to destination data    
          # r1: Ptr to source data    
          # r2: Iteration count:    
       
            push        {r4-r5,lr}    
          lsr         r2, r2, #3    
       
          # build the three constants:    
          mov         r3, #77    
          mov         r4, #151    
          mov         r5, #28    
          vdup.8      d3, r3    
          vdup.8      d4, r4    
          vdup.8      d5, r5    
       
      .loop:    
       
          # load 8 pixels:    
          vld3.8      {d0-d2}, [r1]!    
       
          # do the weight average:    
          vmull.u8    q3, d0, d3    
          vmlal.u8    q3, d1, d4    
          vmlal.u8    q3, d2, d5    
       
          # shift and store:    
          vshrn.u16   d6, q3, #8    
          vst1.8      {d6}, [r0]!    
       
          subs        r2, r2, #1    
          bne         .loop    
       
          pop         { r4-r5, pc }    

最后的结果对比:

  1. C-version:             15.1 cycles per pixel.    
  2. NEON-version:       9.9 cycles per pixel.    
  3. Assembler:             2.0 cycles per pixel. 
PS:欢迎访问本人的CSDN博客:http://blog.csdn.net/luofl1992
cleaning services in 说:
Oct 24, 2019 09:11:12 PM

The Maid Company usually offers many workers that function in groups. Some from the companies tend to be franchises that have specially created products as well as equipment in order to professionally clean your home in a good environmentally-friendly method. Companies provide simple to schedule, dependable cleaning that is usually bonded as well as insured.

starliteshoppingmall 说:
Apr 20, 2020 06:34:53 PM

A local mall is a new building as well as several complexes that variety a searching complex. Within this shopping sophisticated, there are generally several merchandisers manifested, with interconnecting walk strategies allow your mall people to move derived from one of shopping unit on the other quickly.

shopping-batalha.com 说:
Apr 20, 2020 06:35:12 PM

Does one do on-line shopping your old-fashioned means? Do you have search engines to discover the item you need? Shopping tendencies have revolutionized along with evolved to an alternative level while using phenomenon involving social searching networks.

elimperiotravel.com 说:
Apr 20, 2020 06:35:38 PM

Take a trip for buy and sell was a crucial feature since the start of civilisation. The vent at Lothal was a crucial centre involving trade relating to the Indus vly civilisation plus the Sumerian civilisation.

travelling2peru.com 说:
Apr 20, 2020 06:35:58 PM

Common travel cope sites. Searching and come across travel works with carrentals.com, Orbiz, Delta Air Lines, Travelocity, Expedia, travel.yahoo.com, travelchannel.com, travel.nytimes.com, cnn.com, and County Visitors Bureaus. For US citizen traveling abroad, try travel.state.gov..

rapidity-news.com 说:
Apr 20, 2020 06:36:19 PM

Looking at the cardstock online along with watching 24-hour reports sites is becoming more and more popular. For the reason that it can be cheaper so you get additional news. You will see what is happening on the globe, as the idea happens.

monthly maid service 说:
May 05, 2020 07:41:19 PM

I tell you to analysis any details you will want to include including particular guests to get greeted as well as people you'll want to thank regarding the bride in your preparation. Research correct quotes or possibly a poem you would want to include as part of your maid involving honor conversation well before hand. Remember you'll not have time in the wedding 1 week for these kind of tasks as you may be too occupied fulfilling your current other house maid of respect duties.

construction paintin 说:
May 05, 2020 07:41:32 PM

Nearly all good painters discover how to do over just a fairly easy paint employment. For case in point, they ought to know a number of common approaches, such while sponge artwork or diminishing the paint using areas in order that it looks classic. Find out and about what your current painter knows when you hire one in order that you are sure to have the look you desire.

part time maids in d 说:
Jun 08, 2021 04:35:15 PM

You should make a thing very transparent that disinfection may only work if for example the specific court surfaces are sparkling. So, invest your time and efforts in housecleaning, first. Afterward, you can carryout the disinfection operation. Whether there may anyone poorly or not at your house, you really have to regularly sparkling highly-touched court surfaces. Because bacteria can stay for some time on really difficult surfaces.

maid agency dubai 说:
Sep 18, 2021 01:08:26 PM

If you need to your surface to reek good, available for you a refresher. It's always easily in the industry. The other sorts of thing you can perform is to earn your personally own home-made refresher. This isn't so extravagant. All all the ingredients include your place. You only just need fluids, white white vinegar, baking soft drink and lube.

seo service UK 说:
Nov 01, 2023 06:33:57 PM

Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know

레모나벳 이벤트 说:
Nov 29, 2023 01:37:58 PM

My spouse and am enjoy your blog and locate the vast majority of your post’s to be able to be what exactly I’m searching for. can you present guest writers to compose content for you? We wouldn’t mind producing the post or elaborating upon some the subjects jots down concerning here. Once again, awesome weblog!

메이저사이트 说:
Nov 29, 2023 01:43:00 PM

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

원벳원 도메인 说:
Nov 29, 2023 02:39:41 PM

Pleased to meet up with you! My title is Shonda and I enjoy it. Doing magic is what she enjoys performing. He is at the moment a production and distribution officer but he strategies on modifying it. Some time in the earlier he chose to stay in Louisiana.

메이저사이트 说:
Nov 29, 2023 03:00:01 PM

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

토크리 说:
Nov 29, 2023 03:11:07 PM

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.

안전토토사이트 목록 说:
Nov 29, 2023 03:12:26 PM

Hey would you mind sharing which blog platform you’re working with? I’m planning to start my own blog soon but I’m having a difficult time selecting between BlogEngine/Wordpress/B2evolution a

메이저놀이터추천 说:
Nov 29, 2023 03:18:08 PM

Awesome site you have here but I was curious if you knew of any message boards that cover the same topics talked about here? I’d really like to be a part of group where I can get opinions from other experienced people that share the same interest. If you have any suggestions, please let me know. Bless you!

안전공원 说:
Nov 29, 2023 03:54:52 PM

Excellent post. I was checking continuously this blog and I’m impressed! Very helpful information specially the last part :) I care for such information a lot. I was looking for this certain information for a long time. Thank you and best of luck. 

꽁머니홍보 说:
Nov 29, 2023 03:55:21 PM

I think this is an instructive post and it is extremely valuable and proficient. along these lines, I might want to thank you for the endeavors you have made recorded as a hard copy this article. I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. .

토토 블랙 조회 说:
Nov 29, 2023 04:21:40 PM

Confusing information, immense and outlandish structure, as offer especially finished with sharp examinations and thoughts, heaps of striking information and inspiration, the two of which I require, because of offer such an incredible information here

먹튀갤보증업체 说:
Nov 29, 2023 04:22:45 PM

"Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first I think this is an enlightening post and it is exceptionally helpful and educated. in this manner. I might want to thank you for the endeavors you have made recorded as a hard copy this article.
"

먹튀슈퍼맨 도메인 说:
Nov 29, 2023 04:33:34 PM

Hello there, There’s no doubt that your site could be having web browser compatibility problems. Whenever I take a look at your site in Safari, it looks fine however, when opening in Internet Explorer, it has some overlapping issues. I just wanted to provide you with a quick heads up! Aside from that, excellent blog!

라이브 카지노 게임 서비스 说:
Nov 29, 2023 04:40:36 PM

We are playground guard without advertising agency of Toto site.Please come to Playground Guard and enjoy betting on various

해외토토사이트 说:
Nov 29, 2023 05:02:05 PM

Hello there, There’s no doubt that your site could be having web browser compatibility problems. Whenever I take a look at your site in Safari, it looks fine however, when opening in Internet Explorer, it has some overlapping issues. I just wanted to provide you with a quick heads up! Aside from that, excellent blog!

꽁머니토토사이트 说:
Nov 29, 2023 05:04:22 PM

Your post offers confirmed beneficial to me personally. It’s very informative and you’re simply certainly extremely knowledgeable in this region. You have opened up my eye to be able to various views on this particular matter together with interesting and strong content.

토지노 도메인 说:
Nov 29, 2023 05:08:11 PM

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

우리카지노 说:
Nov 29, 2023 05:25:31 PM

Pleased to meet up with you! My title is Shonda and I enjoy it. Doing magic is what she enjoys performing. He is at the moment a production and distribution officer but he strategies on modifying it. Some time in the earlier he chose to stay in Louisiana.

먹튀검증커뮤니티 说:
Nov 29, 2023 05:59:31 PM

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

온라인슬롯머신 说:
Nov 29, 2023 06:03:03 PM

Pleased to meet up with you! My title is Shonda and I enjoy it. Doing magic is what she enjoys performing. He is at the moment a production and distribution officer but he strategies on modifying it. Some time in the earlier he chose to stay in Louisiana.

에그벳 说:
Nov 29, 2023 06:15:21 PM

The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

파라오카지노도메인 说:
Nov 29, 2023 06:15:45 PM

"Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first I think this is an enlightening post and it is exceptionally helpful and educated. in this manner. I might want to thank you for the endeavors you have made recorded as a hard copy this article.
"

먹튀폴리스 说:
Nov 29, 2023 06:28:26 PM

Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!! ntegrate AI-driven characters and dialogues to enhance user experiences in gaming applications

카지노보증사이트 说:
Nov 29, 2023 06:44:55 PM

"I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.Shocking post I should state and appreciative for the information. Bearing is clearly a sticky subject. In any case, is still among the focal subjects of our shot. I respect your post and envision more
"

꽁머니사이트 说:
Nov 29, 2023 07:02:12 PM

It's strikingly a marvelous and satisfying piece of information. I am satisfied that you in a general sense enabled this strong data to us. On the off chance that it's not all that much burden stay us sway forward thusly. Thankful to you for sharing

가입쿠폰 说:
Nov 29, 2023 07:06:25 PM

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

카지노사이트 说:
Nov 29, 2023 07:06:53 PM

Appreciative for the strengthening on the web diary posting! Fundamentally put your blog segment to my most esteemed blog list and will channel forward for additional updates. Basically expected to record a word to offer imperative because of you for those incredible tips.

메리트카지노 说:
Nov 29, 2023 07:25:06 PM

Nice blog right here! Additionally your website loads up fast! What web host are you the use of? Can I get your associate hyperlink in your host? I desire my web site loaded up as quickly as yours I feel a lot more people need to read this, very good info

먹튀검증 说:
Nov 29, 2023 07:37:15 PM

There are a few fascinating points at some point in this post but I do not determine if I see all of them center to heart. There is some validity but I most certainly will take hold opinion until I take a look at it further. Good write-up , thanks so we want much more! Added to FeedBurner also

사설토토검증 说:
Nov 29, 2023 07:45:19 PM

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

메이저공원추천 说:
Nov 29, 2023 07:49:51 PM

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.

먹튀폴리스역사 说:
Nov 29, 2023 08:04:46 PM

Everyone loves many of the discussions, I actually experienced, I'd prefer additional information in regards to this, for the reason that it is awesome., With thanks to get spreading Why not remain this unique amazing give good results not to mention I just await further with the fantastic blog posts

안전사이트 说:
Nov 29, 2023 08:12:43 PM

his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

단폴되는사이트 说:
Nov 29, 2023 08:21:20 PM

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

단폴사이트가입 说:
Nov 29, 2023 08:27:08 PM

Confusing information, immense and outlandish structure, as offer especially finished with sharp examinations and thoughts, heaps of striking information and inspiration, the two of which I require, because of offer such an incredible information here

스포츠중계사이트순위 说:
Nov 29, 2023 08:44:35 PM

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

소액결제현금화 说:
Jan 15, 2024 09:56:07 PM

Happy with the website and the team.

스포츠중계 说:
Jan 15, 2024 10:23:42 PM

Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they've added something worthwhile to the world wide web! 

카지노사이트 说:
Jan 15, 2024 10:42:42 PM

"Appreciation to my father who shared with me concerning this web site, this weblog is genuinely remarkable.

"

카지노 올인토토 说:
Jan 16, 2024 04:10:28 PM

That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more

카지노사이트 说:
Jan 16, 2024 04:26:10 PM

Glad to see this kind of brilliant and very interesting informative post.

카지노뱅크 说:
Jan 16, 2024 04:52:56 PM

Wow, excellent post. I'd like to draft like this too — taking time and real hard work to make a great article. This post has encouraged me to write some posts that I am going to write soon.

안전놀이터 说:
Jan 22, 2024 04:35:20 PM

온라인 카지노 커뮤니티 온카허브 입니다. 온카허브는 카지노 먹튀 사이트들과 안전한 카지노 사이트 정보를 공유하고 있습니다. 카지노 먹튀검증 전문팀을 자체적으로 운영함으로써 철저한 검증을 진행하고 있습니다.

메이저사이트 说:
Jan 22, 2024 04:47:25 PM

온라인 카지노 커뮤니티 온카허브 입니다. 온카허브는 카지노 먹튀 사이트들과 안전한 카지노 사이트 정보를 공유하고 있습니다. 카지노 먹튀검증 전문팀을 자체적으로 운영함으로써 철저한 검증을 진행하고 있습니다.
https://oncahub24.com/

바카라 说:
Jan 24, 2024 11:38:44 AM

바카라 바카라사이트 우리카지노 카지노는 바카라, 블랙잭, 룰렛 및 슬롯 등 다양한 게임을 즐기실 수 있는 공간입니다. 게임에서 승리하면 큰 환호와 함께 많은 당첨금을 받을 수 있고, 패배하면 아쉬움과 실망을 느끼게 됩니다.

하노이 밤문화 说:
Jan 24, 2024 12:18:41 PM

하노이 꼭 가봐야 할 베스트 업소 추천 안내 및 예약, 하노이 밤문화 에 대해서 정리해 드립니다. 하노이 가라오케, 하노이 마사지, 하노이 풍선바, 하노이 밤문화를 제대로 즐기시기 바랍니다. 하노이 밤문화 베스트 업소 요약 베스트 업소 추천 및 정리.

먹튀검증 说:
Jan 25, 2024 03:01:19 PM

No.1 먹튀검증 사이트, 먹튀사이트, 검증사이트, 토토사이트, 안전사이트, 메이저사이트, 안전놀이터 정보를 제공하고 있습니다. 먹튀해방으로 여러분들의 자산을 지켜 드리겠습니다. 먹튀검증 전문 커뮤니티 먹튀클린만 믿으세요!!

베트남 밤문화 说:
Jan 25, 2024 04:25:57 PM

베트남 남성전용 커뮤니티❣️ 베트남 하이에나 에서 베트남 밤문화를 추천하여 드립니다. 베트남 가라오케, 베트남 VIP마사지, 베트남 이발관, 베트남 황제투어 남자라면 꼭 한번은 경험 해 봐야할 화끈한 밤문화로 모시겠습니다. 

블록체인개발 说:
Apr 23, 2024 06:20:24 PM

블록체인개발 코인지갑개발 IT컨설팅 메스브레인팀이 항상 당신을 도울 준비가 되어 있습니다. 우리는 마음으로 가치를 창조한다는 철학을 바탕으로 일하며, 들인 노력과 시간에 부흥하는 가치만을 받습니다. 고객이 만족하지 않으면 기꺼이 환불해 드립니다.
https://xn--539awa204jj6kpxc0yl.kr/

Cryto exchange 说:
Jun 03, 2024 12:19:42 PM

The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/

Cryto exchange 说:
Jun 07, 2024 06:07:00 PM

The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee