Search code examples
android-ndkneon

use of undeclared identifier 'vpaddq_u8'


I am using neon in android-ndk, but I'm facing an problem as topic title.
I download hello-neon demo here : https://github.com/googlesamples/android-ndk this is a demo shows how to use neon in android ndk. and I add this code like this :

#include <arm_neon.h>
uint16_t neonTest(uint8x16_t input){
    uint8x16_t minput = vandq_u8(input,input);
    uint8x16_t tmp = vpaddq_u8(minput,minput);
    tmp = vpaddq_u8(tmp,tmp);
    tmp = vpaddq_u8(tmp,tmp);
    return vgetq_lane_u16(vreinterpretq_u16_u8(tmp),0);
}

The most strange thing is : both vandq_u8 & vpaddq_u8 are include from arm_neon.h , but the exception trace is :

error: use of undeclared identifier 'vpaddq_u8'

It means 'vandq_u8' is include but 'vpaddq_u8' isn't . but they are in same header file .

How should I resolve this problem?


Solution

  • I believe the issue here is that you are compiling the same code not only for ARM, but also for x86.

    The NDK has got a version of arm_neon.h also for x86, which has got an incomplete set of the ARM intrinsics, which emulate them using different SSE intrinsics. This allows using the same SIMD code even for x86, but won't get optimal performance. (Whether this even is desireable, or whether it actually does give you better performance than plain serial code, is highly disputed.) This header does contain vandq_u8, but is lacking vpaddq_u8.

    So, make sure to not compile the code containing NEON intrinsics for x86 (remove x86 and x86_64 from ndk.abiFilters in build.gradle). Alternatively, use ifdefs to only use this code when targeting ARM/AArch64, and replace it with a fallback for other architectures.