Use OSX terminal to find out the CPU instructions set (AVX, SSE and such)
I have different machines running OSX 10.12 and 10.13, which use different processors. I am trying to get from terminal, a string that can show me which CPU instructions are supported by that machine; so I can use the appropriate software (some of the software require specific instructions to be present on the CPU, and if that CPU does not support them, the software will either work incorrectly or crash).
I did check querying the system profiler via terminal but I can get only the CPU type and model, not the CPU instruction set that it support; and if I would do this by hand, getting every CPU model and checking online, it would take hours.
- CPU instructions are these set of instructions like MMX, AVX, SSE; that allow your CPU to operate in a certain way. With years, they are added to the base CPU instruction set, so modern CPU these days support more than 15 different instruction types.
Solution 1:
Enter
sysctl -a | grep cpu.feat
get a list like
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC POPCNT AES PCID XSAVE OSXSAVE TSCTMR AVX1.0
machdep.cpu.feature_bits: 2286390173542120447
Alternatively (avoiding the grep and being a lot faster, which might help you run this often within a script)
sysctl machdep.cpu.features
sysctl machdep.cpu.features machdep.cpu.feature_bits
gives you just the list (or both) directly.
Or just use: sysctl machdep.cpu
to get them all
Solution 2:
Just to extend LangLangC's answer, for some reason, AVX2 does not appear in the machdep.cpu.features
list but in a separate list: machdep.cpu.leaf7_features
. To check all supported flags you can use:
/usr/sbin/sysctl -n machdep.cpu.features machdep.cpu.leaf7_features
Resulting in an output like
FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX SMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C
RDWRFSGS TSC_THREAD_OFFSET SGX BMI1 HLE AVX2 SMEP BMI2 ERMS INVPCID RTM FPU_CSDS MPX RDSEED ADX SMAP CLFSOPT IPT MDCLEAR TSXFA IBRS STIBP L1DF SSBD