【问题标题】:Errors when compiling NEON code on Android在 Android 上编译 NEON 代码时出错
【发布时间】:2012-12-08 09:30:08
【问题描述】:

这里是简单的二值化函数

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 编译它时,它给了我一个错误:

错误:'uint8x16_t {aka __vector(16) 类型的无效操作数 __builtin_neon_uqi}' 和 'uint8x16_t {aka __vector(16) __builtin_neon_uqi}' 到二进制 'operator>'

我在 Android.mk 中使用这个标志来启用 NEON:

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

【问题讨论】:

    标签: android gcc android-ndk neon


    【解决方案1】:

    不同之处在于不同的编译器。对于 iOS,您使用 Clang 进行编译,但对于 Android,您使用 GCC 构建代码(除非您覆盖默认值)。

    GCC 对向量类型更加愚蠢,不能将它们与 &gt;&amp; 等 C/C++ 运算符一起使用。所以你有两个基本的选择:

    1. 尝试使用来自最新 Android NDK r8c 的 Clang 进行编译

      为此,请将NDK_TOOLCHAIN_VERSION=clang3.1 发送到您的Application.mk

    2. 使用vld1q_u8 用于加载,vst1q_u8 用于存储,vcgtq_u8 用于operator &gt;vandq_u8 用于operator &amp;,显式重写您的代码

    【讨论】:

    • 没有尝试第一个选项,但第二个效果很好。谢谢!
    猜你喜欢
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多