[JSC] Mask TrustedImm32 to 8bit in MacroAssembler for 8bit operations
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Jul 2016 14:33:26 +0000 (14:33 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Jul 2016 14:33:26 +0000 (14:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159334

Reviewed by Filip Pizlo.

Previously, in 8bit operations (like add8, compare8, test8, branch8, branchTest8 etc.),
we require that the given TrustedImm32 is in range of 8bit. While achieving this in
the manual MacroAssembler calling is easy, in Air, we don't guarantee that the higher bit
of the 8bit argument is cleared. So the current assertions are invalid.

This patch relaxes the above restriction. By removing this assertion,
8bit operations can take arbitrary 32bit imms. And only lower 8bit are effective when
emitting the code in these methods.

* assembler/MacroAssembler.h:
(JSC::MacroAssembler::branchTest8):
* assembler/MacroAssemblerARM.h:
(JSC::MacroAssemblerARM::store8):
(JSC::MacroAssemblerARM::branch8):
(JSC::MacroAssemblerARM::branchTest8):
(JSC::MacroAssemblerARM::compare8):
(JSC::MacroAssemblerARM::test8):
* assembler/MacroAssemblerARM64.h:
(JSC::MacroAssemblerARM64::store8):
(JSC::MacroAssemblerARM64::branch8):
(JSC::MacroAssemblerARM64::branchTest8):
(JSC::MacroAssemblerARM64::compare8):
(JSC::MacroAssemblerARM64::test8):
* assembler/MacroAssemblerARMv7.h:
(JSC::MacroAssemblerARMv7::store8):
(JSC::MacroAssemblerARMv7::branch8):
(JSC::MacroAssemblerARMv7::branchTest8):
(JSC::MacroAssemblerARMv7::compare8):
(JSC::MacroAssemblerARMv7::test8):
* assembler/MacroAssemblerMIPS.h:
(JSC::MacroAssemblerMIPS::store8):
(JSC::MacroAssemblerMIPS::branch8):
(JSC::MacroAssemblerMIPS::compare8):
(JSC::MacroAssemblerMIPS::branchTest8):
(JSC::MacroAssemblerMIPS::test8):
* assembler/MacroAssemblerSH4.h:
(JSC::MacroAssemblerSH4::store8):
(JSC::MacroAssemblerSH4::branchTest8):
(JSC::MacroAssemblerSH4::branch8):
(JSC::MacroAssemblerSH4::compare8):
(JSC::MacroAssemblerSH4::test8):
* assembler/MacroAssemblerX86.h:
(JSC::MacroAssemblerX86::store8):
(JSC::MacroAssemblerX86::branch8):
(JSC::MacroAssemblerX86::branchTest8):
* assembler/MacroAssemblerX86Common.h:
(JSC::MacroAssemblerX86Common::add8):
(JSC::MacroAssemblerX86Common::store8):
(JSC::MacroAssemblerX86Common::branch8):
(JSC::MacroAssemblerX86Common::branchTest8):
(JSC::MacroAssemblerX86Common::compare8):
(JSC::MacroAssemblerX86Common::test8):
* assembler/MacroAssemblerX86_64.h:
(JSC::MacroAssemblerX86_64::store8):
(JSC::MacroAssemblerX86_64::branch8):
(JSC::MacroAssemblerX86_64::branchTest8):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203331 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/assembler/MacroAssembler.h
Source/JavaScriptCore/assembler/MacroAssemblerARM.h
Source/JavaScriptCore/assembler/MacroAssemblerARM64.h
Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h
Source/JavaScriptCore/assembler/MacroAssemblerMIPS.h
Source/JavaScriptCore/assembler/MacroAssemblerSH4.h
Source/JavaScriptCore/assembler/MacroAssemblerX86.h
Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h
Source/JavaScriptCore/assembler/MacroAssemblerX86_64.h

index b28b0ef..49791a8 100644 (file)
@@ -1,3 +1,67 @@
+2016-07-17  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Mask TrustedImm32 to 8bit in MacroAssembler for 8bit operations
+        https://bugs.webkit.org/show_bug.cgi?id=159334
+
+        Reviewed by Filip Pizlo.
+
+        Previously, in 8bit operations (like add8, compare8, test8, branch8, branchTest8 etc.),
+        we require that the given TrustedImm32 is in range of 8bit. While achieving this in
+        the manual MacroAssembler calling is easy, in Air, we don't guarantee that the higher bit
+        of the 8bit argument is cleared. So the current assertions are invalid.
+
+        This patch relaxes the above restriction. By removing this assertion,
+        8bit operations can take arbitrary 32bit imms. And only lower 8bit are effective when
+        emitting the code in these methods.
+
+        * assembler/MacroAssembler.h:
+        (JSC::MacroAssembler::branchTest8):
+        * assembler/MacroAssemblerARM.h:
+        (JSC::MacroAssemblerARM::store8):
+        (JSC::MacroAssemblerARM::branch8):
+        (JSC::MacroAssemblerARM::branchTest8):
+        (JSC::MacroAssemblerARM::compare8):
+        (JSC::MacroAssemblerARM::test8):
+        * assembler/MacroAssemblerARM64.h:
+        (JSC::MacroAssemblerARM64::store8):
+        (JSC::MacroAssemblerARM64::branch8):
+        (JSC::MacroAssemblerARM64::branchTest8):
+        (JSC::MacroAssemblerARM64::compare8):
+        (JSC::MacroAssemblerARM64::test8):
+        * assembler/MacroAssemblerARMv7.h:
+        (JSC::MacroAssemblerARMv7::store8):
+        (JSC::MacroAssemblerARMv7::branch8):
+        (JSC::MacroAssemblerARMv7::branchTest8):
+        (JSC::MacroAssemblerARMv7::compare8):
+        (JSC::MacroAssemblerARMv7::test8):
+        * assembler/MacroAssemblerMIPS.h:
+        (JSC::MacroAssemblerMIPS::store8):
+        (JSC::MacroAssemblerMIPS::branch8):
+        (JSC::MacroAssemblerMIPS::compare8):
+        (JSC::MacroAssemblerMIPS::branchTest8):
+        (JSC::MacroAssemblerMIPS::test8):
+        * assembler/MacroAssemblerSH4.h:
+        (JSC::MacroAssemblerSH4::store8):
+        (JSC::MacroAssemblerSH4::branchTest8):
+        (JSC::MacroAssemblerSH4::branch8):
+        (JSC::MacroAssemblerSH4::compare8):
+        (JSC::MacroAssemblerSH4::test8):
+        * assembler/MacroAssemblerX86.h:
+        (JSC::MacroAssemblerX86::store8):
+        (JSC::MacroAssemblerX86::branch8):
+        (JSC::MacroAssemblerX86::branchTest8):
+        * assembler/MacroAssemblerX86Common.h:
+        (JSC::MacroAssemblerX86Common::add8):
+        (JSC::MacroAssemblerX86Common::store8):
+        (JSC::MacroAssemblerX86Common::branch8):
+        (JSC::MacroAssemblerX86Common::branchTest8):
+        (JSC::MacroAssemblerX86Common::compare8):
+        (JSC::MacroAssemblerX86Common::test8):
+        * assembler/MacroAssemblerX86_64.h:
+        (JSC::MacroAssemblerX86_64::store8):
+        (JSC::MacroAssemblerX86_64::branch8):
+        (JSC::MacroAssemblerX86_64::branchTest8):
+
 2016-07-16  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, rolling out r203318.
index 2e35b5f..98c34e0 100644 (file)
@@ -790,7 +790,8 @@ public:
     using MacroAssemblerBase::branchTest8;
     Jump branchTest8(ResultCondition cond, ExtendedAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
-        return MacroAssemblerBase::branchTest8(cond, Address(address.base, address.offset), mask);
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
+        return MacroAssemblerBase::branchTest8(cond, Address(address.base, address.offset), mask8);
     }
 
 #else // !CPU(X86_64)
index bbe8269..3e1062c 100644 (file)
@@ -501,14 +501,16 @@ public:
 
     void store8(TrustedImm32 imm, ImplicitAddress address)
     {
-        move(imm, ARMRegisters::S1);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        move(imm8, ARMRegisters::S1);
         store8(ARMRegisters::S1, address);
     }
 
     void store8(TrustedImm32 imm, const void* address)
     {
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
         move(TrustedImm32(reinterpret_cast<ARMWord>(address)), ARMRegisters::S0);
-        move(imm, ARMRegisters::S1);
+        move(imm8, ARMRegisters::S1);
         m_assembler.dtrUp(ARMAssembler::StoreUint8, ARMRegisters::S1, ARMRegisters::S0, 0);
     }
 
@@ -623,22 +625,24 @@ public:
 
     Jump branch8(RelationalCondition cond, Address left, TrustedImm32 right)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, ARMRegisters::S1);
-        return branch32(cond, ARMRegisters::S1, right);
+        return branch32(cond, ARMRegisters::S1, right8);
     }
 
     Jump branch8(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
     {
-        ASSERT(!(right.m_value & 0xFFFFFF00));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, ARMRegisters::S1);
-        return branch32(cond, ARMRegisters::S1, right);
+        return branch32(cond, ARMRegisters::S1, right8);
     }
 
     Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         move(TrustedImmPtr(left.m_ptr), ARMRegisters::S1);
         load8(Address(ARMRegisters::S1), ARMRegisters::S1);
