Skip to content

Commit 5f62713

Browse files
committed
Support more updating assignments
1 parent 3fa854d commit 5f62713

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/vectorizationbase_compat/contract_pass.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,21 @@ function contract!(expr::Expr, ex::Expr, i::Int, mod)
209209
if ex.head === :(+=)
210210
call = append_update_args(:add_fast, ex)
211211
expr.args[i] = ex = Expr(:(=), first(ex.args), call)
212-
elseif ex.head === :(-=)
213-
call = Expr(:call, :sub_fast)
214-
append!(call.args, ex.args)
215-
expr.args[i] = ex = Expr(:(=), first(ex.args), call)
216212
elseif ex.head === :(*=)
217213
call = append_update_args(:mul_fast, ex)
218214
expr.args[i] = ex = Expr(:(=), first(ex.args), call)
219-
elseif ex.head === :(/=)
220-
call = Expr(:call, :div_fast)
221-
append!(call.args, ex.args)
222-
expr.args[i] = ex = Expr(:(=), first(ex.args), call)
215+
elseif Meta.isexpr(ex, :(\=), 2)
216+
exa1 = ex.args[1]
217+
call = Expr(:call, :div_fast, ex.args[2], exa1)
218+
expr.args[i] = ex = Expr(:(=), exa1, call)
219+
else
220+
j = findfirst(Base.Fix2(===, ex.head), (:(-=), :(/=), :(÷=), :(%=), :(^=), :(&=), :(|=), :(⊻=), :(>>>=), :(>>=), :(<<=)))
221+
if j nothing
222+
f = (:sub_fast, :div_fast, :(÷), :(%), :(^), :(&), :(|), :(), :(>>>), :(>>), :(<<))[j::Int]
223+
call = Expr(:call, f)
224+
append!(call.args, ex.args)
225+
expr.args[i] = ex = Expr(:(=), first(ex.args), call)
226+
end
223227
end
224228
if ex.head === :(=)
225229
RHS = ex.args[2]

test/grouptests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const START_TIME = time()
5151
@time include("reduction_untangling.jl")
5252

5353
@time include("manyloopreductions.jl")
54+
55+
@time include("simplemisc.jl")
5456
end
5557

5658
@time if LOOPVECTORIZATION_TEST == "all" || LOOPVECTORIZATION_TEST == "part2"

test/simplemisc.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
function lv_turbo(r::Vector{UInt64}, mask::UInt64)
3+
@turbo for i in 1:length(r)
4+
r[i] &= mask
5+
end
6+
r
7+
end
8+
9+
@testset "Simple Miscellaneous" begin
10+
r1 = rand(UInt, 239);
11+
mask = ~(one(eltype(r))<<(2))
12+
r2 = r1 .& mask;
13+
@test lv_turbo(r1, mask) == r2;
14+
end
15+

0 commit comments

Comments
 (0)