Skip to content

Commit

Permalink
fix support for -1^x, fixes #441 (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Oct 18, 2022
1 parent 16fae56 commit 9da30ff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LoopVectorization"
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
authors = ["Chris Elrod <[email protected]>"]
version = "0.12.134"
version = "0.12.135"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down Expand Up @@ -52,5 +52,5 @@ SpecialFunctions = "1, 2"
Static = "0.7"
ThreadingUtilities = "0.5"
UnPack = "1"
VectorizationBase = "0.21.21"
VectorizationBase = "0.21.53"
julia = "1.6"
4 changes: 4 additions & 0 deletions src/parse/add_compute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,11 @@ function add_compute!(
instr = instruction!(ls, first(ex.args))::Instruction
args = @view(ex.args[2:end])
if (instr.instr === :pow_fast || instr.instr === :(^)) && length(args) == 2
arg1 = args[1]
arg2 = args[2]
if arg1 isa Number && convert(Float64, arg1) === -1.0
return add_compute!(ls, var, :(2iseven($arg2)-1), elementbytes, position, mpref)
end
if arg2 isa Number
return add_pow!(ls, var, args[1], arg2, elementbytes, position)
elseif arg2 isa Val
Expand Down
21 changes: 21 additions & 0 deletions test/miscellaneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,28 @@ end
# @test LoopVectorization.choose_order(lsvar) == (Symbol[:j,:i], :j, Symbol("##undefined##"), :j, 8, -1)
# @test LoopVectorization.choose_order(lsvar) == (Symbol[:j,:i], :j, :i, :j, 2, 6)
# end
function piestsimd(rounds)
pi = 1.0

@simd for i in 2:(rounds + 2)
x = (-1)^iseven(i)
pi += x / (2 * i - 1)
end

return pi*4
end
function piestturbo(rounds)
pi = 1.0

@turbo for i in 2:(rounds + 2)
x = (-1)^iseven(i)
pi += x / (2 * i - 1)
end

return pi*4
end
@test piestturbo(4096) π rtol = 1e-4
@test piestturbo(2000) piestsimd(2000)
function myvar!(s², A, x̄)
@.= 0
@inbounds for i 1:size(A, 2)
Expand Down

2 comments on commit 9da30ff

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/70494

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.135 -m "<description of version>" 9da30ffe021aa4d78ecc66821b805c5da0e5d5c3
git push origin v0.12.135

Please sign in to comment.