simple.nim example does not detect SIMD type on OSX
simple.nim compiles and runs fine on my Ubuntu 16.04 box, but fails with the following under OSX, using either clang or gcc-7.
./simple
Illegal instruction: 4
Thanks for testing that, probably something awry with CPU detection. what hardware is the osx box?
Check out this post: https://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10
Any chance that is relevant? Can you set minversion and resolve it?
That didn't fix it. I get the same error on a Mac Pro (Late 2013), with 3 Ghz 8-core Intel Xeon E3, 64GB 1866 Mhz RAM, running OSX v 10.11.3 (El Capitan), as well as on a Mac Mini Server with El Capitan.
I wonder if you put a bunch of echos in the cpu identification code to narrow down the LOC that causes the fault? I have no way to debug OSX issues from here
The code compiles under debug:
Detected cpu type:SSE41
A + B = R
@[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0]
@[0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0]
@[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
The error only comes with -d:release, in which case I can't even echo from the first line.
@sdwfrost just wanted to let you know I am occasionally trying to figure this out as I have time. Been inquiring on the nim forums.
@sdwfrost new version of nim, and all new cpu detection code! If you can get latest and try this with nim 0.18 and let me know what you get I would appreciate it.
Hi @jackmott
The code doesn't compile under clang at all:
nim/nim_simd/examples/nimcache/nimsimd_nimsimd.c:120:20: error: expected '(' after 'asm'
__asm {
^
1 error generated.
As before, the code compiles with gcc under debug, but I still get an illegal instruction with -d:release. I'm using 0.18.1.
@sdwfrost the error is here because Nim uses GCC-style assembly in its C files (if you embed ASM from nim)
@Yardanico hmm, I'm trying to emit both styles of assembly depending on the C compiler used.
@jackmott well, IDK, but it doesn't work with clang
I'll get clang set up and figure it out, thanks for the feedback!
@Yardanico @sdwfrost fix for clang is in, got it working on ubuntu. Will be interesting to see if we still get the illegal instruction with it.
Hi @jackmott
The package now compiles with clang, but I still get the problem with -d:release where I get the illegal instruction (which I don't get with the debug build)
I guess I have a 3rd excuse to buy a mac
@jackmott you can also try hackintosh :)
@jackmott Maybe these libraries will be useful for you: google/cpu_features tycho/cpuid mgorny/cpuid2cpuflags anrieff/libcpuid Maratyszcza/cpuinfo (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)
@jackmott
maybe the easiest option just from terminal with no dependencies (?):
sysctl -a | grep machdep.cpu.leaf7_features
and also sysctl -a | grep machdep.cpu.features