tkluck / GaloisFields.jl

Finite fields for Julia
Other
47 stars 6 forks source link

llvm.x86.pclmulqdq on Julia over Apple M1 #21

Closed uchkw closed 2 years ago

uchkw commented 2 years ago

On Julia over Apple M1, I am unable to perform power operations as shown below.

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.2.0)
  CPU: Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, cyclone)

julia> using GaloisFields
[ Info: Precompiling GaloisFields [8d0d7f98-d412-5cd4-8397-071c807280aa]

julia> const G, α = GaloisField(2, 4, :α)
(𝔽₁₆, α)

julia> α^2
LLVM ERROR: Cannot select: intrinsic %llvm.x86.pclmulqdq

signal (6): Abort trap: 6
in expression starting at REPL[3]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 7490130 (Pool: 7486448; Big: 3682); GC: 9
fish: Job 1, 'julia' terminated by signal SIGABRT (Abort)

There seems to be an error in the following line executing pclmulqdq in BinaryFields.jl. I would appreciate it if you could provide me with a solution.

function carrylessmul(a::m128, b::m128)
    ccall("llvm.x86.pclmulqdq", llvmcall, m128, (m128, m128, UInt8), a, b, 0)
end
tkluck commented 2 years ago

Hi @uchkw , would you be able to verify for me that

julia> using Base.BinaryPlatforms.CPUID

julia> CPUID.test_cpu_feature(CPUID.JL_X86_pclmul)

returns false on your platform? That will help me publish a fix.

uchkw commented 2 years ago

Thanks for your quick response. Yes, it returns false.

julia> using Base.BinaryPlatforms.CPUID

julia> CPUID.test_cpu_feature(CPUID.JL_X86_pclmul)
false
uchkw commented 2 years ago

It worked! Thanks!