Bug 1334239 - Baldr: re-enable SigIdDesc immediate optimization (r=bbouvier)
authorLuke Wagner <luke@mozilla.com>
Thu, 02 Feb 2017 14:33:07 -0600
changeset 332353 fb57bb8234adb76e65e11a3d0a00740cc7de10fd
parent 332352 3d1891948fe9f337f4af1df67b5c1b6cc107a4b0
child 332354 223ff75af17c58cd1c588db44819d6ac4ab8ddb3
push id31304
push usercbook@mozilla.com
push dateFri, 03 Feb 2017 12:25:47 +0000
treeherdermozilla-central@9f17a6fc04f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1334239
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1334239 - Baldr: re-enable SigIdDesc immediate optimization (r=bbouvier) MozReview-Commit-ID: H8WJ8nandop
js/src/wasm/WasmTypes.cpp
--- a/js/src/wasm/WasmTypes.cpp
+++ b/js/src/wasm/WasmTypes.cpp
@@ -557,35 +557,68 @@ static const unsigned sTagBits = 1;
 static const unsigned sReturnBit = 1;
 static const unsigned sLengthBits = 4;
 static const unsigned sTypeBits = 2;
 static const unsigned sMaxTypes = (sTotalBits - sTagBits - sReturnBit - sLengthBits) / sTypeBits;
 
 static bool
 IsImmediateType(ValType vt)
 {
-    MOZ_ASSERT(uint32_t(vt) > 0);
-    return (uint32_t(vt) - 1) < (1 << sTypeBits);
+    switch (vt) {
+      case ValType::I32:
+      case ValType::I64:
+      case ValType::F32:
+      case ValType::F64:
+        return true;
+      case ValType::I8x16:
+      case ValType::I16x8:
+      case ValType::I32x4:
+      case ValType::F32x4:
+      case ValType::B8x16:
+      case ValType::B16x8:
+      case ValType::B32x4:
+        return false;
+    }
+    MOZ_CRASH("bad ValType");
 }
 
-static bool
-IsImmediateType(ExprType et)
+static unsigned
+EncodeImmediateType(ValType vt)
 {
-    return et == ExprType::Void || IsImmediateType(NonVoidToValType(et));
+    static_assert(3 < (1 << sTypeBits), "fits");
+    switch (vt) {
+      case ValType::I32:
+        return 0;
+      case ValType::I64:
+        return 1;
+      case ValType::F32:
+        return 2;
+      case ValType::F64:
+        return 3;
+      case ValType::I8x16:
+      case ValType::I16x8:
+      case ValType::I32x4:
+      case ValType::F32x4:
+      case ValType::B8x16:
+      case ValType::B16x8:
+      case ValType::B32x4:
+        break;
+    }
+    MOZ_CRASH("bad ValType");
 }
 
 /* static */ bool
 SigIdDesc::isGlobal(const Sig& sig)
 {
     unsigned numTypes = (sig.ret() == ExprType::Void ? 0 : 1) +
                         (sig.args().length());
     if (numTypes > sMaxTypes)
         return true;
 
-    if (!IsImmediateType(sig.ret()))
+    if (sig.ret() != ExprType::Void && !IsImmediateType(NonVoidToValType(sig.ret())))
         return true;
 
     for (ValType v : sig.args()) {
         if (!IsImmediateType(v))
             return true;
     }
 
     return false;
@@ -601,45 +634,37 @@ SigIdDesc::global(const Sig& sig, uint32
 static ImmediateType
 LengthToBits(uint32_t length)
 {
     static_assert(sMaxTypes <= ((1 << sLengthBits) - 1), "fits");
     MOZ_ASSERT(length <= sMaxTypes);
     return length;
 }
 
-static ImmediateType
-TypeToBits(ValType type)
-{
-    static_assert(3 <= ((1 << sTypeBits) - 1), "fits");
-    MOZ_ASSERT(uint32_t(type) >= 1 && uint32_t(type) <= 4);
-    return uint32_t(type) - 1;
-}
-
 /* static */ SigIdDesc
 SigIdDesc::immediate(const Sig& sig)
 {
     ImmediateType immediate = ImmediateBit;
     uint32_t shift = sTagBits;
 
     if (sig.ret() != ExprType::Void) {
         immediate |= (1 << shift);
         shift += sReturnBit;
 
-        immediate |= TypeToBits(NonVoidToValType(sig.ret())) << shift;
+        immediate |= EncodeImmediateType(NonVoidToValType(sig.ret())) << shift;
         shift += sTypeBits;
     } else {
         shift += sReturnBit;
     }
 
     immediate |= LengthToBits(sig.args().length()) << shift;
     shift += sLengthBits;
 
     for (ValType argType : sig.args()) {
-        immediate |= TypeToBits(argType) << shift;
+        immediate |= EncodeImmediateType(argType) << shift;
         shift += sTypeBits;
     }
 
     MOZ_ASSERT(shift <= sTotalBits);
     return SigIdDesc(Kind::Immediate, immediate);
 }
 
 size_t