Android NDK + NEON configuration process and simple example in Ubuntu 32, androidndk

Source: Internet
Author: User

Android NDK + NEON configuration process and simple example in Ubuntu 32, androidndk

1. Use VMware to install Ubuntu13.10 32-bit Virtual Machine on 64-bit Windows 7;

2. Slave nodes;

3. Copy android-ndk32-r10-linux-x86.tar.bz2 to the/home/spring/NEON folder of Ubuntu and decompress the package;

4. Configure environment variables: Enter sudovi/etc/profile on the terminal, open the profile file, and add:

Export NDKROOT =/home/spring/NEON/android-ndk-r10 (Note: absolute path)

Export PATH = $ NDKROOT: $ PATH

5. Save the profile file and restart Ubuntu;

6. Input echo $ PATH, there will be/home/spring/NEON/android-ndk-r10;

7. Enter ndk-build to display information such as AndroidNDK. This indicates that the NDK is successfully configured;

8. Install arm-linux-gcc (arm-based cross-compiling tool for linux platform): Download arm-linux-gcc-4.4.3-20100728.tar.gz from the http://www.arm9.net/download.asp;

9. Copy arm-linux-gcc-4.4.3-20100728.tar.gz to the/home/spring/NEON folder of Ubuntu and decompress it. tarxvzf arm-linux-gcc-4.4.3-20100728.tar.gz

10. Configure environment variables: Enter sudo vi/etc/profile on the terminal to open the profile file, and add: exportPATH = $ PATH: /home/spring/NEON/opt/FriendlyARM/toolschain/4.4.3/bin to save the profile;

11. Restart Ubuntu and enter arm-linum-gcc-v on the terminal. If gcc version 4.4.3 and other information are displayed, the configuration is successful.

Sample Code (http://hilbert-space.de /? P = 22) test. cpp:

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);  }}void neon_convert (uint8_t * __restrict dest, uint8_t * __restrict src, int n){  int i;  uint8x8_t rfac = vdup_n_u8 (77);  uint8x8_t gfac = vdup_n_u8 (151);  uint8x8_t bfac = vdup_n_u8 (28);  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);    temp = vmlal_u8 (temp,rgb.val[1], gfac);    temp = vmlal_u8 (temp,rgb.val[2], bfac);    result = vshrn_n_u16 (temp, 8);    vst1_u8 (dest, result);    src  += 8*3;    dest += 8;  }}

12. Run the command: arm-linux-gcc-g-c-OS-fPIC-mfloat-abi = softfp-mfpu = neon test. cpp.

Ar-r libtest [android]. a *. o successfully generates the libtest [android]. a static library.

 

 

Another method is to directly use Android-NDK without installing arm-linux-gcc. The procedure is as follows:

1. Go to step 2;

2. Add environment variables: Enter sudovi/etc/profile on the terminal, open the profile file, and add:

Export NDKBIN =/home/spring/NEON/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin (Note: absolute path)

Export PATH = $ NDKBIN: $ PATH

3. Save the profile file and restart Ubuntu;

4. Input echo $ PATH with/home/spring/NEON/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin

5. compile test. cpp Code: arm-linux-androideabi-gcc-I/home/spring/NEON/android-ndk-r10/platforms/android-9/arch-arm/usr/include-c-OS-mfloat-abi = softfp-mfpu = neon test. cpp

Ar-r libtest [android]. a *. o successfully generates the libtest [android]. a static library.

Android android-ndk-r4-windows Configuration
How to Use assembly language in Android

I am using the latest development tool Android4.0, and NDK also supports 4.0. This NDK is obviously different from the old version. Because I am using Mac OS X, it is much easier to configure it than to shake it down. You don't need to install any third-party tools, so you can directly use the NDK you downloaded. First, set the target path -- enter the root directory of the NDK in your Terminal, and then press NDK_PROJECT_PATH = "<project path you want to compile> ". Press enter, and then enter export NDK_PROJECT_PATH to press Enter. Note that the path after NDK_PROJECT_PATH = needs to be enclosed in quotation marks. Otherwise, it is invalid. Because NDK supports only the ARMv5 to ARMv5TE architectures by default, there are two ways to use more advanced features: 1. You have a way to change the value of TARGET_ARCH_ABI to a armeabi-v7a, I tried it myself, wood has succeeded. So you can use the second method, more simple and convenient: 2, in your NDK directory, find the toolchains, and then find the arm-linux-androideabi-x.y.z directory, you can find the setup. mk file. Find-march = armv7-a, remove the above Shenma # ifdef, the # endif below are also deleted. This ensures that the compiler uses ARMv7A for compilation. After completing the above operations, we can first write the assembly in the simplest way, that is, inline assembly -- static int my_thumb (int dummy) {_ asm _ ("movw r0, #1001 \ t \ n "" movw r12, #2020 \ t \ n "" add r0, r0, r12 \ t \ n "" bx lr "); return dummy ;} jstring evaluate (JNIEnv * env, jobject thiz) {my_thumb (0); return (* env)-> NewStringUTF (env, "Hello from JNI! ");} The above Code is actually modified based on the" hello-jni "project that comes with NDK. Finally, you can use ndk-build to compile the program successfully. The above code is compiled by the compiler using Thumb/Thumb-2 by default. Therefore, all the commands written in the inline assembly are the Thumb code. The following describes how to use ARM code and the NEON instruction set. First, modify LOCAL_SRC_FILES in your Android. mk and add the. neon suffix after the source file name, such as LOCAL_SRC_FILES: = hello-jni.c to LOCAL_SRC_FILES: = hello-jni.c.neon. Note that you can modify the value of LOCAL_SRC_FILES without modifying the source file name. Then we add new variables to instruct arm gcc to use the ARM instruction set to compile -- LOCAL_ARM_MODE: = arm. Let's modify the code: static int my_arm (int dummy) {_ asm _ ("movw r0, #1001 \ t \ n" "movw r12, #2020 \ t \ n "" add r0, r0, r12 \ t \ n "&...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.