草庐IT

assembly - 为什么汇编 POPCNTQ 基准测试会比使用整数技巧的 native Go 函数慢?

ASM版本TEXT·CountBitsUint64PopCnt(SB),NOSPLIT,$0POPCNTQx+0(FP),AXMOVQAX,ret+8(FP)RETGo版本const(m1quint64=0x5555555555555555m2q=0x3333333333333333m4q=0x0f0f0f0f0f0f0f0fhq=0x0101010101010101)funcCountBitsUint64(xuint64)int{x-=(x>>1)&m1q//putcountofeach2bitsintothose2bitsx=(x&m2q)+((x>>2)&m2q)//putcou