2012-12-08 50 views
2

NEON编译代码时,下面是简单的二值化功能错误在Android

void binarize(void *output, const void *input, int begin, int end, uint8_t threshold) { 
#ifdef __ARM_NEON__ 
    uint8x16_t thresholdVector = vdupq_n_u8(threshold); 
    uint8x16_t highValueVector = vdupq_n_u8(255); 
    uint8x16_t* __restrict inputVector = (uint8x16_t*)input; 
    uint8x16_t* __restrict outputVector = (uint8x16_t*)output; 
    for (; begin < end; begin += 16, ++inputVector, ++outputVector) { 
     *outputVector = (*inputVector > thresholdVector) & highValueVector; 
    } 
#endif 
} 

它正常工作在iOS。然而,当我编译它为Android它给了我一个错误:

error: invalid operands of types 'uint8x16_t {aka __vector(16) __builtin_neon_uqi}' and 'uint8x16_t {aka __vector(16) __builtin_neon_uqi}' to binary 'operator>'

我使用此标志在Android.mk启用NEON:

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 
     LOCAL_ARM_NEON := true 
endif 

回答

3

的差异主要是因为不同的编译器。对于iOS,您正在使用Clang进行编译,但对于Android,您正在使用GCC编译代码(除非您覆盖默认设置)。

GCC对于矢量类型更加愚蠢,不能将它们与C/C++运算符(如>&)一起使用。所以,你有两种基本的选择:

  1. 尝试从最新的Android NDK R8C

    NDK_TOOLCHAIN_VERSION=clang3.1Application.mk这铿锵编译。

  2. 改写明确使用operator >vld1q_u8负载,vst1q_u8店面,vcgtq_u8vandq_u8代码为operator &
+0

没有尝试的第一选择,但第二个伟大工程。谢谢! – Max