diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b795eec..af9b5c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,9 +15,12 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: ["1.5", "1.6", nightly] - julia-arch: [x64] + julia-version: ["1.5", "1.7", nightly] + julia-arch: [x64, x86] os: [ubuntu-latest, windows-latest, macOS-latest] + exclude: + - os: macOS-latest + julia-arch: x86 steps: - uses: actions/checkout@v2 diff --git a/deps/build.jl b/deps/build.jl deleted file mode 100644 index eaa608a..0000000 --- a/deps/build.jl +++ /dev/null @@ -1,24 +0,0 @@ -disabled() = get(ENV, "R123_DISABLE_AESNI", "") != "" - -const deps_dir = dirname(@__FILE__) - -has_aesni() = try - cmd = Base.julia_cmd() - push!(cmd.exec, joinpath(deps_dir, "has_aesni.jl")) - run(cmd) - true -catch - false -end - -const filename = joinpath(deps_dir, "aes-ni") -isfile(filename) && rm(filename) - -if disabled() - @info "AES-NI is disabled." -elseif has_aesni() - @info "AES-NI is enabled." - touch(filename) -else - @info "AES-NI is not supported." -end diff --git a/deps/has_aesni.jl b/deps/has_aesni.jl deleted file mode 100644 index d3d010e..0000000 --- a/deps/has_aesni.jl +++ /dev/null @@ -1,5 +0,0 @@ -const __m128i = NTuple{2, VecElement{UInt64}} -@assert ccall( - "llvm.x86.aesni.aeskeygenassist", llvmcall, __m128i, (__m128i, UInt8), - __m128i((0x0123456789123450, 0x9876543210987654)), 0x1 -) ≡ __m128i((0x857c266f7c266e85, 0x2346382146382023)) diff --git a/src/Random123.jl b/src/Random123.jl index 3f23dd4..53ab0b5 100644 --- a/src/Random123.jl +++ b/src/Random123.jl @@ -18,7 +18,7 @@ module Random123 using RandomNumbers -export R123_USE_AESNI, set_counter! +export set_counter! include("common.jl") export Threefry2x, Threefry4x @@ -27,15 +27,38 @@ include("threefry.jl") export Philox2x, Philox4x include("philox.jl") -if R123_USE_AESNI - include("aesni_common.jl") - export AESNI1x, AESNI4x - include("aesni.jl") +"True when AES-NI has been enabled." +const R123_USE_AESNI = Ref(false) +export R123_USE_AESNI +export AESNI1x, AESNI4x +export ARS1x, ARS4x +include("./aesni/module.jl") - export ARS1x, ARS4x - include("ars.jl") -else - @warn "AES-NI is not enabled, so AESNI and ARS are not available." +function __init__() + + R123_USE_AESNI[] = try + cmd = Base.julia_cmd() + push!( + cmd.exec, "-e", + "const __m128i = NTuple{2, VecElement{UInt64}};" * + "@assert ccall(\"llvm.x86.aesni.aeskeygenassist\", " * + "llvmcall, __m128i, (__m128i, UInt8), " * + "__m128i((0x0123456789123450, 0x9876543210987654)), 0x1) ≡ " * + "__m128i((0x857c266f7c266e85, 0x2346382146382023))" + ) + success(cmd) + catch e + @show e + false + end + + if R123_USE_AESNI[] + @eval using ._AESNIModule + else + @warn "AES-NI is not enabled, so AESNI and ARS are not available." + end + + nothing end end diff --git a/src/aesni.jl b/src/aesni/aesni.jl similarity index 100% rename from src/aesni.jl rename to src/aesni/aesni.jl diff --git a/src/ars.jl b/src/aesni/ars.jl similarity index 100% rename from src/ars.jl rename to src/aesni/ars.jl diff --git a/src/aesni_common.jl b/src/aesni/common.jl similarity index 95% rename from src/aesni_common.jl rename to src/aesni/common.jl index 4f20cd0..4079cdd 100644 --- a/src/aesni_common.jl +++ b/src/aesni/common.jl @@ -1,6 +1,9 @@ using Base: llvmcall import Base.(+) +using ..Random123: R123Generator1x, R123Generator4x +import ..Random123: random123_r, set_counter! + const __m128i = NTuple{2, VecElement{UInt64}} Base.convert(::Type{__m128i}, x::UInt128) = unsafe_load(Ptr{__m128i}(pointer_from_objref(Ref(x)))) Base.convert(::Type{UInt128}, x::__m128i) = unsafe_load(Ptr{UInt128}(pointer_from_objref(Ref(x)))) diff --git a/src/aesni/module.jl b/src/aesni/module.jl new file mode 100644 index 0000000..cce0d8b --- /dev/null +++ b/src/aesni/module.jl @@ -0,0 +1,14 @@ +module _AESNIModule + +using ..Random123 + +export __m128i, AESNIKey +include("common.jl") + +export AESNI1x, AESNI4x +include("aesni.jl") + +export ARS1x, ARS4x +include("ars.jl") + +end diff --git a/src/common.jl b/src/common.jl index 71bece2..def3d39 100644 --- a/src/common.jl +++ b/src/common.jl @@ -2,12 +2,6 @@ import Libdl import Random: rand, seed! import RandomNumbers: AbstractRNG -const _dep_dir = joinpath(dirname(@__FILE__), "../deps/") -include_dependency(joinpath(_dep_dir, "build.log")) - -"True when AES-NI has been enabled." -const R123_USE_AESNI = isfile(joinpath(_dep_dir, "aes-ni")) - const R123Array1x{T<:Union{UInt128}} = NTuple{1, T} const R123Array2x{T<:Union{UInt32, UInt64}} = NTuple{2, T} const R123Array4x{T<:Union{UInt32, UInt64}} = NTuple{4, T} diff --git a/test/aesni.jl b/test/aesni.jl index 7fc9ab4..7ea1935 100644 --- a/test/aesni.jl +++ b/test/aesni.jl @@ -1,4 +1,4 @@ -if R123_USE_AESNI +if R123_USE_AESNI[] import Random: seed! using Test: @test diff --git a/test/ars.jl b/test/ars.jl index 648687d..cb46494 100644 --- a/test/ars.jl +++ b/test/ars.jl @@ -1,4 +1,4 @@ -if R123_USE_AESNI +if R123_USE_AESNI[] import Random: seed! using Test: @test