forked from JuliaDiff/ForwardDiff.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIMDTest.jl
47 lines (36 loc) · 1.42 KB
/
SIMDTest.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module SIMDTest
using Compat
using Compat.Test
using ForwardDiff: Dual, valtype
const DUALS = (Dual(1., 2., 3., 4.),
Dual(1., 2., 3., 4., 5.),
Dual(Dual(1., 2.), Dual(3., 4.)))
function simd_sum(x::Vector{T}) where T
s = zero(T)
@simd for i in eachindex(x)
@inbounds s = s + x[i]
end
return s
end
for D in map(typeof, DUALS)
plus_bitcode = sprint(io -> code_llvm(io, +, (D, D)))
@test contains(plus_bitcode, "fadd <4 x double>")
minus_bitcode = sprint(io -> code_llvm(io, -, (D, D)))
@test contains(minus_bitcode, "fsub <4 x double>")
times_bitcode = sprint(io -> code_llvm(io, *, (D, D)))
@test ismatch(r"fadd \<.*?x double\>", times_bitcode)
@test ismatch(r"fmul \<.*?x double\>", times_bitcode)
div_bitcode = sprint(io -> code_llvm(io, /, (D, D)))
@test ismatch(r"fadd \<.*?x double\>", div_bitcode)
@test ismatch(r"fmul \<.*?x double\>", div_bitcode)
exp_bitcode = sprint(io -> code_llvm(io, ^, (D, D)))
@test ismatch(r"fadd \<.*?x double\>", exp_bitcode)
if !(valtype(D) <: Dual)
# see https://github.com/JuliaDiff/ForwardDiff.jl/issues/167
@test ismatch(r"fmul \<.*?x double\>", exp_bitcode)
# see https://github.com/JuliaDiff/ForwardDiff.jl/pull/201
sum_bitcode = sprint(io -> code_llvm(io, simd_sum, (Vector{D},)))
@test ismatch(r"fadd \<.*?x double\>", sum_bitcode)
end
end
end # module