Skip to content

Commit 9da30ff

Browse files
authored
fix support for -1^x, fixes #441 (#442)
1 parent 16fae56 commit 9da30ff

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LoopVectorization"
22
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
33
authors = ["Chris Elrod <[email protected]>"]
4-
version = "0.12.134"
4+
version = "0.12.135"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
@@ -52,5 +52,5 @@ SpecialFunctions = "1, 2"
5252
Static = "0.7"
5353
ThreadingUtilities = "0.5"
5454
UnPack = "1"
55-
VectorizationBase = "0.21.21"
55+
VectorizationBase = "0.21.53"
5656
julia = "1.6"

src/parse/add_compute.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,11 @@ function add_compute!(
459459
instr = instruction!(ls, first(ex.args))::Instruction
460460
args = @view(ex.args[2:end])
461461
if (instr.instr === :pow_fast || instr.instr === :(^)) && length(args) == 2
462+
arg1 = args[1]
462463
arg2 = args[2]
464+
if arg1 isa Number && convert(Float64, arg1) === -1.0
465+
return add_compute!(ls, var, :(2iseven($arg2)-1), elementbytes, position, mpref)
466+
end
463467
if arg2 isa Number
464468
return add_pow!(ls, var, args[1], arg2, elementbytes, position)
465469
elseif arg2 isa Val

test/miscellaneous.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,28 @@ end
184184
# @test LoopVectorization.choose_order(lsvar) == (Symbol[:j,:i], :j, Symbol("##undefined##"), :j, 8, -1)
185185
# @test LoopVectorization.choose_order(lsvar) == (Symbol[:j,:i], :j, :i, :j, 2, 6)
186186
# end
187+
function piestsimd(rounds)
188+
pi = 1.0
187189

190+
@simd for i in 2:(rounds + 2)
191+
x = (-1)^iseven(i)
192+
pi += x / (2 * i - 1)
193+
end
194+
195+
return pi*4
196+
end
197+
function piestturbo(rounds)
198+
pi = 1.0
199+
200+
@turbo for i in 2:(rounds + 2)
201+
x = (-1)^iseven(i)
202+
pi += x / (2 * i - 1)
203+
end
204+
205+
return pi*4
206+
end
207+
@test piestturbo(4096) π rtol = 1e-4
208+
@test piestturbo(2000) piestsimd(2000)
188209
function myvar!(s², A, x̄)
189210
@.= 0
190211
@inbounds for i 1:size(A, 2)

0 commit comments

Comments
 (0)