Other Determining CPU capabilities..

How to determine if CPU of a host is capable for SSE,SSE2,SSSE3,SSE4.1 and SSE4.2 ?

In cmake. So it should be accessible through shell.

I did find
Code:
hw.instruction_sse
while browsing FreeBSD's source but nothing readily accessible besides that.

I also came up with the idea of parsing the dmesg | grep Features2 but it may not be available with plain user privileges.

Ideas?

Why I need it? Perhaps image would explain better.
build.png
 
dmesg shows the additional CPU instruction sets:
Code:
CPU: Intel(R) Core(TM) i5-2430M CPU @ 2.40GHz (2394.61-MHz K8-class CPU)
  Origin="GenuineIntel"  Id=0x206a7  Family=0x6  Model=0x2a  Stepping=7
  Features=0xbfebfbff<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,HTT,TM,PBE>
  Features2=0x1fbae3bf<SSE3,PCLMULQDQ,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,TSCDLT,AESNI,XSAVE,OSXSAVE,AVX>
  AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM>
  AMD Features2=0x1<LAHF>
  XSAVE Features=0x1<XSAVEOPT>
  VT-x: PAT,HLT,MTF,PAUSE,EPT,UG,VPID
  TSC: P-state invariant, performance statistics

dmesg | head -n20
 
Would work unless machine was set up with

In which case dmesg would show for unprivileged user

dmesg: sysctl kern.msgbuf: Operation not permitted

Parsing dmesg would work otherwise. Can't ask people build as root either. Install - yes, build - no.

I've been going through utilities in ports but so far really nothing that would precisely fit.
 
You could write a piece of code (in C + assembly) that executes the cpuidex instruction. The result of that instruction is the complete CPUID (loaded into some registers), which you can then decode to find out which features are enabled. Alas, that instruction requires requires root privileges as far as I can see. So scratch that.

Here's an idea: Find some SSE/SSE2/... instructions. That's easy to do: Download and read the Intel instruction set architecture reference manual, read and understand it. Then write a handful of tiny little programs, each of which execute one of those instructions. Writing these programs will require either finding the correct C compiler pragmas for the instructions (gnarly), or writing part of the programs in assembly or hand-coding the numeric instructions (more gnarly). Having written those programs, start them one at a time (from a shell, which is for example available in make), and observe whether the succeed, or whether they crash with a signal that would indicate "illegal instruction". This can all be done in user space, but is quite a bit of work (it would take an experienced programmer who knows Intel assembly probably an hour, and a novice a day).
 
Would work unless machine was set up with

In which case dmesg would show for unprivileged user

dmesg: sysctl kern.msgbuf: Operation not permitted

Parsing dmesg would work otherwise. Can't ask people build as root either. Install - yes, build - no.

I've been going through utilities in ports but so far really nothing that would precisely fit.

/var/run/dmesg.boot is available, and is much better to use as the boot messages can be pushed out of the kernel buffer that dmesg(8) reads if the system has been running for more than a few days.
 
Code:
# cd /usr/ports
# make -VMACHINE_CPU
sse42 sse41 ssse3 sse3 amd64 sse2 sse mmx
More info:
# view /usr/share/mk/bsd.cpu.mk

And then you can do stuff in Makefiles like:
Code:
 .    if !empty(MACHINE_CPU:Mavx)
CONFIGURE_ARGS+=--enable-avx
.    endif
I grabbed this example from /usr/ports/math/fftw3/Makefile
 
Back
Top