github.com/muyo/sno@v1.2.1/internal/cpu_amd64.go (about) 1 package internal 2 3 const cpuLacksSSE2ErrMsg = "sno: CPU does not seem to support SSE2 instructions required on amd64 platforms" 4 5 func checkVectorSupport() bool { 6 // We need a highest function parameter of at least 7 since we need 7 // to check for BMI2 support as well. 8 eax, _, _, _ := cpuid(0) 9 if eax < 7 { 10 if eax < 1 { 11 panic(cpuLacksSSE2ErrMsg) 12 } 13 14 return false 15 } 16 17 _, _, ecx, edx := cpuid(1) 18 if (edx & (1 << 26)) == 0 { 19 panic(cpuLacksSSE2ErrMsg) 20 } 21 22 // c & 0x00000001 -> SSE3 23 // c & 0x00000200 -> SSSE3 24 // c & 0x00080000 -> SSE4 25 // c & 0x00100000 -> SSE4.2 26 if (ecx & 0x00180201) != 0x00180201 { 27 return false 28 } 29 30 // b & 0x00000008 -> BMI1 31 // b & 0x00000100 -> BMI2 32 _, ebx, _, _ := cpuid(7) 33 34 return (ebx & 0x00000108) == 0x00000108 35 } 36 37 // Gets temporarily swapped out with a mock during tests. 38 var cpuid = cpuidReal 39 40 //go:noescape 41 func cpuidReal(op uint32) (eax, ebx, ecx, edx uint32)