Skip to content

Commit

Permalink
Implement changes in fastmath.jl rather than lowering.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Mar 20, 2017
1 parent d609cb1 commit d46ec6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ function make_fastmath(expr::Expr)
$arrvar[$(indvars...)] = $op($arrvar[$(indvars...)], $rhs)
end
end
elseif is_literal_int_pow(expr)
expr = Expr(expr.head, :(Base.literal_pow),
expr.args[1], expr.args[2], Val{expr.args[3]})
end
Expr(make_fastmath(expr.head), map(make_fastmath, expr.args)...)
end
Expand All @@ -127,6 +130,10 @@ macro fastmath(expr)
make_fastmath(esc(expr))
end

function is_literal_int_pow(ex::Expr)
return (ex.head === :call && length(ex.args) == 3 &&
ex.args[1] === :^ && isa(ex.args[3], Integer))
end

# Basic arithmetic

Expand Down
7 changes: 7 additions & 0 deletions test/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,10 @@ let a = ones(2,2), b = ones(2,2)
local c = 0
@test @fastmath(c |= 1) == 1
end

struct LitPowTest end
Base.literal_pow{p}(::typeof(Base.FastMath.pow_fast), ::LitPowTest, ::Type{Val{p}}) = 1
Base.literal_pow{p}(::typeof(^), ::LitPowTest, ::Type{Val{p}}) = 2
LPT = LitPowTest()
@test (@fastmath LPT^2) == 1
@test LPT^2 == 2

0 comments on commit d46ec6c

Please sign in to comment.