Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS CI: Now running on ARM64 CPUs #372

Open
mratsim opened this issue Apr 27, 2024 · 2 comments
Open

MacOS CI: Now running on ARM64 CPUs #372

mratsim opened this issue Apr 27, 2024 · 2 comments
Labels

Comments

@mratsim
Copy link
Owner

mratsim commented Apr 27, 2024

It seems like assembly for Apple Clang changed:

https://github.com/mratsim/constantine/actions/runs/8862799707/job/24336160802?pr=370

/Users/runner/work/constantine/constantine/constantine/nimcache/libcurves_headers/@m..@sconstantine@splatforms@sisa@scpudetect_x86.nim.c:80:8: error: invalid output constraint '=a' in asm
      :"=a"(result.eax), "=b"(result.ebx), "=c"(result.ecx), "=d"(result.edx)
       ^

proc cpuid(eax: uint32, ecx = 0'u32): CpuIdRegs =
## Query the CPU
##
## CPUID is a very slow operation, 27-70 cycles, ~120 latency
## - https://uops.info/table.html
## - https://www.agner.org/optimize/instruction_tables.pdf
##
## and need to be cached if CPU capabilities are needed in a hot path
when defined(vcc):
# limited inline asm support in MSVC, so intrinsics, here we go:
proc cpuidMSVC(cpuInfo: ptr uint32; functionID, subFunctionID: uint32)
{.noconv, importc: "__cpuidex", header: "intrin.h".}
cpuidMSVC(addr result, eax, ecx)
else:
# Note: https://bugs.llvm.org/show_bug.cgi?id=17907
# AddressSanitizer + -mstackrealign might not respect RBX clobbers.
asm """
cpuid
:"=a"(`result.eax`), "=b"(`result.ebx`), "=c"(`result.ecx`), "=d"(`result.edx`)
:"a"(`eax`), "c"(`ecx`)"""

@mratsim mratsim changed the title Apple Clang: Change of ASM MacOS CI: Now running on ARM64 CPUs Apr 27, 2024
@mratsim mratsim added bug 🪲 Something isn't working testing 🛂 labels Apr 27, 2024
@mratsim
Copy link
Owner Author

mratsim commented Apr 27, 2024

It seems like the MacOS CI is now using ARM CPUs:
image

and the make_headers task assumes it is running on x86

  Executing task make_lib in /Users/runner/work/constantine/constantine/constantine/constantine.nimble
Compiling static library:  lib/libconstantine.a.arm
Compiling static library:  lib/libconstantine.a.x64
Compiling dynamic library: lib/libconstantine.dylib.arm
ld: warning: ignoring duplicate libraries: '-lm'
Compiling dynamic library: lib/libconstantine.dylib.x64
ld: warning: ignoring duplicate libraries: '-lm'
  Executing task make_headers in /Users/runner/work/constantine/constantine/constantine/constantine.nimble
/Users/runner/work/constantine/constantine/constantine/nimcache/libcurves_headers/@m..@sconstantine@splatforms@sisa@scpudetect_x86.nim.c:80:8: error: invalid output constraint '=a' in asm
      :"=a"(result.eax), "=b"(result.ebx), "=c"(result.ecx), "=d"(result.edx)
       ^

However building a fat binary for both x86 and ARM works well.

@mratsim
Copy link
Owner Author

mratsim commented Apr 28, 2024

Cross-compiling for Linux ARM64 on Linux x86 host works with Clang.

However looking at the error message we can see Nim Compiler version 1.6.21 [MacOSX: amd64]
but the host is actually arm64-apple-darwin23.4.0

So I suspect Nim is actually running through Rosetta and "thinks" it is on a x86 platform, which leads to this const X86 check being mistakenly true:

const GCC_Compatible* = defined(gcc) or defined(clang) or defined(llvm_gcc) or defined(icc)
const X86* = defined(amd64) or defined(i386)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant