Skip to content

Commit

Permalink
Use copysign LLVM intrinsic rather than bithack ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Feb 20, 2021
1 parent d524f21 commit 832c924
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void jl_init_intrinsic_functions_codegen(void)
float_func[fpiseq] = true;
float_func[fpislt] = true;
float_func[abs_float] = true;
//float_func[copysign_float] = false; // this is actually an integer operation
float_func[copysign_float] = true;
float_func[ceil_llvm] = true;
float_func[floor_llvm] = true;
float_func[trunc_llvm] = true;
Expand Down Expand Up @@ -1252,14 +1252,8 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
return ctx.builder.CreateCall(absintr, x);
}
case copysign_float: {
Value *bits = ctx.builder.CreateBitCast(x, t);
Value *sbits = ctx.builder.CreateBitCast(y, t);
unsigned nb = cast<IntegerType>(t)->getBitWidth();
APInt notsignbit = APInt::getSignedMaxValue(nb);
APInt signbit0(nb, 0); signbit0.setBit(nb - 1);
return ctx.builder.CreateOr(
ctx.builder.CreateAnd(bits, ConstantInt::get(t, notsignbit)),
ctx.builder.CreateAnd(sbits, ConstantInt::get(t, signbit0)));
FunctionCallee copyintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::copysign, makeArrayRef(t));
return ctx.builder.CreateCall(copyintr, {x, y});
}
case flipsign_int: {
ConstantInt *cx = dyn_cast<ConstantInt>(x);
Expand Down

0 comments on commit 832c924

Please sign in to comment.