diff options
author | Mike Pall <mike> | 2018-05-20 12:25:36 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2018-05-20 12:25:36 +0200 |
commit | f5d424afe8b9395f0df05aba905e0e1f6a2262b8 (patch) | |
tree | 822729c9c00452497cf41c03d765e8605cc773db /src | |
parent | cf7a0540a3a9f80fc729211eb21d1e9b72acc89c (diff) | |
download | luajit-f5d424afe8b9395f0df05aba905e0e1f6a2262b8.tar.gz luajit-f5d424afe8b9395f0df05aba905e0e1f6a2262b8.tar.bz2 luajit-f5d424afe8b9395f0df05aba905e0e1f6a2262b8.zip |
FFI: Make FP to U64 conversions match JIT backend behavior.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_obj.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/lj_obj.h b/src/lj_obj.h index e70b0032..2ee526cf 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -816,14 +816,22 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) | |||
816 | #define lj_num2int(n) ((int32_t)(n)) | 816 | #define lj_num2int(n) ((int32_t)(n)) |
817 | #endif | 817 | #endif |
818 | 818 | ||
819 | /* | ||
820 | ** This must match the JIT backend behavior. In particular for archs | ||
821 | ** that don't have a common hardware instruction for this conversion. | ||
822 | ** Note that signed FP to unsigned int conversions have an undefined | ||
823 | ** result and should never be relied upon in portable FFI code. | ||
824 | ** See also: C99 or C11 standard, 6.3.1.4, footnote of (1). | ||
825 | */ | ||
819 | static LJ_AINLINE uint64_t lj_num2u64(lua_Number n) | 826 | static LJ_AINLINE uint64_t lj_num2u64(lua_Number n) |
820 | { | 827 | { |
821 | #ifdef _MSC_VER | 828 | #if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS |
822 | if (n >= 9223372036854775808.0) /* They think it's a feature. */ | 829 | int64_t i = (int64_t)n; |
823 | return (uint64_t)(int64_t)(n - 18446744073709551616.0); | 830 | if (i < 0) i = (int64_t)(n - 18446744073709551616.0); |
824 | else | 831 | return (uint64_t)i; |
832 | #else | ||
833 | return (uint64_t)n; | ||
825 | #endif | 834 | #endif |
826 | return (uint64_t)n; | ||
827 | } | 835 | } |
828 | 836 | ||
829 | static LJ_AINLINE int32_t numberVint(cTValue *o) | 837 | static LJ_AINLINE int32_t numberVint(cTValue *o) |