forked from M-Labs/artiq
Revert "runtime: remove some redundant libm functions copied inline."
This reverts commit fee75bd50f
.
LLVM does not have lround as a libcall and this inhibits LICM.
This commit is contained in:
parent
6e77f65d50
commit
798a5f70df
|
@ -323,6 +323,8 @@ class LLVMIRGenerator:
|
||||||
llty = ll.FunctionType(llvoid, [])
|
llty = ll.FunctionType(llvoid, [])
|
||||||
elif name == "llvm.floor.f64":
|
elif name == "llvm.floor.f64":
|
||||||
llty = ll.FunctionType(lldouble, [lldouble])
|
llty = ll.FunctionType(lldouble, [lldouble])
|
||||||
|
elif name == "llvm.round.f64":
|
||||||
|
llty = ll.FunctionType(lldouble, [lldouble])
|
||||||
elif name == "llvm.pow.f64":
|
elif name == "llvm.pow.f64":
|
||||||
llty = ll.FunctionType(lldouble, [lldouble, lldouble])
|
llty = ll.FunctionType(lldouble, [lldouble, lldouble])
|
||||||
elif name == "llvm.powi.f64":
|
elif name == "llvm.powi.f64":
|
||||||
|
@ -347,8 +349,6 @@ class LLVMIRGenerator:
|
||||||
llty = ll.FunctionType(lli32, [llptr])
|
llty = ll.FunctionType(lli32, [llptr])
|
||||||
elif name == "strcmp":
|
elif name == "strcmp":
|
||||||
llty = ll.FunctionType(lli32, [llptr, llptr])
|
llty = ll.FunctionType(lli32, [llptr, llptr])
|
||||||
elif name == "lround":
|
|
||||||
llty = ll.FunctionType(lli32, [lldouble])
|
|
||||||
elif name == "send_rpc":
|
elif name == "send_rpc":
|
||||||
llty = ll.FunctionType(llvoid, [lli32, llptr, llptrptr])
|
llty = ll.FunctionType(llvoid, [lli32, llptr, llptrptr])
|
||||||
elif name == "send_async_rpc":
|
elif name == "send_async_rpc":
|
||||||
|
@ -1044,8 +1044,9 @@ class LLVMIRGenerator:
|
||||||
name=insn.name)
|
name=insn.name)
|
||||||
elif insn.op == "round":
|
elif insn.op == "round":
|
||||||
llarg = self.map(insn.operands[0])
|
llarg = self.map(insn.operands[0])
|
||||||
return self.llbuilder.call(self.llbuiltin("lround"), [llarg],
|
llvalue = self.llbuilder.call(self.llbuiltin("llvm.round.f64"), [llarg])
|
||||||
name=insn.name)
|
return self.llbuilder.fptosi(llvalue, self.llty_of_type(insn.type),
|
||||||
|
name=insn.name)
|
||||||
elif insn.op == "globalenv":
|
elif insn.op == "globalenv":
|
||||||
def get_outer(llenv, env_ty):
|
def get_outer(llenv, env_ty):
|
||||||
if "$outer" in env_ty.params:
|
if "$outer" in env_ty.params:
|
||||||
|
|
|
@ -74,7 +74,7 @@ static mut API: &'static [(&'static str, *const ())] = &[
|
||||||
|
|
||||||
/* libm */
|
/* libm */
|
||||||
api!(sqrt),
|
api!(sqrt),
|
||||||
api!(lround),
|
api!(round),
|
||||||
|
|
||||||
/* exceptions */
|
/* exceptions */
|
||||||
api!(_Unwind_Resume),
|
api!(_Unwind_Resume),
|
||||||
|
|
|
@ -70,10 +70,33 @@ int dl_iterate_phdr (int (*callback)(struct dl_phdr_info *, size_t, void *), voi
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called by kernel */
|
/* called by kernel */
|
||||||
long lround(double x);
|
double round(double x);
|
||||||
long lround(double x)
|
double round(double x)
|
||||||
{
|
{
|
||||||
return x < 0 ? floor(x) : ceil(x);
|
union {double f; uint64_t i;} u = {x};
|
||||||
|
int e = u.i >> 52 & 0x7ff;
|
||||||
|
double y;
|
||||||
|
|
||||||
|
if (e >= 0x3ff+52)
|
||||||
|
return x;
|
||||||
|
if (u.i >> 63)
|
||||||
|
x = -x;
|
||||||
|
if (e < 0x3ff-1) {
|
||||||
|
/* we don't do it in ARTIQ */
|
||||||
|
/* raise inexact if x!=0 */
|
||||||
|
// FORCE_EVAL(x + 0x1p52);
|
||||||
|
return 0*u.f;
|
||||||
|
}
|
||||||
|
y = (double)(x + 0x1p52) - 0x1p52 - x;
|
||||||
|
if (y > 0.5)
|
||||||
|
y = y + x - 1;
|
||||||
|
else if (y <= -0.5)
|
||||||
|
y = y + x + 1;
|
||||||
|
else
|
||||||
|
y = y + x;
|
||||||
|
if (u.i >> 63)
|
||||||
|
y = -y;
|
||||||
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called by kernel */
|
/* called by kernel */
|
||||||
|
|
Loading…
Reference in New Issue