Skip to content

Commit 2ada0e8

Browse files
committed
support Val in pow_fast, fixes #433
1 parent 0ae6dd2 commit 2ada0e8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/parse/add_compute.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@ function add_compute!(
460460
args = @view(ex.args[2:end])
461461
if (instr.instr === :pow_fast || instr.instr === :(^)) && length(args) == 2
462462
arg2 = args[2]
463-
arg2 isa Number && return add_pow!(ls, var, args[1], arg2, elementbytes, position)
463+
if arg2 isa Number
464+
return add_pow!(ls, var, args[1], arg2, elementbytes, position)
465+
elseif arg2 isa Val
466+
arg2num = Int(static(ex.args[3]))::Int
467+
return add_pow!(ls, var, args[1], arg2num, elementbytes, position)
468+
end
464469
end
465470
vparents = Operation[]
466471
deps = Symbol[]

test/miscellaneous.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,13 @@ end
887887
end
888888
x
889889
end
890-
890+
function powfastmath!(x::Vector{T}) where T
891+
@turbo for i = 1:length(x)
892+
xv = x[i]
893+
@fastmath x[i] = 1/(xv^2)
894+
end
895+
x
896+
end
891897
@inline ninereturns(x) = (0.25x, 0.5x, 0.75, 1.0x, 1.25x, 1.5x, 1.75x, 2.0x, 2.25x)
892898
function manyreturntest(x)
893899
s = zero(eltype(x))
@@ -1215,7 +1221,11 @@ end
12151221

12161222
@test all(isequal(81), powcseliteral!(E0))
12171223
@test all(isequal(81), powcsesymbol!(E3))
1218-
1224+
let
1225+
x = rand(T,10) .+ T(0.5);
1226+
r = @. inv(x^2)
1227+
@test r powfastmath!(x)
1228+
end
12191229

12201230
@test isapprox(
12211231
maybe_const_issue144!(

0 commit comments

Comments
 (0)