TEXT ·hasPOPCNT(SB),NOSPLIT,$0
XORQ AX, AX ; AX <- 0
INCL AX ; AX <- 1
CPUID ; check cpu caps
SHRQ $23, CX ; shift bit 23 to bit 0 (bit 23 => POPCNT support)
ANDQ $1, CX ; examine bit 0
MOVB CX, ret+0(FP) ; return 1 iff POPCNT instruction supported
RET
It seems Intel CPU's have such a bloated and varied instruction set you have to query to see what flavor of CPU you have to create portable code. Writing compilers for this must be a real pain.Full disclosure : I work for Intel