aboutsummaryrefslogtreecommitdiff
path: root/lib/Target
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-03 17:34:29 -0500
committerAlon Zakai <alonzakai@gmail.com>2014-02-03 17:34:29 -0500
commit4a073eaf7a387755247589f972b3b3057ddd4e87 (patch)
treeafd106471890198b12585e894dbc7eb93acfe261 /lib/Target
parenta263e839c76bcba24fb707ed338ed99cc35f5a15 (diff)
handle floats in casts to int
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/JSBackend/CallHandlers.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Target/JSBackend/CallHandlers.h b/lib/Target/JSBackend/CallHandlers.h
index a37d11a34a..8c97459375 100644
--- a/lib/Target/JSBackend/CallHandlers.h
+++ b/lib/Target/JSBackend/CallHandlers.h
@@ -168,12 +168,16 @@ DEF_CALL_HANDLER(getHigh32, {
DEF_CALL_HANDLER(setHigh32, {
return "tempRet0 = " + getValueAsStr(CI->getOperand(0));
})
+// XXX float handling here is not optimal
#define TO_I(low, high) \
DEF_CALL_HANDLER(low, { \
- return getAssign(getJSName(CI), CI->getType()) + "(~~" + getValueAsStr(CI->getOperand(0)) + ")>>>0"; \
+ std::string Input = getValueAsStr(CI->getOperand(0)); \
+ if (PreciseF32 && CI->getOperand(0)->getType()->isFloatTy()) Input = "+" + Input; \
+ return getAssign(getJSName(CI), CI->getType()) + "(~~" + Input + ")>>>0"; \
}) \
DEF_CALL_HANDLER(high, { \
std::string Input = getValueAsStr(CI->getOperand(0)); \
+ if (PreciseF32 && CI->getOperand(0)->getType()->isFloatTy()) Input = "+" + Input; \
return getAssign(getJSName(CI), CI->getType()) + "+Math_abs(" + Input + ") >= +1 ? " + Input + " > +0 ? (Math_min(+Math_floor(" + Input + " / +4294967296), +4294967295) | 0) >>> 0 : ~~+Math_ceil((" + Input + " - +(~~" + Input + " >>> 0)) / +4294967296) >>> 0 : 0"; \
})
TO_I(FtoILow, FtoIHigh);