-        return branch32(cond, ARMRegisters::S1, right);
+        return branch32(cond, ARMRegisters::S1, right8);
     }
 
     Jump branch32(RelationalCondition cond, RegisterID left, RegisterID right, int useConstantPool = 0)
@@ -685,21 +689,24 @@ public:
 
     Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, ARMRegisters::S1);
-        return branchTest32(cond, ARMRegisters::S1, mask);
+        return branchTest32(cond, ARMRegisters::S1, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, ARMRegisters::S1);
-        return branchTest32(cond, ARMRegisters::S1, mask);
+        return branchTest32(cond, ARMRegisters::S1, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         move(TrustedImmPtr(address.m_ptr), ARMRegisters::S1);
         load8(Address(ARMRegisters::S1), ARMRegisters::S1);
-        return branchTest32(cond, ARMRegisters::S1, mask);
+        return branchTest32(cond, ARMRegisters::S1, mask8);
     }
 
     Jump branchTest32(ResultCondition cond, RegisterID reg, RegisterID mask)
@@ -965,8 +972,9 @@ public:
 
     void compare8(RelationalCondition cond, Address left, TrustedImm32 right, RegisterID dest)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, ARMRegisters::S1);
-        compare32(cond, ARMRegisters::S1, right, dest);
+        compare32(cond, ARMRegisters::S1, right8, dest);
     }
 
     void test32(ResultCondition cond, RegisterID reg, TrustedImm32 mask, RegisterID dest)
@@ -987,8 +995,9 @@ public:
 
     void test8(ResultCondition cond, Address address, TrustedImm32 mask, RegisterID dest)
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, ARMRegisters::S1);
-        test32(cond, ARMRegisters::S1, mask, dest);
+        test32(cond, ARMRegisters::S1, mask8, dest);
     }
 
     void add32(TrustedImm32 imm, RegisterID src, RegisterID dest)
index 768c45f..6e78c7c 100644 (file)
@@ -1408,23 +1408,25 @@ public:
 
     void store8(TrustedImm32 imm, void* address)
     {
-        if (!imm.m_value) {
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        if (!imm8.m_value) {
             store8(ARM64Registers::zr, address);
             return;
         }
 
-        move(imm, getCachedDataTempRegisterIDAndInvalidate());
+        move(imm8, getCachedDataTempRegisterIDAndInvalidate());
         store8(dataTempRegister, address);
     }
 
     void store8(TrustedImm32 imm, ImplicitAddress address)
     {
-        if (!imm.m_value) {
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        if (!imm8.m_value) {
             store8(ARM64Registers::zr, address);
             return;
         }
 
-        move(imm, getCachedDataTempRegisterIDAndInvalidate());
+        move(imm8, getCachedDataTempRegisterIDAndInvalidate());
         store8(dataTempRegister, address);
     }
 
@@ -2402,23 +2404,23 @@ public:
 
     Jump branch8(RelationalCondition cond, Address left, TrustedImm32 right)
     {
-        ASSERT(!(0xffffff00 & right.m_value));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, getCachedMemoryTempRegisterIDAndInvalidate());
-        return branch32(cond, memoryTempRegister, right);
+        return branch32(cond, memoryTempRegister, right8);
     }
 
     Jump branch8(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
     {
-        ASSERT(!(0xffffff00 & right.m_value));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, getCachedMemoryTempRegisterIDAndInvalidate());
-        return branch32(cond, memoryTempRegister, right);
+        return branch32(cond, memoryTempRegister, right8);
     }
     
     Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right)
     {
-        ASSERT(!(0xffffff00 & right.m_value));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left.m_ptr, getCachedMemoryTempRegisterIDAndInvalidate());
-        return branch32(cond, memoryTempRegister, right);
+        return branch32(cond, memoryTempRegister, right8);
     }
     
     Jump branchTest32(ResultCondition cond, RegisterID reg, RegisterID mask)
@@ -2545,27 +2547,31 @@ public:
 
     Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, getCachedDataTempRegisterIDAndInvalidate());
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address.m_ptr, getCachedDataTempRegisterIDAndInvalidate());
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, ExtendedAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         move(TrustedImmPtr(reinterpret_cast<void*>(address.offset)), getCachedDataTempRegisterIDAndInvalidate());
         m_assembler.ldrb(dataTempRegister, address.base, dataTempRegister);
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, getCachedDataTempRegisterIDAndInvalidate());
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump branch32WithUnalignedHalfWords(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
@@ -2975,8 +2981,9 @@ public:
 
     void compare8(RelationalCondition cond, Address left, TrustedImm32 right, RegisterID dest)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, getCachedMemoryTempRegisterIDAndInvalidate());
-        move(right, getCachedDataTempRegisterIDAndInvalidate());
+        move(right8, getCachedDataTempRegisterIDAndInvalidate());
         compare32(cond, memoryTempRegister, dataTempRegister, dest);
     }
 
@@ -3000,8 +3007,9 @@ public:
 
     void test8(ResultCondition cond, Address address, TrustedImm32 mask, RegisterID dest)
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, getCachedMemoryTempRegisterIDAndInvalidate());
-        test32(cond, memoryTempRegister, mask, dest);
+        test32(cond, memoryTempRegister, mask8, dest);
     }
 
     void test64(ResultCondition cond, RegisterID op1, RegisterID op2, RegisterID dest)
index 22336d0..3c8c48d 100644 (file)
@@ -829,13 +829,15 @@ public:
     
     void store8(TrustedImm32 imm, void* address)
     {
-        move(imm, dataTempRegister);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        move(imm8, dataTempRegister);
         store8(dataTempRegister, address);
     }
     
     void store8(TrustedImm32 imm, Address address)
     {
-        move(imm, dataTempRegister);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        move(imm8, dataTempRegister);
         store8(dataTempRegister, address);
     }
     
@@ -1476,32 +1478,34 @@ public:
 
     Jump branch8(RelationalCondition cond, RegisterID left, TrustedImm32 right)
     {
-        compare32AndSetFlags(left, right);
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
+        compare32AndSetFlags(left, right8);
         return Jump(makeBranch(cond));
     }
 
     Jump branch8(RelationalCondition cond, Address left, TrustedImm32 right)
     {
-        ASSERT(!(0xffffff00 & right.m_value));
         // use addressTempRegister incase the branch8 we call uses dataTempRegister. :-/
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, addressTempRegister);
-        return branch8(cond, addressTempRegister, right);
+        return branch8(cond, addressTempRegister, right8);
     }
 
     Jump branch8(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
     {
-        ASSERT(!(0xffffff00 & right.m_value));
         // use addressTempRegister incase the branch32 we call uses dataTempRegister. :-/
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, addressTempRegister);
-        return branch32(cond, addressTempRegister, right);
+        return branch32(cond, addressTempRegister, right8);
     }
     
     Jump branch8(RelationalCondition cond, AbsoluteAddress address, TrustedImm32 right)
     {
         // Use addressTempRegister instead of dataTempRegister, since branch32 uses dataTempRegister.
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         move(TrustedImmPtr(address.m_ptr), addressTempRegister);
         load8(Address(addressTempRegister), addressTempRegister);
-        return branch32(cond, addressTempRegister, right);
+        return branch32(cond, addressTempRegister, right8);
     }
     
     Jump branchTest32(ResultCondition cond, RegisterID reg, RegisterID mask)
@@ -1535,23 +1539,26 @@ public:
     Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
     {
         // use addressTempRegister incase the branchTest8 we call uses dataTempRegister. :-/
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, addressTempRegister);
-        return branchTest32(cond, addressTempRegister, mask);
+        return branchTest32(cond, addressTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
     {
         // use addressTempRegister incase the branchTest8 we call uses dataTempRegister. :-/
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, addressTempRegister);
-        return branchTest32(cond, addressTempRegister, mask);
+        return branchTest32(cond, addressTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
         // use addressTempRegister incase the branchTest8 we call uses dataTempRegister. :-/
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         move(TrustedImmPtr(address.m_ptr), addressTempRegister);
         load8(Address(addressTempRegister), addressTempRegister);
-        return branchTest32(cond, addressTempRegister, mask);
+        return branchTest32(cond, addressTempRegister, mask8);
     }
 
     void jump(RegisterID target)
@@ -1778,8 +1785,9 @@ public:
 
     void compare8(RelationalCondition cond, Address left, TrustedImm32 right, RegisterID dest)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, addressTempRegister);
