簡體   English   中英

如何在我的計算機上啟用對POPCNT指令/內在函數的支持?

[英]How to enable support for the POPCNT instruction / intrinsic on my computer?

我試圖在我的電腦上運行以下程序(Fedora 17 32bit)。 如何啟用我的系統以支持快速人口統計的popcnt指令?

#include <stdio.h>
#include <nmmintrin.h>

int main(void)
{
    int pop = _mm_popcnt_u32(0xf0f0f0f0ULL);
    printf("pop = %d\n", pop);
    return 0;
}

我編譯了程序並運行它,但得到以下異常:

[xiliu@xiliu tmp]$ gcc -Wall -march=corei7 -m32 -msse4.2 popcnt.c -o popcnt
[xiliu@xiliu tmp]$ ./popcnt 
Illegal instruction (core dumped)

以下是我的處理器的信息:

[xiliu@xiliu tmp]$ cat /proc/cpuinfo 
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 15
model name  : Intel(R) Pentium(R) Dual  CPU  T2370  @ 1.73GHz
stepping    : 13
microcode   : 0xa4
cpu MHz     : 800.000
cache size  : 1024 KB
physical id : 0
siblings    : 2
core id     : 0
cpu cores   : 2
apicid      : 0
initial apicid  : 0
fdiv_bug    : no
hlt_bug     : no
f00f_bug    : no
coma_bug    : no
fpu     : yes
fpu_exception   : yes
cpuid level : 10
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm dtherm
bogomips    : 3458.20
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

[... repeated for 2nd core ...]

請改用__builtin_popcount() ,它不是特定於平台的。

支持POPCNT指令的第一個CPU是Intel的Nehalem。 它看起來像你的Core系列,它更老。 Hasturkun的建議將適用於您的系統,但將使用多個指令而不是單個指令來實現。

如果您想要一個可移植的解決方案而不是GCC特定的解決方案,請查看Sean Eron Anderson的優秀Bit Twiddling Hacks頁面,該頁面具有高度優化的代碼。

您的CPU不支持POPCNT (請參閱https://en.wikipedia.org/wiki/SSE4 )但是您可以使用這個免費的開源工具來檢測它是否受支持: https//github.com/mgorny/cpuid2cpuflags

例如,它返回Intel Core i7-3770

CPU_FLAGS_X86: aes avx f16c mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM