Title: [196544] trunk/Source/_javascript_Core
Revision
196544
Author
[email protected]
Date
2016-02-12 20:48:40 -0800 (Fri, 12 Feb 2016)

Log Message

[JSC] ZeroExtend and SignExtend use incorrect addressing on ARM64
https://bugs.webkit.org/show_bug.cgi?id=154208

Patch by Benjamin Poulain <[email protected]> on 2016-02-12
Reviewed by Filip Pizlo.

When lowering:
    @1 = Load32(@x)
    @2 = SExt8(@1)

LowerToAir would see there is a form of SignExtend8To32 (an alias for Load8S)
and use that.

There are two problems with that:
1) If we have an Addr, it went through legalizeMemoryOffsets() for a 32bits
   load. If used on an other kind of load, there is no guarantee the addressing
   is still valid.
2) If we have an Index, it is computed for the 32bits MemoryValue.
   The computed index is not valid for the 8bits load.

(2) could be fixed by changing LowerToAir to use the current instruction width
instead of the B3ValueWidth but that's a bit tricky. We should just embrace
that one of our target is a Load-Store architecture.

In this patch, I just disabled the faulty forms on ARM64. We still need those operations
to be fast, this will be addressed in: https://bugs.webkit.org/show_bug.cgi?id=154207

I also strengthened the m_allowScratchRegister assertion. The instructions that do not
invalidate the temporary did not run the assertion, making this harder to debug.

* assembler/MacroAssemblerARM64.h:
(JSC::MacroAssemblerARM64::load8):
(JSC::MacroAssemblerARM64::store64):
(JSC::MacroAssemblerARM64::store32):
(JSC::MacroAssemblerARM64::loadDouble):
(JSC::MacroAssemblerARM64::storeDouble):
(JSC::MacroAssemblerARM64::branch32):
(JSC::MacroAssemblerARM64::branch64):
(JSC::MacroAssemblerARM64::getCachedDataTempRegisterIDAndInvalidate):
(JSC::MacroAssemblerARM64::getCachedMemoryTempRegisterIDAndInvalidate):
(JSC::MacroAssemblerARM64::dataMemoryTempRegister):
(JSC::MacroAssemblerARM64::cachedMemoryTempRegister):
(JSC::MacroAssemblerARM64::load):
(JSC::MacroAssemblerARM64::store):
* b3/air/AirOpcode.opcodes:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (196543 => 196544)


--- trunk/Source/_javascript_Core/ChangeLog	2016-02-13 03:18:12 UTC (rev 196543)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-02-13 04:48:40 UTC (rev 196544)
@@ -1,3 +1,50 @@
+2016-02-12  Benjamin Poulain  <[email protected]>
+
+        [JSC] ZeroExtend and SignExtend use incorrect addressing on ARM64
+        https://bugs.webkit.org/show_bug.cgi?id=154208
+
+        Reviewed by Filip Pizlo.
+
+        When lowering:
+            @1 = Load32(@x)
+            @2 = SExt8(@1)
+
+        LowerToAir would see there is a form of SignExtend8To32 (an alias for Load8S)
+        and use that.
+
+        There are two problems with that:
+        1) If we have an Addr, it went through legalizeMemoryOffsets() for a 32bits
+           load. If used on an other kind of load, there is no guarantee the addressing
+           is still valid.
+        2) If we have an Index, it is computed for the 32bits MemoryValue.
+           The computed index is not valid for the 8bits load.
+
+        (2) could be fixed by changing LowerToAir to use the current instruction width
+        instead of the B3ValueWidth but that's a bit tricky. We should just embrace
+        that one of our target is a Load-Store architecture.
+
+        In this patch, I just disabled the faulty forms on ARM64. We still need those operations
+        to be fast, this will be addressed in: https://bugs.webkit.org/show_bug.cgi?id=154207
+
+        I also strengthened the m_allowScratchRegister assertion. The instructions that do not
+        invalidate the temporary did not run the assertion, making this harder to debug.
+
+        * assembler/MacroAssemblerARM64.h:
+        (JSC::MacroAssemblerARM64::load8):
+        (JSC::MacroAssemblerARM64::store64):
+        (JSC::MacroAssemblerARM64::store32):
+        (JSC::MacroAssemblerARM64::loadDouble):
+        (JSC::MacroAssemblerARM64::storeDouble):
+        (JSC::MacroAssemblerARM64::branch32):
+        (JSC::MacroAssemblerARM64::branch64):
+        (JSC::MacroAssemblerARM64::getCachedDataTempRegisterIDAndInvalidate):
+        (JSC::MacroAssemblerARM64::getCachedMemoryTempRegisterIDAndInvalidate):
+        (JSC::MacroAssemblerARM64::dataMemoryTempRegister):
+        (JSC::MacroAssemblerARM64::cachedMemoryTempRegister):
+        (JSC::MacroAssemblerARM64::load):
+        (JSC::MacroAssemblerARM64::store):
+        * b3/air/AirOpcode.opcodes:
+
 2016-02-12  Michael Saboff  <[email protected]>
 
         offlineasm: Emit Dwarf2 file and location directives to allow for debugging .asm files

Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h (196543 => 196544)


--- trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h	2016-02-13 03:18:12 UTC (rev 196543)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h	2016-02-13 04:48:40 UTC (rev 196544)
@@ -1049,10 +1049,10 @@
     
     void load8(const void* address, RegisterID dest)
     {
-        moveToCachedReg(TrustedImmPtr(address), m_cachedMemoryTempRegister);
+        moveToCachedReg(TrustedImmPtr(address), cachedMemoryTempRegister());
         m_assembler.ldrb(dest, memoryTempRegister, ARM64Registers::zr);
         if (dest == memoryTempRegister)
-            m_cachedMemoryTempRegister.invalidate();
+            cachedMemoryTempRegister().invalidate();
     }
 
     void load8SignedExtendTo32(ImplicitAddress address, RegisterID dest)
@@ -1124,7 +1124,7 @@
             return;
         }
 
-        moveToCachedReg(imm, m_dataMemoryTempRegister);
+        moveToCachedReg(imm, dataMemoryTempRegister());
         store64(dataTempRegister, address);
     }
 
@@ -1135,7 +1135,7 @@
             return;
         }
 
-        moveToCachedReg(imm, m_dataMemoryTempRegister);
+        moveToCachedReg(imm, dataMemoryTempRegister());
         store64(dataTempRegister, address);
     }
     
@@ -1180,7 +1180,7 @@
             return;
         }
 
-        moveToCachedReg(imm, m_dataMemoryTempRegister);
+        moveToCachedReg(imm, dataMemoryTempRegister());
         store32(dataTempRegister, address);
     }
 
@@ -1191,7 +1191,7 @@
             return;
         }
 
-        moveToCachedReg(imm, m_dataMemoryTempRegister);
+        moveToCachedReg(imm, dataMemoryTempRegister());
         store32(dataTempRegister, address);
     }
 
@@ -1202,7 +1202,7 @@
             return;
         }
 
-        moveToCachedReg(imm, m_dataMemoryTempRegister);
+        moveToCachedReg(imm, dataMemoryTempRegister());
         store32(dataTempRegister, address);
     }
 
@@ -1497,7 +1497,7 @@
     
     void loadDouble(TrustedImmPtr address, FPRegisterID dest)
     {
-        moveToCachedReg(address, m_cachedMemoryTempRegister);
+        moveToCachedReg(address, cachedMemoryTempRegister());
         m_assembler.ldr<64>(dest, memoryTempRegister, ARM64Registers::zr);
     }
 
@@ -1642,7 +1642,7 @@
 
     void storeDouble(FPRegisterID src, TrustedImmPtr address)
     {
-        moveToCachedReg(address, m_cachedMemoryTempRegister);
+        moveToCachedReg(address, cachedMemoryTempRegister());
         m_assembler.str<64>(src, memoryTempRegister, ARM64Registers::zr);
     }
 
@@ -1900,7 +1900,7 @@
         else if (isUInt12(-right.m_value))
             m_assembler.cmn<32>(left, UInt12(-right.m_value));
         else {
-            moveToCachedReg(right, m_dataMemoryTempRegister);
+            moveToCachedReg(right, dataMemoryTempRegister());
             m_assembler.cmp<32>(left, dataTempRegister);
         }
         return Jump(makeBranch(cond));
@@ -1966,7 +1966,7 @@
         else if (isUInt12(-immediate))
             m_assembler.cmn<64>(left, UInt12(static_cast<int32_t>(-immediate)));
         else {
-            moveToCachedReg(right, m_dataMemoryTempRegister);
+            moveToCachedReg(right, dataMemoryTempRegister());
             m_assembler.cmp<64>(left, dataTempRegister);
         }
         return Jump(makeBranch(cond));
@@ -2877,13 +2877,23 @@
     ALWAYS_INLINE RegisterID getCachedDataTempRegisterIDAndInvalidate()
     {
         RELEASE_ASSERT(m_allowScratchRegister);
-        return m_dataMemoryTempRegister.registerIDInvalidate();
+        return dataMemoryTempRegister().registerIDInvalidate();
     }
     ALWAYS_INLINE RegisterID getCachedMemoryTempRegisterIDAndInvalidate()
     {
         RELEASE_ASSERT(m_allowScratchRegister);
-        return m_cachedMemoryTempRegister.registerIDInvalidate();
+        return cachedMemoryTempRegister().registerIDInvalidate();
     }
