Add absDouble to the MacroAssembler interface, and abstract the 'x & -x' trick away as it is an x86-specific optimization. [bug 655260] [r=bhackett]
authorJacob Bramley <Jacob.Bramley@arm.com>
Wed, 11 May 2011 15:16:22 +0100
changeset 75031 5e9fa1b150aab88ef9e81502c133d0853bd17a66
parent 75030 07270a0cbc869c7de9a04e6ccbe10f5eb04b9630
child 75032 43c304c90149ec85a0916b025afd78f11e0b52aa
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersbhackett
bugs655260
milestone6.0a1
Add absDouble to the MacroAssembler interface, and abstract the 'x & -x' trick away as it is an x86-specific optimization. [bug 655260] [r=bhackett]
js/src/assembler/assembler/ARMAssembler.h
js/src/assembler/assembler/MacroAssemblerARM.h
js/src/assembler/assembler/MacroAssemblerX86Common.h
js/src/methodjit/FastBuiltins.cpp
--- a/js/src/assembler/assembler/ARMAssembler.h
+++ b/js/src/assembler/assembler/ARMAssembler.h
@@ -185,16 +185,17 @@ namespace JSC {
             MOV = (0xd << 21),
             BIC = (0xe << 21),
             MVN = (0xf << 21),
             MUL = 0x00000090,
             MULL = 0x00c00090,
             FCPYD = 0x0eb00b40,
             FADDD = 0x0e300b00,
             FNEGD = 0x0eb10b40,
+            FABSD = 0x0eb00bc0,
             FDIVD = 0x0e800b00,
             FSUBD = 0x0e300b40,
             FMULD = 0x0e200b00,
             FCMPD = 0x0eb40b40,
             FSQRTD = 0x0eb10bc0,
             DTR = 0x05000000,
             LDRH = 0x00100090,
             STRH = 0x00000090,
@@ -543,16 +544,23 @@ namespace JSC {
 
         void fnegd_r(int dd, int dm, Condition cc = AL)
         {
             js::JaegerSpew(js::JSpew_Insns,
                     IPFX   "%-15s %s, %s, %s, %s\n", MAYBE_PAD, "fnegd", nameFpRegD(dd), nameFpRegD(dm));
             m_buffer.putInt(static_cast<ARMWord>(cc) | FNEGD | DD(dd) | DM(dm));
         }
 
+        void fabsd_r(int dd, int dm, Condition cc = AL)
+        {
+            js::JaegerSpew(js::JSpew_Insns,
+                    IPFX   "%-15s %s, %s, %s, %s\n", MAYBE_PAD, "fabsd", nameFpRegD(dd), nameFpRegD(dm));
+            m_buffer.putInt(static_cast<ARMWord>(cc) | FABSD | DD(dd) | DM(dm));
+        }
+
         void fdivd_r(int dd, int dn, int dm, Condition cc = AL)
         {
             js::JaegerSpew(js::JSpew_Insns,
                     IPFX   "%-15s %s, %s, %s\n", MAYBE_PAD, "vdiv.f64", nameFpRegD(dd), nameFpRegD(dn), nameFpRegD(dm));
             // TODO: emitInst doesn't work for VFP instructions, though it
             // seems to work for current usage.
             emitInst(static_cast<ARMWord>(cc) | FDIVD, dd, dn, dm);
         }
--- a/js/src/assembler/assembler/MacroAssemblerARM.h
+++ b/js/src/assembler/assembler/MacroAssemblerARM.h
@@ -1032,16 +1032,21 @@ public:
         mulDouble(ARMRegisters::SD0, dest);
     }
 
     void negDouble(FPRegisterID src, FPRegisterID dest)
     {
         m_assembler.fnegd_r(dest, src);
     }
 
+    void absDouble(FPRegisterID src, FPRegisterID dest)
+    {
+        m_assembler.fabsd_r(dest, src);
+    }
+
     void sqrtDouble(FPRegisterID src, FPRegisterID dest)
     {
         m_assembler.fsqrtd_r(dest, src);
     }
 
     void convertInt32ToDouble(RegisterID src, FPRegisterID dest)
     {
         m_assembler.fmsr_r(dest, src);
--- a/js/src/assembler/assembler/MacroAssemblerX86Common.h
+++ b/js/src/assembler/assembler/MacroAssemblerX86Common.h
@@ -634,16 +634,25 @@ public:
     }
 
     void andDouble(FPRegisterID src, FPRegisterID dest)
     {
         ASSERT(isSSE2Present());
         m_assembler.andpd_rr(src, dest);
     }
 
+    void absDouble(FPRegisterID src, FPRegisterID dest)
+    {
+        ASSERT(isSSE2Present());
+        /* Compile abs(x) as x & -x. */
+        zeroDouble(dest);
+        subDouble(src, dest);
+        andDouble(src, dest);
+    }
+
     void convertInt32ToDouble(RegisterID src, FPRegisterID dest)
     {
         ASSERT(isSSE2Present());
         m_assembler.cvtsi2sd_rr(src, dest);
     }
 
     void convertInt32ToDouble(Address src, FPRegisterID dest)
     {
--- a/js/src/methodjit/FastBuiltins.cpp
+++ b/js/src/methodjit/FastBuiltins.cpp
@@ -89,20 +89,17 @@ mjit::Compiler::compileMathAbsDouble(Fra
     FPRegisterID fpResultReg = frame.allocFPReg();
 
     FPRegisterID fpReg;
     bool allocate;
 
     MaybeJump notNumber = loadDouble(arg, &fpReg, &allocate);
     JS_ASSERT(!notNumber.isSet());
 
-    /* Compile abs(x) as x & -x. */
-    masm.zeroDouble(fpResultReg);
-    masm.subDouble(fpReg, fpResultReg);
-    masm.andDouble(fpReg, fpResultReg);
+    masm.absDouble(fpReg, fpResultReg);
 
     if (allocate)
         frame.freeReg(fpReg);
 
     frame.popn(3);
     frame.pushDouble(fpResultReg);
 
     return Compile_Okay;