Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use llvm.pow.* intrinsic rather than _iexp helper function

  • Loading branch information...
commit 6e336ec5e37091b627bde7cb244efaaf5c660771 1 parent 3867c39
@nickg authored
Showing with 18 additions and 18 deletions.
  1. +18 −9 src/cgen.c
  2. +0 −9 src/rt/rtkern.c
View
27 src/cgen.c
@@ -1047,8 +1047,17 @@ static LLVMValueRef cgen_fcall(tree_t t, struct cgen_ctx *ctx)
return LLVMBuildURem(builder, args[0], args[1], "");
else if (icmp(builtin, "rem"))
return LLVMBuildSRem(builder, args[0], args[1], "");
- else if (icmp(builtin, "exp"))
- return LLVMBuildCall(builder, llvm_fn("_iexp"), args, 2, "");
+ else if (icmp(builtin, "exp")) {
+ LLVMValueRef cast[] = {
+ LLVMBuildUIToFP(builder, args[0], LLVMDoubleType(), ""),
+ LLVMBuildUIToFP(builder, args[1], LLVMDoubleType(), "")
+ };
+ return LLVMBuildFPToUI(
+ builder,
+ LLVMBuildCall(builder, llvm_fn("llvm.pow.f64"), cast, 2, ""),
+ llvm_type(tree_type(t)),
+ "pow");
+ }
else if (icmp(builtin, "abs")) {
return LLVMBuildSelect(
builder,
@@ -3019,14 +3028,14 @@ static void cgen_support_fns(void)
ARRAY_LEN(_debug_out_args),
false));
- LLVMTypeRef _iexp_args[] = {
- LLVMInt32Type(),
- LLVMInt32Type()
+ LLVMTypeRef llvm_pow_args[] = {
+ LLVMDoubleType(),
+ LLVMDoubleType()
};
- LLVMAddFunction(module, "_iexp",
- LLVMFunctionType(LLVMInt32Type(),
- _iexp_args,
- ARRAY_LEN(_iexp_args),
+ LLVMAddFunction(module, "llvm.pow.f64",
+ LLVMFunctionType(LLVMDoubleType(),
+ llvm_pow_args,
+ ARRAY_LEN(llvm_pow_args),
false));
LLVMTypeRef _inst_name_args[] = {
View
9 src/rt/rtkern.c
@@ -433,14 +433,6 @@ void _debug_out(int32_t val)
printf("DEBUG: val=%"PRIx32"\n", val);
}
-int32_t _iexp(int32_t n, int32_t v)
-{
- if (unlikely(v < 0))
- fatal("negative exponent not allowed for integer");
-
- return (int32_t)pow(n, v);
-}
-
void _inst_name(void *_sig, struct uarray *u)
{
struct signal *sig = _sig;
@@ -933,7 +925,6 @@ static void rt_one_time_init(void)
jit_bind_fn("_array_copy", _array_copy);
jit_bind_fn("_image", _image);
jit_bind_fn("_debug_out", _debug_out);
- jit_bind_fn("_iexp", _iexp);
jit_bind_fn("_inst_name", _inst_name);
trace_on = opt_get_int("rt_trace_en");
Please sign in to comment.
Something went wrong with that request. Please try again.