Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: address issue #20882 #20889

Merged
merged 8 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ end
# We mark these @inline since if the target is marked @inline,
# we want to make sure that gets propagated,
# even if it is over the inlining threshold.
@inline ^(x, p) = internal_pow(x, p)
@inline internal_pow{p}(x, ::Type{Val{p}}) = x^p
@inline internal_pow{p}(x, ::Type{Val{p}}, z) = z(x,p)

# Restrict inlining to hardware-supported arithmetic types, which
# are fast enough to benefit from inlining. This also makes it
Expand All @@ -214,10 +213,10 @@ const HWNumber = Union{HWReal, Complex{<:HWReal}, Rational{<:HWReal}}

# inference.jl has complicated logic to inline x^2 and x^3 for
# numeric types. In terms of Val we can do it much more simply:
@inline internal_pow(x::HWNumber, ::Type{Val{0}}) = one(x)
@inline internal_pow(x::HWNumber, ::Type{Val{1}}) = x
@inline internal_pow(x::HWNumber, ::Type{Val{2}}) = x*x
@inline internal_pow(x::HWNumber, ::Type{Val{3}}) = x*x*x
@inline internal_pow(x::HWNumber, ::Type{Val{0}}, z::typeof(^)) = one(x)
@inline internal_pow(x::HWNumber, ::Type{Val{1}}, z::typeof(^)) = x
@inline internal_pow(x::HWNumber, ::Type{Val{2}}, z::typeof(^)) = x*x
@inline internal_pow(x::HWNumber, ::Type{Val{3}}, z::typeof(^)) = x*x*x

# b^p mod m

Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@

((and (eq? f '^) (length= e 4) (integer? (cadddr e)))
(expand-forms
`(call ^ ,(caddr e) (call (core apply_type) (top Val) ,(cadddr e)))))
`(call (|.| Base (quote internal_pow)) ,(caddr e) (call (core apply_type) (top Val) ,(cadddr e)) ^)))
Copy link
Member

Choose a reason for hiding this comment

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

We should probably call it literal_pow in this case

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Yes, that does seem like a better name now that it's used this way.


((and (eq? f '*) (length= e 4))
(expand-transposed-op
Expand Down