Bug 1115748 - SpiderMonkey: Fix spewing of 8-bit register names affected by REX prefixes r=jandem
authorDan Gohman <sunfish@mozilla.com>
Sun, 28 Dec 2014 07:04:12 -0800
changeset 238174 165bbe7a3759d910786c9b1d63a935232d8bcc20
parent 238173 e1219e861f783b9865e6785ca8651057e8352a86
child 238175 13a2592c2e2a96e2f742770c02aec933c5aff789
push id7472
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 20:36:27 +0000
treeherdermozilla-aurora@300ca104f8fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1115748
milestone37.0a1
Bug 1115748 - SpiderMonkey: Fix spewing of 8-bit register names affected by REX prefixes r=jandem
js/src/jit/shared/BaseAssembler-x86-shared.h
--- a/js/src/jit/shared/BaseAssembler-x86-shared.h
+++ b/js/src/jit/shared/BaseAssembler-x86-shared.h
@@ -94,41 +94,55 @@ namespace X86Registers {
     static const char* nameFPReg(XMMRegisterID fpreg)
     {
         static const char* const xmmnames[16]
           = { "%xmm0", "%xmm1", "%xmm2", "%xmm3",
               "%xmm4", "%xmm5", "%xmm6", "%xmm7",
               "%xmm8", "%xmm9", "%xmm10", "%xmm11",
               "%xmm12", "%xmm13", "%xmm14", "%xmm15" };
         int off = (XMMRegisterID)fpreg - (XMMRegisterID)xmm0;
-        return (off < 0 || off > 15) ? "%xmm?" : xmmnames[off];
+        MOZ_ASSERT(off >= 0 && size_t(off) < mozilla::ArrayLength(xmmnames));
+        return xmmnames[off];
     }
 
     static const char* nameIReg(int szB, RegisterID reg)
     {
         static const char* const r64names[16]
           = { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
               "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" };
         static const char* const r32names[16]
           = { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
               "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" };
         static const char* const r16names[16]
           = { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
               "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" };
         static const char* const r8names[16]
-          = { "%al", "%cl", "%dl", "%bl", "%ah/spl", "%ch/bpl", "%dh/sil", "%bh/dil",
+          = { "%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
               "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" };
         int          off = (RegisterID)reg - (RegisterID)eax;
+        MOZ_ASSERT(off >= 0 && size_t(off) < mozilla::ArrayLength(r64names));
         const char* const* tab = r64names;
         switch (szB) {
             case 1: tab = r8names; break;
             case 2: tab = r16names; break;
             case 4: tab = r32names; break;
         }
-        return (off < 0 || off > 15) ? "%r???" : tab[off];
+        return tab[off];
+    }
+
+    static const char* nameI8Reg_norex(RegisterID reg)
+    {
+        // The same as r8names above, except that %spl through %dil are replaced
+        // by %ah through %bh since there is to be no REX prefix.
+        static const char* const r8names_norex[16]
+          = { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
+              "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" };
+        int off = (RegisterID)reg - (RegisterID)eax;
+        MOZ_ASSERT(off >= 0 && size_t(off) < mozilla::ArrayLength(r8names_norex));
+        return r8names_norex[off];
     }
 
     static const char* nameIReg(RegisterID reg)
     {
 #       ifdef JS_CODEGEN_X64
         return nameIReg(8, reg);
 #       else
         return nameIReg(4, reg);
@@ -211,17 +225,18 @@ public:
     } ConditionCmp;
 
     static const char* nameCC(Condition cc)
     {
         static const char* const names[16]
           = { "o ", "no", "b ", "ae", "e ", "ne", "be", "a ",
               "s ", "ns", "p ", "np", "l ", "ge", "le", "g " };
         int ix = (int)cc;
-        return (ix < 0 || ix > 15) ? "??" : names[ix];
+        MOZ_ASSERT(ix >= 0 && size_t(ix) < mozilla::ArrayLength(names));
+        return names[ix];
     }
 
     // Rounding modes for ROUNDSD.
     typedef enum {
         RoundToNearest = 0x0,
         RoundDown      = 0x1,
         RoundUp        = 0x2,
         RoundToZero    = 0x3
@@ -1934,17 +1949,17 @@ public:
             m_formatter.oneByteOp8(OP_GROUP3_EbIb, lhs, GROUP3_OP_TEST);
         m_formatter.immediate8(rhs);
     }
 
     // Like testb_i8r, but never emits a REX prefix. This may be used to
     // reference ah..bh.
     void testb_i8r_norex(int rhs, RegisterID lhs)
     {
-        spew("testb      $0x%x, %s", rhs, nameIReg(1, lhs));
+        spew("testb      $0x%x, %s", rhs, nameI8Reg_norex(lhs));
         m_formatter.oneByteOp8_norex(OP_GROUP3_EbIb, lhs, GROUP3_OP_TEST);
         m_formatter.immediate8(rhs);
     }
 
     void setCC_r(Condition cond, RegisterID lhs)
     {
         spew("set%s      %s", nameCC(cond), nameIReg(1, lhs));
         m_formatter.twoByteOp8(setccOpcode(cond), lhs, (GroupOpcodeID)0);