]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Merge branch 'master' into v2.1
authorMike Pall <mike>
Sun, 20 May 2018 10:28:10 +0000 (12:28 +0200)
committerMike Pall <mike>
Sun, 20 May 2018 10:28:10 +0000 (12:28 +0200)
1  2 
src/lj_obj.h

diff --cc src/lj_obj.h
index c7e47422bf9918ab7a15ea036bc8740786896cde,2ee526cf803b548a43d1f02bc98389347c24cb29..72b7ace837989957de3ee4d4598623d61c6264a3
@@@ -940,16 -810,28 +940,24 @@@ static LJ_AINLINE int32_t lj_num2bit(lu
  #endif
  }
  
 -#if LJ_TARGET_X86 && !defined(__SSE2__)
 -#define lj_num2int(n)   lj_num2bit((n))
 -#else
  #define lj_num2int(n)   ((int32_t)(n))
 -#endif
  
+ /*
+ ** This must match the JIT backend behavior. In particular for archs
+ ** that don't have a common hardware instruction for this conversion.
+ ** Note that signed FP to unsigned int conversions have an undefined
+ ** result and should never be relied upon in portable FFI code.
+ ** See also: C99 or C11 standard, 6.3.1.4, footnote of (1).
+ */
  static LJ_AINLINE uint64_t lj_num2u64(lua_Number n)
  {
- #ifdef _MSC_VER
-   if (n >= 9223372036854775808.0)  /* They think it's a feature. */
-     return (uint64_t)(int64_t)(n - 18446744073709551616.0);
-   else
+ #if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS
+   int64_t i = (int64_t)n;
+   if (i < 0) i = (int64_t)(n - 18446744073709551616.0);
+   return (uint64_t)i;
+ #else
+   return (uint64_t)n;
  #endif
-     return (uint64_t)n;
  }
  
  static LJ_AINLINE int32_t numberVint(cTValue *o)