guzba / zippy

Pure Nim implementation of deflate, zlib, gzip and zip.
MIT License
246 stars 29 forks source link

Failing to compile for iOS with simd enabled #50

Closed iffy closed 1 year ago

iffy commented 1 year ago

By reading the source, I've discovered I can disable simd with -d:zippyNoSimd so this isn't a blocker for me anymore, but in case it's fixable, I've filed this anyway. Feel free to close if it's not worth the time.

# samp.nim
import zippy
let gz = compress("something")
doAssert uncompress(gz) == "something"

Compiling samp.nim with this command:

nim c --cpu:arm64 --threads:on --parallelBuild:1 --tlsEmulation:off "--passC:-arch arm64" "--passC:-isysroot" "--passC:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk"   /tmp/samp.nim

Results in the error Cannot select: intrinsic %llvm.aarch64.crc32b:

Hint: clang -c  -w -ferror-limit=3 -pthread -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk   -I/Users/matt/.choosenim/toolchains/nim-1.6.6/lib -I/private/tmp -o /Users/matt/.cache/nim/samp_d/@m..@s..@sUsers@smatt@s.nimble@spkgs@szippy-0.10.3@szippy@scrc32_simd.nim.c.o /Users/matt/.cache/nim/samp_d/@m..@s..@sUsers@smatt@s.nimble@spkgs@szippy-0.10.3@szippy@scrc32_simd.nim.c [Exec]
fatal error: error in backend: Cannot select: intrinsic %llvm.aarch64.crc32b
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: aarch64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to http://developer.apple.com/bugreporter/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/mt/84ydn6s16y793cksy0ykq7zw0000gn/T/@m-2a6dff.c
clang: note: diagnostic msg: /var/folders/mt/84ydn6s16y793cksy0ykq7zw0000gn/T/@m-2a6dff.sh
clang: note: diagnostic msg: Crash backtrace is located in
clang: note: diagnostic msg: /Users/matt/Library/Logs/DiagnosticReports/clang_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang: note: diagnostic msg: 

********************
Error: execution of an external program failed: 'clang -c  -w -ferror-limit=3 -pthread -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk   -I/Users/matt/.choosenim/toolchains/nim-1.6.6/lib -I/private/tmp -o /Users/matt/.cache/nim/samp_d/@m..@s..@sUsers@smatt@s.nimble@spkgs@szippy-0.10.3@szippy@scrc32_simd.nim.c.o /Users/matt/.cache/nim/samp_d/@m..@s..@sUsers@smatt@s.nimble@spkgs@szippy-0.10.3@szippy@scrc32_simd.nim.c'
guzba commented 1 year ago

Unfortunately ARM has no way of runtime detecting features / instructions so I must chose a default. In this case I chose to use the instruction since it is important for performance on M1 / M2 and future stuff. You'll want to use the -d:zippyNoSimd for cases where any instructions are not available, I am not aware of any way to avoid this without slowing down the default ARM executable a lot.