[英]Need for -xarch=XXX when an instruction is used in byte code form?
I have a x86 RDRAND implementation like below. 我有一个如下的x86 RDRAND实现。 I have a similar implementation for RDSEED. 对于RDSEED,我也有类似的实现。
inline void RDRAND32(void* output)
{
#if defined(HAVE_GCC_RDRAND_ASM)
__asm__
(
"1:\n"
".byte 0x0f, 0xc7, 0xf0;\n"
"jnc 1b;\n"
: "=a" (*(uint32_t*)output)
: : "cc"
);
#endif
}
The byte codes emitted are rdrand eax
and a capable processor happily consumes them. 发出的字节码是rdrand eax
,有能力的处理器会愉快地消耗它们。 Sun Studio 12.1 and above supports GCC inline assembly and also consumes them. Sun Studio 12.1和更高版本支持GCC内联汇编,也可以使用它们。
The Sun docs say I need -xarch=avx_i
for the ISA that provides RDRAND (and -xarch=avx2_i
for RDSEED). 太阳文档说我需要-xarch=avx_i
对提供RDRAND(和ISA -xarch=avx2_i
为RDSEED)。 Also see Sun Studio 12.6 | 另请参见Sun Studio 12.6。 -xarch Flags for x86 . x86的-xarch标志 。
Do I still need to add -xarch=avx_i
to my linker flags for RDRAND
in this use case? 我仍然需要添加-xarch=avx_i
我的连接标志的RDRAND
在这种使用情况?
In case it matters we guard CPU features at runtime and use a Mapfile to lower the ISA (because runtime paths are guarded): 如果很重要,我们会在运行时保护CPU功能并使用Mapfile降低ISA(因为可以保护运行时路径):
$ cat cryptopp.mapfile
# Solaris mapfile to override hardware caps to avoid kills
hwcap_1 = SSE SSE2 OVERRIDE;
No, you don't need to. 不,您不需要。 The compiler does not process instructions inside __asm
statement. 编译器不会在__asm
语句中处理指令。 And the assembler will detect the instructions you used and mark the .o with the appropriate HWCAP. 汇编器将检测到您使用的指令,并使用适当的HWCAP标记.o。 You don't have to pass anything to the compiler explicitly. 您不必显式地将任何内容传递给编译器。
The only case the compiler will require -xarch=avx_i
from you is if you are using rdrand intrinsics as in this case the compiler is aware that it is about to generate the instructions for avx_i
and has to check if the currently selected architecture allows it. 如果您使用的是rdrand内在函数,则编译器将要求您提供-xarch=avx_i
的唯一情况,因为在这种情况下,编译器意识到它将要为avx_i
生成指令,并且必须检查当前选择的体系结构是否允许它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.