Skip to content

Commit

Permalink
use powi intrinsic for float^int. ref JuliaLang#6112
Browse files Browse the repository at this point in the history
restores the performance of stockcorr
  • Loading branch information
JeffBezanson authored and tkelman committed Mar 29, 2014
1 parent 8111988 commit 13d00f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export
#checked_smul, checked_ssub, checked_uadd, checked_umul, checked_usub,
#nan_dom_err, copysign_float, ctlz_int, ctpop_int, cttz_int,
#div_float, eq_float, eq_int, eqfsi64, eqfui64, flipsign_int, select_value,
#sqrt_llvm, fpext64, fpiseq, fpislt, fpsiround, fpuiround, fptosi, fptoui,
#sqrt_llvm, powi_llvm,
#fpext64, fpiseq, fpislt, fpsiround, fpuiround, fptosi, fptoui,
#fptrunc32, le_float, lefsi64, lefui64, lesif64,
#leuif64, lshr_int, lt_float, ltfsi64, ltfui64, ltsif64, ltuif64, mul_float,
#mul_int, ne_float, ne_int, neg_float, neg_int, not_int, or_int, rem_float,
Expand Down
8 changes: 5 additions & 3 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin,
acos, atan, asinh, acosh, atanh, sqrt, log2, log10,
max, min, minmax, ceil, floor, trunc, round, ^, exp2, exp10

import Core.Intrinsics: nan_dom_err, sqrt_llvm, box, unbox
import Core.Intrinsics: nan_dom_err, sqrt_llvm, box, unbox, powi_llvm

# non-type specific math functions

Expand Down Expand Up @@ -409,8 +409,10 @@ modf(x) = rem(x,one(x)), trunc(x)
^(x::Float64, y::Float64) = nan_dom_err(ccall((:pow,libm), Float64, (Float64,Float64), x, y), x+y)
^(x::Float32, y::Float32) = nan_dom_err(ccall((:powf,libm), Float32, (Float32,Float32), x, y), x+y)

^(x::Float64, y::Integer) = ccall((:pow,libm), Float64, (Float64,Float64), x, y)
^(x::Float32, y::Integer) = ccall((:powf,libm), Float32, (Float32,Float32), x, y)
^(x::Float64, y::Integer) =
box(Float64, powi_llvm(unbox(Float64,x), unbox(Int32,int32(y))))
^(x::Float32, y::Integer) =
box(Float32, powi_llvm(unbox(Float32,x), unbox(Int32,int32(y))))

# special functions

Expand Down
11 changes: 10 additions & 1 deletion src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace JL_I {
nan_dom_err,
// functions
abs_float, copysign_float, flipsign_int, select_value,
sqrt_llvm,
sqrt_llvm, powi_llvm,
// pointer access
pointerref, pointerset, pointertoref,
// c interface
Expand Down Expand Up @@ -1250,6 +1250,14 @@ static Value *emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs,
ArrayRef<Type*>(x->getType())),
x);
}
HANDLE(powi_llvm,2) {
x = FP(x);
y = JL_INT(y);
Type *ts[2] = { x->getType(), T_int32 };
return builder.CreateCall2(Intrinsic::getDeclaration(jl_Module, Intrinsic::powi,
ArrayRef<Type*>(ts)),
x, y);
}
default:
assert(false);
}
Expand Down Expand Up @@ -1329,6 +1337,7 @@ extern "C" void jl_init_intrinsic_functions(void)
ADD_I(fptrunc); ADD_I(fpext);
ADD_I(abs_float); ADD_I(copysign_float);
ADD_I(flipsign_int); ADD_I(select_value); ADD_I(sqrt_llvm);
ADD_I(powi_llvm);
ADD_I(pointerref); ADD_I(pointerset); ADD_I(pointertoref);
ADD_I(checked_sadd); ADD_I(checked_uadd);
ADD_I(checked_ssub); ADD_I(checked_usub);
Expand Down

0 comments on commit 13d00f4

Please sign in to comment.