-        compare32(cond, addressTempRegister, right, dest);
+        compare32(cond, addressTempRegister, right8, dest);
     }
 
     void compare32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
@@ -1805,8 +1813,9 @@ public:
 
     void test8(ResultCondition cond, Address address, TrustedImm32 mask, RegisterID dest)
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, dataTempRegister);
-        test32(dataTempRegister, mask);
+        test32(dataTempRegister, mask8);
         m_assembler.it(armV7Condition(cond), false);
         m_assembler.mov(dest, ARMThumbImmediate::makeUInt16(1));
         m_assembler.mov(dest, ARMThumbImmediate::makeUInt16(0));
index b36ebcf..9deca8f 100644 (file)
@@ -1091,11 +1091,12 @@ public:
             li  addrTemp, address
             sb  src, 0(addrTemp)
         */
-        if (!imm.m_value && !m_fixedWidth) {
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        if (!imm8.m_value && !m_fixedWidth) {
             move(TrustedImmPtr(address), addrTempRegister);
             m_assembler.sb(MIPSRegisters::zero, addrTempRegister, 0);
         } else {
-            move(imm, immTempRegister);
+            move(imm8, immTempRegister);
             move(TrustedImmPtr(address), addrTempRegister);
             m_assembler.sb(immTempRegister, addrTempRegister, 0);
         }
@@ -1103,12 +1104,13 @@ public:
 
     void store8(TrustedImm32 imm, ImplicitAddress address)
     {
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
         if (address.offset >= -32768 && address.offset <= 32767
             && !m_fixedWidth) {
-            if (!imm.m_value)
+            if (!imm8.m_value)
                 m_assembler.sb(MIPSRegisters::zero, address.base, address.offset);
             else {
-                move(imm, immTempRegister);
+                move(imm8, immTempRegister);
                 m_assembler.sb(immTempRegister, address.base, address.offset);
             }
         } else {
@@ -1119,10 +1121,10 @@ public:
               */
             m_assembler.lui(addrTempRegister, (address.offset + 0x8000) >> 16);
             m_assembler.addu(addrTempRegister, addrTempRegister, address.base);
-            if (!imm.m_value && !m_fixedWidth)
+            if (!imm8.m_value && !m_fixedWidth)
                 m_assembler.sb(MIPSRegisters::zero, addrTempRegister, address.offset);
             else {
-                move(imm, immTempRegister);
+                move(imm8, immTempRegister);
                 m_assembler.sb(immTempRegister, addrTempRegister, address.offset);
             }
         }
@@ -1444,38 +1446,35 @@ public:
 
     Jump branch8(RelationalCondition cond, Address left, TrustedImm32 right)
     {
-        // Make sure the immediate value is unsigned 8 bits.
-        ASSERT(!(right.m_value & 0xFFFFFF00));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, dataTempRegister);
-        move(right, immTempRegister);
+        move(right8, immTempRegister);
         return branch32(cond, dataTempRegister, immTempRegister);
     }
 
     Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right)
     {
-        // Make sure the immediate value is unsigned 8 bits.
-        ASSERT(!(right.m_value & 0xFFFFFF00));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, dataTempRegister);
-        move(right, immTempRegister);
+        move(right8, immTempRegister);
         return branch32(cond, dataTempRegister, immTempRegister);
     }
 
     void compare8(RelationalCondition cond, Address left, TrustedImm32 right, RegisterID dest)
     {
-        // Make sure the immediate value is unsigned 8 bits.
-        ASSERT(!(right.m_value & 0xFFFFFF00));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, dataTempRegister);
-        move(right, immTempRegister);
+        move(right8, immTempRegister);
         compare32(cond, dataTempRegister, immTempRegister, dest);
     }
 
     Jump branch8(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
     {
-        ASSERT(!(right.m_value & 0xFFFFFF00));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         load8(left, dataTempRegister);
         // Be careful that the previous load8() uses immTempRegister.
         // So, we need to put move() after load8().
-        move(right, immTempRegister);
+        move(right8, immTempRegister);
         return branch32(cond, dataTempRegister, immTempRegister);
     }
 
@@ -1630,21 +1629,24 @@ public:
 
     Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, dataTempRegister);
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, dataTempRegister);
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         move(TrustedImmPtr(address.m_ptr), dataTempRegister);
         load8(Address(dataTempRegister), dataTempRegister);
-        return branchTest32(cond, dataTempRegister, mask);
+        return branchTest32(cond, dataTempRegister, mask8);
     }
 
     Jump jump()
@@ -2217,14 +2219,15 @@ public:
     void test8(ResultCondition cond, Address address, TrustedImm32 mask, RegisterID dest)
     {
         ASSERT((cond == Zero) || (cond == NonZero));
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         load8(address, dataTempRegister);
-        if (mask.m_value == -1 && !m_fixedWidth) {
+        if (mask8.m_value == -1 && !m_fixedWidth) {
             if (cond == Zero)
                 m_assembler.sltiu(dest, dataTempRegister, 1);
             else
                 m_assembler.sltu(dest, MIPSRegisters::zero, dataTempRegister);
         } else {
-            move(mask, immTempRegister);
+            move(mask8, immTempRegister);
             m_assembler.andInsn(cmpTempRegister, dataTempRegister, immTempRegister);
             if (cond == Zero)
                 m_assembler.sltiu(dest, cmpTempRegister, 1);
index 53e71cf..c12c657 100644 (file)
@@ -921,11 +921,11 @@ public:
 
     void store8(TrustedImm32 imm, void* address)
     {
-        ASSERT((imm.m_value >= -128) && (imm.m_value <= 127));
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
         RegisterID dstptr = claimScratch();
         move(TrustedImmPtr(address), dstptr);
         RegisterID srcval = claimScratch();
-        move(imm, srcval);
+        move(imm8, srcval);
         m_assembler.movbRegMem(srcval, dstptr);
         releaseScratch(dstptr);
         releaseScratch(srcval);
@@ -933,12 +933,12 @@ public:
 
     void store8(TrustedImm32 imm, Address address)
     {
-        ASSERT((imm.m_value >= -128) && (imm.m_value <= 127));
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
         RegisterID dstptr = claimScratch();
         move(address.base, dstptr);
         add32(TrustedImm32(address.offset), dstptr);
         RegisterID srcval = claimScratch();
-        move(imm, srcval);
+        move(imm8, srcval);
         m_assembler.movbRegMem(srcval, dstptr);
         releaseScratch(dstptr);
         releaseScratch(srcval);
@@ -1595,28 +1595,31 @@ public:
 
     Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         RegisterID addressTempRegister = claimScratch();
         load8(address, addressTempRegister);
-        Jump jmp = branchTest32(cond, addressTempRegister, mask);
+        Jump jmp = branchTest32(cond, addressTempRegister, mask8);
         releaseScratch(addressTempRegister);
         return jmp;
     }
 
     Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         RegisterID addressTempRegister = claimScratch();
         load8(address, addressTempRegister);
-        Jump jmp = branchTest32(cond, addressTempRegister, mask);
+        Jump jmp = branchTest32(cond, addressTempRegister, mask8);
         releaseScratch(addressTempRegister);
         return jmp;
     }
 
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         RegisterID addressTempRegister = claimScratch();
         move(TrustedImmPtr(address.m_ptr), addressTempRegister);
         load8(Address(addressTempRegister), addressTempRegister);
-        Jump jmp = branchTest32(cond, addressTempRegister, mask);
+        Jump jmp = branchTest32(cond, addressTempRegister, mask8);
         releaseScratch(addressTempRegister);
         return jmp;
     }
@@ -1633,27 +1636,30 @@ public:
 
     Jump branch8(RelationalCondition cond, Address left, TrustedImm32 right)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         RegisterID addressTempRegister = claimScratch();
         load8(left, addressTempRegister);
-        Jump jmp = branch32(cond, addressTempRegister, right);
+        Jump jmp = branch32(cond, addressTempRegister, right8);
         releaseScratch(addressTempRegister);
         return jmp;
     }
 
     Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         RegisterID addressTempRegister = claimScratch();
         load8(left, addressTempRegister);
-        Jump jmp = branch32(cond, addressTempRegister, right);
+        Jump jmp = branch32(cond, addressTempRegister, right8);
         releaseScratch(addressTempRegister);
         return jmp;
     }
 
     void compare8(RelationalCondition cond, Address left, TrustedImm32 right, RegisterID dest)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         RegisterID addressTempRegister = claimScratch();
         load8(left, addressTempRegister);
-        compare32(cond, addressTempRegister, right, dest);
+        compare32(cond, addressTempRegister, right8, dest);
         releaseScratch(addressTempRegister);
     }
 
@@ -1825,11 +1831,13 @@ public:
     {
         ASSERT((cond == Zero) || (cond == NonZero));
 
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
+
         load8(address, dest);
-        if (mask.m_value == -1)
+        if (mask8.m_value == -1)
             compare32(0, dest, static_cast<RelationalCondition>(cond));
         else
-            testlImm(mask.m_value, dest);
+            testlImm(mask8.m_value, dest);
         if (cond != NonZero) {
             m_assembler.movt(dest);
             return;
@@ -1947,14 +1955,14 @@ public:
 
     Jump branch8(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
     {
-        ASSERT(!(right.m_value & 0xFFFFFF00));
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         RegisterID lefttmp = claimScratch();
 
         loadEffectiveAddress(left, lefttmp);
 
         load8(lefttmp, lefttmp);
         RegisterID righttmp = claimScratch();
-        m_assembler.loadConstant(right.m_value, righttmp);
+        m_assembler.loadConstant(right8.m_value, righttmp);
 
         Jump result = branch32(cond, lefttmp, righttmp);
         releaseScratch(lefttmp);
index f05c8ce..d9b236b 100644 (file)
@@ -160,8 +160,8 @@ public:
 
     void store8(TrustedImm32 imm, void* address)
     {
-        ASSERT(-128 <= imm.m_value && imm.m_value < 128);
-        m_assembler.movb_i8m(imm.m_value, address);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        m_assembler.movb_i8m(imm8.m_value, address);
     }
     
     void moveDoubleToInts(FPRegisterID src, RegisterID dest1, RegisterID dest2)
@@ -237,17 +237,18 @@ public:
     
     Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right)
     {
-        m_assembler.cmpb_im(right.m_value, left.m_ptr);
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
+        m_assembler.cmpb_im(right8.m_value, left.m_ptr);
         return Jump(m_assembler.jCC(x86Condition(cond)));
     }
 
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
-        ASSERT(mask.m_value >= -128 && mask.m_value <= 255);
-        if (mask.m_value == -1)
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
+        if (mask8.m_value == -1)
             m_assembler.cmpb_im(0, address.m_ptr);
         else
-            m_assembler.testb_im(mask.m_value, address.m_ptr);
+            m_assembler.testb_im(mask8.m_value, address.m_ptr);
         return Jump(m_assembler.jCC(x86Condition(cond)));
     }
 
index 85cfbc4..be2efd7 100644 (file)
@@ -135,12 +135,14 @@ public:
 
     void add8(TrustedImm32 imm, Address address)
     {
-        m_assembler.addb_im(imm.m_value, address.offset, address.base);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        m_assembler.addb_im(imm8.m_value, address.offset, address.base);
     }
 
     void add8(TrustedImm32 imm, BaseIndex address)
     {
-        m_assembler.addb_im(imm.m_value, address.offset, address.base, address.index, address.scale);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        m_assembler.addb_im(imm8.m_value, address.offset, address.base, address.index, address.scale);
     }
 
     void add16(TrustedImm32 imm, Address address)
@@ -908,12 +910,14 @@ public:
 
     void store8(TrustedImm32 imm, Address address)
     {
-        m_assembler.movb_i8m(static_cast<int8_t>(imm.m_value), address.offset, address.base);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        m_assembler.movb_i8m(imm8.m_value, address.offset, address.base);
     }
 
     void store8(TrustedImm32 imm, BaseIndex address)
     {
-        m_assembler.movb_i8m(static_cast<int8_t>(imm.m_value), address.offset, address.base, address.index, address.scale);
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
+        m_assembler.movb_i8m(imm8.m_value, address.offset, address.base, address.index, address.scale);
     }
 
     static ALWAYS_INLINE RegisterID getUnusedRegister(BaseIndex address)
@@ -2121,7 +2125,8 @@ public:
 public:
     Jump branch8(RelationalCondition cond, Address left, TrustedImm32 right)
     {
-        m_assembler.cmpb_im(right.m_value, left.offset, left.base);
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
+        m_assembler.cmpb_im(right8.m_value, left.offset, left.base);
         return Jump(m_assembler.jCC(x86Condition(cond)));
     }
 
@@ -2218,32 +2223,28 @@ public:
     
     Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
     {
-        // Byte in TrustedImm32 is not well defined, so be a little permissive here, but don't accept nonsense values.
-        ASSERT(mask.m_value >= -128 && mask.m_value <= 255);
-        if (mask.m_value == -1)
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
+        if (mask8.m_value == -1)
             m_assembler.cmpb_im(0, address.offset, address.base);
         else
-            m_assembler.testb_im(mask.m_value, address.offset, address.base);
+            m_assembler.testb_im(mask8.m_value, address.offset, address.base);
         return Jump(m_assembler.jCC(x86Condition(cond)));
     }
     
     Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
     {
-        // Byte in TrustedImm32 is not well defined, so be a little permissive here, but don't accept nonsense values.
-        ASSERT(mask.m_value >= -128 && mask.m_value <= 255);
-        if (mask.m_value == -1)
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
+        if (mask8.m_value == -1)
             m_assembler.cmpb_im(0, address.offset, address.base, address.index, address.scale);
         else
-            m_assembler.testb_im(mask.m_value, address.offset, address.base, address.index, address.scale);
+            m_assembler.testb_im(mask8.m_value, address.offset, address.base, address.index, address.scale);
         return Jump(m_assembler.jCC(x86Condition(cond)));
     }
 
     Jump branch8(RelationalCondition cond, BaseIndex left, TrustedImm32 right)
     {
-        // Byte in TrustedImm32 is not well defined, so be a little permissive here, but don't accept nonsense values.
-        ASSERT(right.m_value >= -128 && right.m_value <= 255);
-
-        m_assembler.cmpb_im(right.m_value, left.offset, left.base, left.index, left.scale);
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
+        m_assembler.cmpb_im(right8.m_value, left.offset, left.base, left.index, left.scale);
         return Jump(m_assembler.jCC(x86Condition(cond)));
     }
 
@@ -2459,7 +2460,8 @@ public:
 
     void compare8(RelationalCondition cond, Address left, TrustedImm32 right, RegisterID dest)
     {
-        m_assembler.cmpb_im(right.m_value, left.offset, left.base);
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
+        m_assembler.cmpb_im(right8.m_value, left.offset, left.base);
         set32(x86Condition(cond), dest);
     }
     
@@ -2489,10 +2491,11 @@ public:
 
     void test8(ResultCondition cond, Address address, TrustedImm32 mask, RegisterID dest)
     {
-        if (mask.m_value == -1)
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
+        if (mask8.m_value == -1)
             m_assembler.cmpb_im(0, address.offset, address.base);
         else
-            m_assembler.testb_im(mask.m_value, address.offset, address.base);
+            m_assembler.testb_im(mask8.m_value, address.offset, address.base);
         set32(x86Condition(cond), dest);
     }
 
index b9f5264..d9858f3 100644 (file)
@@ -137,8 +137,9 @@ public:
     
     void store8(TrustedImm32 imm, void* address)
     {
+        TrustedImm32 imm8(static_cast<int8_t>(imm.m_value));
         move(TrustedImmPtr(address), scratchRegister());
-        store8(imm, Address(scratchRegister()));
+        store8(imm8, Address(scratchRegister()));
     }
 
     void store8(RegisterID reg, void* address)
@@ -1210,22 +1211,25 @@ public:
     using MacroAssemblerX86Common::branch8;
     Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right)
     {
+        TrustedImm32 right8(static_cast<int8_t>(right.m_value));
         MacroAssemblerX86Common::move(TrustedImmPtr(left.m_ptr), scratchRegister());
-        return MacroAssemblerX86Common::branch8(cond, Address(scratchRegister()), right);
+        return MacroAssemblerX86Common::branch8(cond, Address(scratchRegister()), right8);
     }
     
     using MacroAssemblerX86Common::branchTest8;
     Jump branchTest8(ResultCondition cond, ExtendedAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         TrustedImmPtr addr(reinterpret_cast<void*>(address.offset));
         MacroAssemblerX86Common::move(addr, scratchRegister());
-        return MacroAssemblerX86Common::branchTest8(cond, BaseIndex(scratchRegister(), address.base, TimesOne), mask);
+        return MacroAssemblerX86Common::branchTest8(cond, BaseIndex(scratchRegister(), address.base, TimesOne), mask8);
     }
     
     Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
     {
+        TrustedImm32 mask8(static_cast<int8_t>(mask.m_value));
         MacroAssemblerX86Common::move(TrustedImmPtr(address.m_ptr), scratchRegister());
-        return MacroAssemblerX86Common::branchTest8(cond, Address(scratchRegister()), mask);
+        return MacroAssemblerX86Common::branchTest8(cond, Address(scratchRegister()), mask8);
     }
 
     void convertInt64ToDouble(RegisterID src, FPRegisterID dest)