Blame SOURCES/0039-FFI-Make-FP-to-U64-conversions-match-JIT-backend-beh.patch

006bc1
commit 362f034c1b91d52ea2cf971314ed4e0c24348bff
006bc1
Merge: 260b9b4 f5d424a
006bc1
Author: Mike Pall <mike>
006bc1
Date:   Sun May 20 12:28:10 2018 +0200
006bc1
006bc1
    Merge branch 'master' into v2.1
006bc1
006bc1
From f5d424afe8b9395f0df05aba905e0e1f6a2262b8 Mon Sep 17 00:00:00 2001
006bc1
From: Mike Pall <mike>
006bc1
Date: Sun, 20 May 2018 12:25:36 +0200
006bc1
Subject: [PATCH 39/72] FFI: Make FP to U64 conversions match JIT backend
006bc1
 behavior.
006bc1
006bc1
---
006bc1
 src/lj_obj.h | 18 +++++++++++++-----
006bc1
 1 file changed, 13 insertions(+), 5 deletions(-)
006bc1
006bc1
diff --git a/src/lj_obj.h b/src/lj_obj.h
006bc1
index e70b003..2ee526c 100644
006bc1
--- a/src/lj_obj.h
006bc1
+++ b/src/lj_obj.h
006bc1
@@ -816,14 +816,22 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
006bc1
 
006bc1
 #define lj_num2int(n)   ((int32_t)(n))
006bc1
 
006bc1
+/*
006bc1
+** This must match the JIT backend behavior. In particular for archs
006bc1
+** that don't have a common hardware instruction for this conversion.
006bc1
+** Note that signed FP to unsigned int conversions have an undefined
006bc1
+** result and should never be relied upon in portable FFI code.
006bc1
+** See also: C99 or C11 standard, 6.3.1.4, footnote of (1).
006bc1
+*/
006bc1
 static LJ_AINLINE uint64_t lj_num2u64(lua_Number n)
006bc1
 {
006bc1
-#ifdef _MSC_VER
006bc1
-  if (n >= 9223372036854775808.0)  /* They think it's a feature. */
006bc1
-    return (uint64_t)(int64_t)(n - 18446744073709551616.0);
006bc1
-  else
006bc1
+#if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS
006bc1
+  int64_t i = (int64_t)n;
006bc1
+  if (i < 0) i = (int64_t)(n - 18446744073709551616.0);
006bc1
+  return (uint64_t)i;
006bc1
+#else
006bc1
+  return (uint64_t)n;
006bc1
 #endif
006bc1
-    return (uint64_t)n;
006bc1
 }
006bc1
 
006bc1
 static LJ_AINLINE int32_t numberVint(cTValue *o)
006bc1
-- 
006bc1
2.20.1
006bc1