+    ALWAYS_INLINE CachedTempRegister& dataMemoryTempRegister()
+    {
+        RELEASE_ASSERT(m_allowScratchRegister);
+        return m_dataMemoryTempRegister;
+    }
+    ALWAYS_INLINE CachedTempRegister& cachedMemoryTempRegister()
+    {
+        RELEASE_ASSERT(m_allowScratchRegister);
+        return m_cachedMemoryTempRegister;
+    }
 
     ALWAYS_INLINE bool isInIntRange(intptr_t value)
     {
@@ -3015,12 +3025,12 @@
     ALWAYS_INLINE void load(const void* address, RegisterID dest)
     {
         intptr_t currentRegisterContents;
-        if (m_cachedMemoryTempRegister.value(currentRegisterContents)) {
+        if (cachedMemoryTempRegister().value(currentRegisterContents)) {
             intptr_t addressAsInt = reinterpret_cast<intptr_t>(address);
             intptr_t addressDelta = addressAsInt - currentRegisterContents;
 
             if (dest == memoryTempRegister)
-                m_cachedMemoryTempRegister.invalidate();
+                cachedMemoryTempRegister().invalidate();
 
             if (isInIntRange(addressDelta)) {
                 if (ARM64Assembler::canEncodeSImmOffset(addressDelta)) {
@@ -3036,7 +3046,7 @@
 
             if ((addressAsInt & (~maskHalfWord0)) == (currentRegisterContents & (~maskHalfWord0))) {
                 m_assembler.movk<64>(memoryTempRegister, addressAsInt & maskHalfWord0, 0);
-                m_cachedMemoryTempRegister.setValue(reinterpret_cast<intptr_t>(address));
+                cachedMemoryTempRegister().setValue(reinterpret_cast<intptr_t>(address));
                 m_assembler.ldr<datasize>(dest, memoryTempRegister, ARM64Registers::zr);
                 return;
             }
@@ -3044,9 +3054,9 @@
 
         move(TrustedImmPtr(address), memoryTempRegister);
         if (dest == memoryTempRegister)
-            m_cachedMemoryTempRegister.invalidate();
+            cachedMemoryTempRegister().invalidate();
         else
-            m_cachedMemoryTempRegister.setValue(reinterpret_cast<intptr_t>(address));
+            cachedMemoryTempRegister().setValue(reinterpret_cast<intptr_t>(address));
         m_assembler.ldr<datasize>(dest, memoryTempRegister, ARM64Registers::zr);
     }
 
@@ -3055,7 +3065,7 @@
     {
         ASSERT(src != memoryTempRegister);
         intptr_t currentRegisterContents;
-        if (m_cachedMemoryTempRegister.value(currentRegisterContents)) {
+        if (cachedMemoryTempRegister().value(currentRegisterContents)) {
             intptr_t addressAsInt = reinterpret_cast<intptr_t>(address);
             intptr_t addressDelta = addressAsInt - currentRegisterContents;
 
@@ -3073,14 +3083,14 @@
 
             if ((addressAsInt & (~maskHalfWord0)) == (currentRegisterContents & (~maskHalfWord0))) {
                 m_assembler.movk<64>(memoryTempRegister, addressAsInt & maskHalfWord0, 0);
-                m_cachedMemoryTempRegister.setValue(reinterpret_cast<intptr_t>(address));
+                cachedMemoryTempRegister().setValue(reinterpret_cast<intptr_t>(address));
                 m_assembler.str<datasize>(src, memoryTempRegister, ARM64Registers::zr);
                 return;
             }
         }
 
         move(TrustedImmPtr(address), memoryTempRegister);
-        m_cachedMemoryTempRegister.setValue(reinterpret_cast<intptr_t>(address));
+        cachedMemoryTempRegister().setValue(reinterpret_cast<intptr_t>(address));
         m_assembler.str<datasize>(src, memoryTempRegister, ARM64Registers::zr);
     }
 

Modified: trunk/Source/_javascript_Core/b3/air/AirOpcode.opcodes (196543 => 196544)


--- trunk/Source/_javascript_Core/b3/air/AirOpcode.opcodes	2016-02-13 03:18:12 UTC (rev 196543)
+++ trunk/Source/_javascript_Core/b3/air/AirOpcode.opcodes	2016-02-13 04:48:40 UTC (rev 196544)
@@ -498,23 +498,23 @@
 
 ZeroExtend8To32 U:G:8, ZD:G:32
     Tmp, Tmp
-    Addr, Tmp as load8
-    Index, Tmp as load8
+    x86: Addr, Tmp as load8
+    x86: Index, Tmp as load8
 
 SignExtend8To32 U:G:8, ZD:G:32
     Tmp, Tmp
-    Addr, Tmp as load8SignedExtendTo32
-    Index, Tmp as load8SignedExtendTo32
+    x86: Addr, Tmp as load8SignedExtendTo32
+    x86: Index, Tmp as load8SignedExtendTo32
 
 ZeroExtend16To32 U:G:16, ZD:G:32
     Tmp, Tmp
-    Addr, Tmp as load16
-    Index, Tmp as load16
+    x86: Addr, Tmp as load16
+    x86: Index, Tmp as load16
 
 SignExtend16To32 U:G:16, ZD:G:32
     Tmp, Tmp
-    Addr, Tmp as load16SignedExtendTo32
-    Index, Tmp as load16SignedExtendTo32
+    x86: Addr, Tmp as load16SignedExtendTo32
+    x86: Index, Tmp as load16SignedExtendTo32
 
 MoveFloat U:F:32, D:F:32
     Tmp, Tmp as moveDouble
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to