Special thunks for math functions should work on ARMv7
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Apr 2013 01:26:35 +0000 (01:26 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Apr 2013 01:26:35 +0000 (01:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=115144

Reviewed by Gavin Barraclough and Oliver Hunt.

The only hard bit here was ensuring that we implemented the very special
"cheap C call" convention on ARMv7.

* assembler/AbstractMacroAssembler.h:
(JSC::isARMv7s):
(JSC):
(JSC::isX86):
* dfg/DFGCommon.h:
* jit/SpecializedThunkJIT.h:
(SpecializedThunkJIT):
(JSC::SpecializedThunkJIT::callDoubleToDoublePreservingReturn):
* jit/ThunkGenerators.cpp:
(JSC::floorThunkGenerator):
(JSC::ceilThunkGenerator):
(JSC::roundThunkGenerator):
(JSC::expThunkGenerator):
(JSC::logThunkGenerator):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
Source/JavaScriptCore/dfg/DFGCommon.h
Source/JavaScriptCore/jit/SpecializedThunkJIT.h
Source/JavaScriptCore/jit/ThunkGenerators.cpp

index b55ddc0..e2a5f72 100644 (file)
@@ -1,3 +1,28 @@
+2013-04-24  Filip Pizlo  <fpizlo@apple.com>
+
+        Special thunks for math functions should work on ARMv7
+        https://bugs.webkit.org/show_bug.cgi?id=115144
+
+        Reviewed by Gavin Barraclough and Oliver Hunt.
+        
+        The only hard bit here was ensuring that we implemented the very special
+        "cheap C call" convention on ARMv7.
+
+        * assembler/AbstractMacroAssembler.h:
+        (JSC::isARMv7s):
+        (JSC):
+        (JSC::isX86):
+        * dfg/DFGCommon.h:
+        * jit/SpecializedThunkJIT.h:
+        (SpecializedThunkJIT):
+        (JSC::SpecializedThunkJIT::callDoubleToDoublePreservingReturn):
+        * jit/ThunkGenerators.cpp:
+        (JSC::floorThunkGenerator):
+        (JSC::ceilThunkGenerator):
+        (JSC::roundThunkGenerator):
+        (JSC::expThunkGenerator):
+        (JSC::logThunkGenerator):
+
 2013-04-24  Julien Brianceau  <jbrianceau@nds.com>
 
         Misc bugfix and cleaning in sh4 base JIT.
index 95eaf7d..68fd804 100644 (file)
 
 namespace JSC {
 
+inline bool isARMv7s()
+{
+#if CPU(APPLE_ARMV7S)
+    return true;
+#else
+    return false;
+#endif
+}
+
+inline bool isX86()
+{
+#if CPU(X86_64) || CPU(X86)
+    return true;
+#else
+    return false;
+#endif
+}
+
 class JumpReplacementWatchpoint;
 class LinkBuffer;
 class RepatchBuffer;
index b883aee..7aef749 100644 (file)
@@ -100,24 +100,6 @@ enum RefNodeMode {
     DontRefNode
 };
 
-inline bool isARMv7s()
-{
-#if CPU(APPLE_ARMV7S)
-    return true;
-#else
-    return false;
-#endif
-}
-
-inline bool isX86()
-{
-#if CPU(X86_64) || CPU(X86)
-    return true;
-#else
-    return false;
-#endif
-}
-
 inline bool verboseCompilationEnabled()
 {
 #if DFG_ENABLE(DEBUG_VERBOSE)
index 76bef14..9a0e0a3 100644 (file)
@@ -145,6 +145,15 @@ namespace JSC {
         {
             m_calls.append(std::make_pair(call(), function));
         }
+        
+        void callDoubleToDoublePreservingReturn(FunctionPtr function)
+        {
+            if (!isX86())
+                preserveReturnAddressAfterCall(regT3);
+            callDoubleToDouble(function);
+            if (!isX86())
+                restoreReturnAddressBeforeReturn(regT3);
+        }
 
     private:
 
index 6a99ac1..8490fd7 100644 (file)
@@ -507,7 +507,7 @@ double jsRound(double d)
 }
 
 }
-    
+
 #if CPU(X86_64) && COMPILER(GCC) && (PLATFORM(MAC) || OS(LINUX))
 
 #define defineUnaryDoubleOpWrapper(function) \
@@ -544,6 +544,30 @@ double jsRound(double d)
     } \
     static MathThunk UnaryDoubleOpWrapper(function) = &function##Thunk;
 
+#elif CPU(ARM_THUMB2) && COMPILER(GCC) && PLATFORM(IOS)
+
+#define defineUnaryDoubleOpWrapper(function) \
+    asm( \
+        ".text\n" \
+        ".align 2\n" \
+        ".globl " SYMBOL_STRING(function##Thunk) "\n" \
+        HIDE_SYMBOL(function##Thunk) "\n" \
+        ".thumb\n" \
+        ".thumb_func " THUMB_FUNC_PARAM(function##Thunk) "\n" \
+        SYMBOL_STRING(function##Thunk) ":" "\n" \
+        "sub sp, sp, #16\n" \
+        "str lr, [sp, #0]\n" \
+        "vmov r0, r1, d0\n" \
+        "blx " GLOBAL_REFERENCE(function) "\n" \
+        "vmov d0, r0, r1\n" \
+        "ldr lr, [sp, #0]\n" \
+        "add sp, sp, #16\n" \
+        "bx lr\n" \
+    ); \
+    extern "C" { \
+        MathThunkCallingConvention function##Thunk(MathThunkCallingConvention); \
+    } \
+    static MathThunk UnaryDoubleOpWrapper(function) = &function##Thunk;
 #else
 
 #define defineUnaryDoubleOpWrapper(function) \
@@ -583,7 +607,7 @@ MacroAssemblerCodeRef floorThunkGenerator(VM* vm)
         intResult = jit.jump();
         slowPath.link(&jit);
     }
-    jit.callDoubleToDouble(UnaryDoubleOpWrapper(floor));
+    jit.callDoubleToDoublePreservingReturn(UnaryDoubleOpWrapper(floor));
     jit.branchConvertDoubleToInt32(SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0, doubleResult, SpecializedThunkJIT::fpRegT1);
     if (jit.supportsFloatingPointTruncate())
         intResult.link(&jit);
@@ -603,7 +627,7 @@ MacroAssemblerCodeRef ceilThunkGenerator(VM* vm)
     jit.returnInt32(SpecializedThunkJIT::regT0);
     nonIntJump.link(&jit);
     jit.loadDoubleArgument(0, SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0);
-    jit.callDoubleToDouble(UnaryDoubleOpWrapper(ceil));
+    jit.callDoubleToDoublePreservingReturn(UnaryDoubleOpWrapper(ceil));
     SpecializedThunkJIT::JumpList doubleResult;
     jit.branchConvertDoubleToInt32(SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0, doubleResult, SpecializedThunkJIT::fpRegT1);
     jit.returnInt32(SpecializedThunkJIT::regT0);
@@ -636,7 +660,7 @@ MacroAssemblerCodeRef roundThunkGenerator(VM* vm)
         intResult = jit.jump();
         slowPath.link(&jit);
     }
-    jit.callDoubleToDouble(UnaryDoubleOpWrapper(jsRound));
+    jit.callDoubleToDoublePreservingReturn(UnaryDoubleOpWrapper(jsRound));
     jit.branchConvertDoubleToInt32(SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0, doubleResult, SpecializedThunkJIT::fpRegT1);
     if (jit.supportsFloatingPointTruncate())
         intResult.link(&jit);
@@ -654,7 +678,7 @@ MacroAssemblerCodeRef expThunkGenerator(VM* vm)
     if (!jit.supportsFloatingPoint())
         return MacroAssemblerCodeRef::createSelfManagedCodeRef(vm->jitStubs->ctiNativeCall(vm));
     jit.loadDoubleArgument(0, SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0);
-    jit.callDoubleToDouble(UnaryDoubleOpWrapper(exp));
+    jit.callDoubleToDoublePreservingReturn(UnaryDoubleOpWrapper(exp));
     jit.returnDouble(SpecializedThunkJIT::fpRegT0);
     return jit.finalize(*vm, vm->jitStubs->ctiNativeCall(vm), "exp");
 }
@@ -667,7 +691,7 @@ MacroAssemblerCodeRef logThunkGenerator(VM* vm)
     if (!jit.supportsFloatingPoint())
         return MacroAssemblerCodeRef::createSelfManagedCodeRef(vm->jitStubs->ctiNativeCall(vm));
     jit.loadDoubleArgument(0, SpecializedThunkJIT::fpRegT0, SpecializedThunkJIT::regT0);
-    jit.callDoubleToDouble(UnaryDoubleOpWrapper(log));
+    jit.callDoubleToDoublePreservingReturn(UnaryDoubleOpWrapper(log));
     jit.returnDouble(SpecializedThunkJIT::fpRegT0);
     return jit.finalize(*vm, vm->jitStubs->ctiNativeCall(vm), "log");
 }