Blame SOURCES/0067-Revert-FFI-Make-FP-to-U64-conversions-match-JIT-back.patch

006bc1
From 49f19e7b31fc033ac1e9208580b5be31e2b66b19 Mon Sep 17 00:00:00 2001
006bc1
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
006bc1
Date: Thu, 14 Mar 2019 23:08:24 +0530
006bc1
Subject: [PATCH 67/72] Revert "FFI: Make FP to U64 conversions match JIT
006bc1
 backend behavior."
006bc1
006bc1
This reverts commit f5d424afe8b9395f0df05aba905e0e1f6a2262b8.
006bc1
006bc1
The patch breaks test 279, i.e.
006bc1
006bc1
  assert(tostring(bit.band(1ll, 1, 1ull, -1)) == "1ULL")
006bc1
006bc1
The patch was put in to make the JIT and interpreter behaviour
006bc1
consistent[1] for float to unsigned int conversions but it ended up
006bc1
making things worse.  There needs to be a better fix for this.
006bc1
006bc1
[1] https://github.com/LuaJIT/LuaJIT/pull/415
006bc1
---
006bc1
 src/lj_obj.h | 18 +++++-------------
006bc1
 1 file changed, 5 insertions(+), 13 deletions(-)
006bc1
006bc1
diff --git a/src/lj_obj.h b/src/lj_obj.h
006bc1
index 72b7ace..c7e4742 100644
006bc1
--- a/src/lj_obj.h
006bc1
+++ b/src/lj_obj.h
006bc1
@@ -942,22 +942,14 @@ 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
-#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
+#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
 #endif
006bc1
+    return (uint64_t)n;
006bc1
 }
006bc1
 
006bc1
 static LJ_AINLINE int32_t numberVint(cTValue *o)
006bc1
-- 
006bc1
2.20.1
006bc1