简体   繁体   English

以字节码形式使用指令时是否需要-xarch = XXX?

[英]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.

相关问题 4字节的汇编指令如何编码4字节的存储器地址? - How can an assembly instruction of 4 byte encode a 4 byte memory address? 当我使用的库使用的库发生更改时,我的可执行文件是否需要重新链接? - Does my executable need relinking when a library used by a library that I use changes? ld linker 在输出到二进制文件时添加了额外的汇编指令 - ld linker is adding extra assembly instruction when outputing to binary file Code :: Blocks and boost 1.55:存在动态库时不使用静态库 - Code::Blocks and boost 1.55: static library is not used when dynamic library is present Java编译器对象代码(字节代码?) - Java Compiler Object Code (Byte Code?) 为什么使用 -l 时 gcc 会动态链接? - why is gcc linking dynamically when -l is used? 为什么在使用 -rpath 时需要 -L? - Why is -L needed when -rpath is used? 在另一个类中使用时链接一个类 - Linking a class when used inside another class "未定义对 'vtable for xxx' 的引用" - Undefined reference to 'vtable for xxx' 当提供程序仅随 xxx.lib 一起提供 xxx.dll 并且您使用的是 MinGW-w64 而不是 MSVC 时,如何链接到 xxx.dll? - How to link to an xxx.dll when the provider only ships it with an xxx.lib and you are using MinGW-w64 and not MSVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM