Jelajahi Sumber

fix asm.js issue where fixnum was causing us to use uint div/mod

Michael Holman 10 tahun lalu
induk
melakukan
abb85c4ecb

+ 2 - 1
lib/Runtime/Language/AsmJsByteCodeGenerator.cpp

@@ -663,7 +663,8 @@ namespace Js
         {
             CheckNodeLocation( lhsEmit, int );
             CheckNodeLocation( rhsEmit, int );
-            auto opType = lType.isUnsigned() ? BMOT_UInt : BMOT_Int;
+            // because fixnum can be either signed or unsigned, use both lhs and rhs to infer sign
+            auto opType = (lType.isSigned() && rType.isSigned()) ? BMOT_Int : BMOT_UInt;
             if (op == BMO_REM || op == BMO_DIV)
             {
                 // div and rem must have explicit sign

+ 7 - 0
test/AsmJs/rlexe.xml

@@ -771,4 +771,11 @@
       <compile-flags>-forcedeferparse -testtrace:asmjs -simdjs</compile-flags>
     </default>
   </test>
+  <test>
+    <default>
+      <files>uint.js</files>
+      <baseline>uint.baseline</baseline>
+      <compile-flags>-maic:1 -testtrace:asmjs -simdjs</compile-flags>
+    </default>
+  </test>
 </regress-exe>

+ 6 - 0
test/AsmJs/uint.baseline

@@ -0,0 +1,6 @@
+Successfully compiled asm.js code
+Successfully compiled asm.js code
+0
+0
+1
+1

+ 27 - 0
test/AsmJs/uint.js

@@ -0,0 +1,27 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+let asmHeap = new ArrayBuffer(1 << 20);
+let m = function (stdlib, foreign, heap) {
+  'use asm';
+  function f(d0) {
+    d0 = +d0;
+    return 1 % ~~d0 | 0;
+  }
+  return f;
+}({}, {}, asmHeap);
+print(m(4294967295));
+print(m(4294967295));
+
+m = function (stdlib, foreign, heap) {
+  'use asm';
+  function f(d0) {
+    d0 = +d0;
+    return 1 % (~~d0 >>> 0) | 0;
+  }
+  return f;
+}({}, {}, asmHeap);
+print(m(4294967295));
+print(m(4294967295));