Skip to content

Commit 6bc3668

Browse files
Add Arm AArch32 support
Builds on the new AArch64 support, since they're extremely similar.
1 parent 35cdee3 commit 6bc3668

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

src/Random123.jl

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ else
4949
false
5050
end
5151

52-
"True when AArch64 FEAT_AES instructions have been detected."
53-
const R123_USE_AARCH64_FEAT_AES::Bool = if Sys.ARCH :aarch64
52+
"True when Arm AArch64 FEAT_AES instructions have been detected."
53+
const R123_USE_ARM_AARCH64_FEAT_AES::Bool = if Sys.ARCH :aarch64
5454
try
5555
cmd = Base.julia_cmd()
5656
push!(
@@ -72,8 +72,33 @@ else
7272
false
7373
end
7474

75+
"True when Arm AArch32 FEAT_AES instructions have been detected."
76+
const R123_USE_ARM_AARCH32_FEAT_AES::Bool = if Sys.ARCH :aarch64
77+
try
78+
cmd = Base.julia_cmd()
79+
push!(
80+
cmd.exec,
81+
"-e",
82+
"const uint8x16 = NTuple{16, VecElement{UInt8}};" *
83+
"@assert ccall(\"llvm.aarch64.crypto.aesmc\", " *
84+
"llvmcall, uint8x16, (uint8x16,), " *
85+
"uint8x16((0x4a, 0x68, 0xbd, 0xe1, 0xfe, 0x16, 0x3d, " *
86+
"0xec, 0xde, 0x06, 0x72, 0x86, 0xe3, 0x8c, 0x14, 0xd9))) ≡ " *
87+
"uint8x16((0x70, 0xa7, 0x7b, 0xd2, 0x0c, 0x79, 0xbd, " *
88+
"0xf1, 0x59, 0xc2, 0xad, 0x1a, 0x9f, 0x05, 0x37, 0x0f))",
89+
)
90+
success(cmd)
91+
catch e
92+
false
93+
end
94+
else
95+
false
96+
end
97+
98+
const R123_USE_ARM_FEAT_AES::Bool = R123_USE_ARM_AARCH64_FEAT_AES || R123_USE_ARM_AARCH32_FEAT_AES
99+
75100
"True when AES-acceleration instructions have been detected."
76-
const R123_USE_AESNI::Bool = R123_USE_X86_AES_NI || R123_USE_AARCH64_FEAT_AES
101+
const R123_USE_AESNI::Bool = R123_USE_X86_AES_NI || R123_USE_ARM_FEAT_AES
77102

78103
@static if R123_USE_AESNI
79104
export AESNI1x, AESNI4x, aesni
@@ -86,10 +111,10 @@ end
86111
include("./x86/aesni_common.jl")
87112
include("./x86/aesni.jl")
88113
include("./x86/ars.jl")
89-
elseif R123_USE_AARCH64_FEAT_AES
90-
include("./aarch64/aesni_common.jl")
91-
include("./aarch64/aesni.jl")
92-
include("./aarch64/ars.jl")
114+
elseif R123_USE_ARM_FEAT_AES
115+
include("./arm/aesni_common.jl")
116+
include("./arm/aesni.jl")
117+
include("./arm/ars.jl")
93118
end
94119

95120
end
File renamed without changes.

src/aarch64/aesni_common.jl renamed to src/arm/aesni_common.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import Base.(+)
44
using ..Random123: R123Generator1x, R123Generator4x
55
import ..Random123: random123_r, set_counter!
66

7+
const LLVM_ARCH_STRING::String = @static if R123_USE_ARM_AARCH64_FEAT_AES
8+
"aarch64"
9+
elseif R123_USE_ARM_AARCH32_FEAT_AES
10+
"arm"
11+
else
12+
@error "Impossible situation! Something has gone seriously wrong."
13+
end
14+
715
const LITTLE_ENDIAN::Bool = ENDIAN_BOM 0x04030201
816

917
const uint64x2_lvec = NTuple{2, VecElement{UInt64}}
@@ -108,15 +116,17 @@ end
108116
) |> uint32x4
109117

110118
# Raw NEON instrinsics, provided by FEAT_AES
119+
const ARM_AESE_LLVM_INTRINSIC = "llvm.$LLVM_ARCH_STRING.crypto.aese"
111120
@inline _vaese(a::uint8x16, b::uint8x16) = ccall(
112-
"llvm.aarch64.crypto.aese",
121+
ARM_AESE_LLVM_INTRINSIC,
113122
llvmcall,
114123
uint8x16_lvec,
115124
(uint8x16_lvec, uint8x16_lvec),
116125
a.data, b.data,
117126
) |> uint8x16
127+
const ARM_AESMC_LLVM_INTRINSIC = "llvm.$LLVM_ARCH_STRING.crypto.aesmc"
118128
@inline _vaesmc(a::uint8x16) = ccall(
119-
"llvm.aarch64.crypto.aesmc",
129+
ARM_AESMC_LLVM_INTRINSIC,
120130
llvmcall,
121131
uint8x16_lvec,
122132
(uint8x16_lvec,),
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ cd(pwd_)
175175
@static if Random123.R123_USE_X86_AES_NI
176176
include("./x86/aesni.jl")
177177
include("./x86/ars.jl")
178-
elseif Random123.R123_USE_AARCH64_FEAT_AES
179-
include("./aarch64/aesni.jl")
180-
include("./aarch64/ars.jl")
178+
elseif Random123.R123_USE_ARM_FEAT_AES
179+
include("./arm/aesni.jl")
180+
include("./arm/ars.jl")
181181
end

0 commit comments

Comments
 (0)