diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-03 18:34:11 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-03 18:34:11 -0500 |
commit | 34290e54d4c4fb87518a664c77244f6e7e4fca6e (patch) | |
tree | 4bd2ffcb33166f71dda5f805e5c162d0083d5ce6 /lib/Target | |
parent | 4a073eaf7a387755247589f972b3b3057ddd4e87 (diff) |
fix asm casts of float as ffi params
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/JSBackend/CallHandlers.h | 10 | ||||
-rw-r--r-- | lib/Target/JSBackend/JSBackend.cpp | 9 |
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/Target/JSBackend/CallHandlers.h b/lib/Target/JSBackend/CallHandlers.h index 8c97459375..d3b3dfa668 100644 --- a/lib/Target/JSBackend/CallHandlers.h +++ b/lib/Target/JSBackend/CallHandlers.h @@ -80,11 +80,14 @@ DEF_CALL_HANDLER(__default__, { } if (NumArgs > 0) text += ","; } + // this is an ffi call if we need casts, and it is not a Math_ builtin + bool FFI = NeedCasts && Name.find("Math_") != 0; + unsigned FFI_OUT = FFI ? ASM_FFI_OUT : 0; for (int i = 0; i < NumArgs; i++) { if (!NeedCasts) { text += getValueAsStr(CI->getOperand(i)); } else { - text += getValueAsCastStr(CI->getOperand(i), ASM_NONSPECIFIC); + text += getValueAsCastStr(CI->getOperand(i), ASM_NONSPECIFIC | FFI_OUT); } if (i < NumArgs - 1) text += ","; } @@ -98,9 +101,8 @@ DEF_CALL_HANDLER(__default__, { getAssign(getJSName(CI), InstRT); // ensure the variable is defined, but do not emit it here // it should have 0 uses, but just to be safe } else if (!ActualRT->isVoidTy()) { - // this is an ffi call if we need casts, and it is not a Math_ builtin - unsigned FFI = NeedCasts && text.find("Math_") != 0 ? ASM_FFI : 0; - text = getAssign(getJSName(CI), ActualRT) + getCast(text, ActualRT, ASM_NONSPECIFIC | FFI); + unsigned FFI_IN = FFI ? ASM_FFI_IN : 0; + text = getAssign(getJSName(CI), ActualRT) + getCast(text, ActualRT, ASM_NONSPECIFIC | FFI_IN); } return text; }) diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp index 2a622c81f3..3345affcbb 100644 --- a/lib/Target/JSBackend/JSBackend.cpp +++ b/lib/Target/JSBackend/JSBackend.cpp @@ -75,7 +75,8 @@ namespace { #define ASM_SIGNED 0 #define ASM_UNSIGNED 1 #define ASM_NONSPECIFIC 2 // nonspecific means to not differentiate ints. |0 for all, regardless of size and sign - #define ASM_FFI 4 // FFI values are limited to things that work in ffis + #define ASM_FFI_IN 4 // FFI return values are limited to things that work in ffis + #define ASM_FFI_OUT 8 // params to FFIs are limited to things that work in ffis typedef unsigned AsmCast; const char *SIMDLane = "XYZW"; @@ -474,8 +475,8 @@ std::string JSWriter::getCast(const StringRef &s, const Type *t, AsmCast sign) { if (!t->isVectorTy()) assert(false && "Unsupported type"); } case Type::FloatTyID: { - if (PreciseF32) { - if (sign & ASM_FFI) { + if (PreciseF32 && !(sign & ASM_FFI_OUT)) { + if (sign & ASM_FFI_IN) { return ("Math_fround(+(" + s + "))").str(); } else { return ("Math_fround(" + s + ")").str(); @@ -816,7 +817,7 @@ std::string JSWriter::getConstant(const Constant* CV, AsmCast sign) { } else { if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { std::string S = ftostr_exact(CFP); - if (PreciseF32 && CV->getType()->isFloatTy()) { + if (PreciseF32 && CV->getType()->isFloatTy() && !(sign & ASM_FFI_OUT)) { S = "Math_fround(" + S + ")"; } else if (S[0] != '+') { S = '+' + S; |