简体   繁体   English

不能在旧版 Intel CPU 上使用 _m_prefetchw 内在函数和 gcc/clang -march=native?

[英]Can't use _m_prefetchw intrinsic with gcc/clang -march=native on older Intel CPU?

I ran into this problem while compiling my project with Clang .我在使用Clang编译我的项目时遇到了这个问题。 I want to use the intrinsic function _m_prefetchw for that I included x86intrin.h, but for some reason my flow is not reaching the _m_prefetchw definition.我想使用内在的 function _m_prefetchw因为我包含了 x86intrin.h,但由于某种原因,我的流程没有达到 _m_prefetchw 定义。 I checked the x86intrin.h header file of Clang and I dont have the __PRFCHW__ defined in order to include prfchwintrin.h although I do have PREFETCHW supported by my PC (I ran coreinfo to know this).我检查了 Clang 的x86intrin.h header 文件,我没有定义__PRFCHW__以包含 prfchwintrin.h,尽管我的 PC 确实支持PREFETCHW (我运行 coreinfo 来知道这一点)。

does anyone know why __PRFCHW__ isn't defined although I have PREFETCHW supported?有谁知道为什么__PRFCHW__没有定义,尽管我支持PREFETCHW

code example:代码示例:

#include <x86intrin.h>

int main(){
    int i = 10;
    _m_prefetchw(&i);
    return 0;
}

After running I get the error error LNK2019: unresolved external symbol _m_prefetchw referenced in function main运行后出现错误error LNK2019: unresolved external symbol _m_prefetchw referenced in function main

I dug into my clang include header files and found this in x86intrin.h:我挖掘了我的 clang 包括 header 文件,并在 x86intrin.h 中找到了这个:

#if !defined(_MSC_VER) || __has_feature(modules) || defined(__PRFCHW__)
#include <prfchwintrin.h>
#endif

And _m_prefetchw is defined in the prfchwintrin.h file. _m_prefetchw定义在 prfchwintrin.h 文件中。

My processor is Intel Xeon E5-2690, Clang version is 9.0.1.我的处理器是Intel Xeon E5-2690,Clang版本是9.0.1。

Manually use -mprfchw to tell the compiler to let you use _m_prefetchw even when compiling for a -march= where prefetchw is only a NOP.手动使用-mprfchw告诉编译器让您使用_m_prefetchw ,即使在为-march=编译时, prefetchw只是一个 NOP。

-march=native only includes -mprfchw if it will actually have an effect. -march=native仅包含-mprfchw如果它确实会产生影响。 See What is the effect of second argument in _builtin_prefetch()?请参阅_builtin_prefetch() 中第二个参数的效果是什么? for more details on how compilers "think about" availability of prefetch instructions and CPUID.有关编译器如何“考虑”预取指令和 CPUID 可用性的更多详细信息。


Your E5-2690 is a Sandybridge, older than Broadwell which introduced (on the Intel side) real support for PREFETCHW.您的 E5-2690 是 Sandybridge,比 Broadwell 更早,它引入了(在英特尔方面)对 PREFETCHW 的真正支持。

Any non-ancient Intel CPUs can run prefetchw as a NOP ( http://ref.x86asm.net/coder64.html#gen_note_NOP_0F0D ), but only Broadwell and later actually advertizes the CPU feature in its CPUID, and only Broadwell and later actually do anything different from a NOP.任何非古代英特尔 CPU 都可以将prefetchw作为 NOP ( http://ref.x86asm.net/coder64.html#gen_note_NOP_0F0D ) 运行,但只有 Broadwell 和更高版本实际上在其 CPUID 中宣传 CPU 功能,并且只有 Broadwell 和更高版本实际上做任何与 NOP 不同的事情。 (AMD CPUs support it as an actual prefetch into Exclusive state ever since 3DNow. introduced it.) (自 3DNow 以来,AMD CPU 支持它作为对 Exclusive state 的实际预取。引入它。)

Running as a NOP instead of faulting is apparently necessary for installing 64-bit Windows, so a lot of discussion about "supporting" PREFETCHW revolves around not faulting, rather than its CPUID bit and actually doing anything.安装 64 位 Windows 显然需要作为 NOP 运行而不是故障运行,因此很多关于“支持”PREFETCHW 的讨论都围绕着不故障运行,而不是它的 CPUID 位和实际做任何事情。 For example, comments on Windows 10 64-bit requirements: Does my CPU support PrefetchW?比如评论Windows 10 64-bit requirements:我的CPU是否支持PrefetchW? discuss this difference in "support" (as in won't fault) vs. "support" as in actually does something.讨论“支持”(如不会出错)与“支持”中的这种差异,如实际做某事。

This forum thread mentions that P4 Nocona faults on prefetchw , and thus can't install Windows 8.1.论坛帖子提到 P4 Nocona 在prefetchw上出现故障,因此无法安装 Windows 8.1。 But Core2 and later do have "won't fault" support.但是 Core2 和更高版本确实有“不会出错”的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用gcc -march编译到其他ISA中吗 - Can I use gcc -march to compile into other ISA 我可以用gcc编译一个函数然后用clang吗? - Can I compile a function with gcc and then use it with clang? 在Intel CPU上选择32至64位固有CRC - Choosing between 32 and 64 bit intrinsic CRC on Intel CPU 我可以将 x86 程序集的英特尔语法与 GCC 一起使用吗? - Can I use Intel syntax of x86 assembly with GCC? 使用__m512 intel内在函数获取可理解的错误 - Getting an understandable error using __m512 intel intrinsic gcc -march = native。 检测为错误架构构建的二进制文件的方法? - gcc -march=native. Way to detect binary built for wrong architecture? gcc如何在x86上确定-march = native? 在胳膊上? - How does gcc determine -march=native on x86? On arm? GCC在类似架构上使用“-march = native”发出大不相同的代码 - GCC emits vastly different code using “-march=native” on similar architectures 如何在 gcc 中使用编译指示(或其他方式)指定 -march=native - How to specify -march=native using pragmas (or otherwise) in gcc OpenMP:gcc 在 -march=native (-march=skylake-avx512) 和 -O3 的情况下会导致奇怪的求和 - OpenMP: gcc causes weird summation in case of -march=native (-march=skylake-avx512) and -O3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM