【发布时间】:2015-08-09 14:35:37
【问题描述】:
我正在调整一些源文件以在选定位置使用内联汇编。一个地方是轮换,我看到 NDK 工具生成了 4 到 6 条指令。 (相关,见Near constant time rotate that does not violate the standards)。
当我尝试使用类似的东西时:
template<> inline word32 rotlFixed<word32>(word32 x, unsigned int y)
{
assert(y < sizeof(word32));
__asm__ ("ror %0, %1" : "+g" (x) : "I" ((unsigned char)(32-y)));
return x;
}
template<> inline word32 rotrFixed<word32>(word32 x, unsigned int y)
{
assert(y < sizeof(word32));
__asm__ ("ror %0, %1" : "+g" (x) : "I" ((unsigned char)y));
return x;
}
结果:
$ make -f GNUmakefile-cross
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -mfloat-abi=softfp -mfpu=vfpv3-d16 \
-mthumb --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-arm \
-I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -c 3way.cpp
.../ccwZw2eI.s: Assembler messages:
.../ccwZw2eI.s:2123: Error: ror #imm not supported -- `ror r0,#16'
.../ccwZw2eI.s:2133: Error: ror #imm not supported -- `ror r3,#24'
.../ccwZw2eI.s:2847: Error: ror #imm not supported -- `ror r6,#10'
...
因此编译器不支持立即 8 版本的旋转。它的损失并不大,因为有这么多可用的寄存器(相对而言)。但我希望能够确定这种情况,因为 rotlFixed 和 rotrFixed 应该使用指令的直接版本。
现在,寻找可以确定情况的关键点:
$ arm-linux-androideabi-cpp -dM < /dev/null | grep -i android
#define __ANDROID__ 1
$ arm-linux-androideabi-cpp -dM < /dev/null | grep -i aosp
$ arm-linux-androideabi-cpp -dM < /dev/null | grep -i ndk
$
NDK 工具链似乎只提供__ANDROID__。我相信其他原生移动工具链也定义了它,所以我不能使用它。而且没有__ANDROID_CC__ 或类似的。
如何检测 Android NDK 工具链?
【问题讨论】:
标签: android android-ndk c-preprocessor