Bug 1046452 - Fix big endian JS_ION issues. r=bhackett
authorSteve Singer <steve@ssinger.info>
Mon, 18 Aug 2014 14:11:54 -0700
changeset 200224 a5de6212a18cb19d7a26ea363cd8bc9cd78bb88b
parent 200223 4741ef815af991357d609870965c8111ee1b7073
child 200225 064789f0d3878c63410aba2776d3f57716ac028c
push id8272
push useremorley@mozilla.com
push dateTue, 19 Aug 2014 14:17:45 +0000
treeherderfx-team@a955e211bfde [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs1046452
milestone34.0a1
Bug 1046452 - Fix big endian JS_ION issues. r=bhackett
js/src/asmjs/AsmJSSignalHandlers.cpp
js/src/jit/IonMacroAssembler.cpp
js/src/jit/IonMacroAssembler.h
js/src/jit/none/MacroAssembler-none.h
--- a/js/src/asmjs/AsmJSSignalHandlers.cpp
+++ b/js/src/asmjs/AsmJSSignalHandlers.cpp
@@ -365,17 +365,21 @@ HandleSimulatorInterrupt(JSRuntime *rt, 
 #endif
     return false;
 }
 
 #if !defined(XP_MACOSX)
 static uint8_t **
 ContextToPC(CONTEXT *context)
 {
+#ifdef JS_CODEGEN_NONE
+    MOZ_CRASH();
+#else
     return reinterpret_cast<uint8_t**>(&PC_sig(context));
+#endif
 }
 
 # if defined(JS_CODEGEN_X64)
 static void
 SetRegisterToCoercedUndefined(CONTEXT *context, bool isFloat32, AnyRegister reg)
 {
     if (reg.isFloat()) {
         switch (reg.fpu().code()) {
--- a/js/src/jit/IonMacroAssembler.cpp
+++ b/js/src/jit/IonMacroAssembler.cpp
@@ -1940,42 +1940,44 @@ MacroAssembler::finish()
 
 void
 MacroAssembler::branchIfNotInterpretedConstructor(Register fun, Register scratch, Label *label)
 {
     // 16-bit loads are slow and unaligned 32-bit loads may be too so
     // perform an aligned 32-bit load and adjust the bitmask accordingly.
     JS_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0);
     JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
-    JS_STATIC_ASSERT(IS_LITTLE_ENDIAN);
 
     // Emit code for the following test:
     //
     // bool isInterpretedConstructor() const {
     //     return isInterpreted() && !isFunctionPrototype() && !isArrow() &&
     //         (!isSelfHostedBuiltin() || isSelfHostedConstructor());
     // }
 
     // First, ensure it's a scripted function.
     load32(Address(fun, JSFunction::offsetOfNargs()), scratch);
-    branchTest32(Assembler::Zero, scratch, Imm32(JSFunction::INTERPRETED << 16), label);
+    int32_t bits = IMM32_16ADJ(JSFunction::INTERPRETED);
+    branchTest32(Assembler::Zero, scratch, Imm32(bits), label);
 
     // Common case: if IS_FUN_PROTO, ARROW and SELF_HOSTED are not set,
     // the function is an interpreted constructor and we're done.
     Label done;
-    uint32_t bits = (JSFunction::IS_FUN_PROTO | JSFunction::ARROW | JSFunction::SELF_HOSTED) << 16;
+    bits = IMM32_16ADJ( (JSFunction::IS_FUN_PROTO | JSFunction::ARROW | JSFunction::SELF_HOSTED) );
     branchTest32(Assembler::Zero, scratch, Imm32(bits), &done);
     {
         // The callee is either Function.prototype, an arrow function or
         // self-hosted. None of these are constructible, except self-hosted
         // constructors, so branch to |label| if SELF_HOSTED_CTOR is not set.
-        branchTest32(Assembler::Zero, scratch, Imm32(JSFunction::SELF_HOSTED_CTOR << 16), label);
+        bits = IMM32_16ADJ(JSFunction::SELF_HOSTED_CTOR);
+        branchTest32(Assembler::Zero, scratch, Imm32(bits), label);
 
 #ifdef DEBUG
-        branchTest32(Assembler::Zero, scratch, Imm32(JSFunction::IS_FUN_PROTO << 16), &done);
+        bits = IMM32_16ADJ(JSFunction::IS_FUN_PROTO);
+        branchTest32(Assembler::Zero, scratch, Imm32(bits), &done);
         assumeUnreachable("Function.prototype should not have the SELF_HOSTED_CTOR flag");
 #endif
     }
     bind(&done);
 }
 
 void
 MacroAssembler::branchEqualTypeIfNeeded(MIRType type, MDefinition *maybeDef, Register tag,
--- a/js/src/jit/IonMacroAssembler.h
+++ b/js/src/jit/IonMacroAssembler.h
@@ -23,16 +23,22 @@
 # error "Unknown architecture!"
 #endif
 #include "jit/IonInstrumentation.h"
 #include "jit/JitCompartment.h"
 #include "jit/VMFunctions.h"
 #include "vm/ProxyObject.h"
 #include "vm/Shape.h"
 
+#ifdef IS_LITTLE_ENDIAN
+#define IMM32_16ADJ(X) X << 16
+#else
+#define IMM32_16ADJ(X) X
+#endif
+
 namespace js {
 namespace jit {
 
 // The public entrypoint for emitting assembly. Note that a MacroAssembler can
 // use cx->lifoAlloc, so take care not to interleave masm use with other
 // lifoAlloc use if one will be destroyed before the other.
 class MacroAssembler : public MacroAssemblerSpecific
 {
@@ -518,29 +524,27 @@ class MacroAssembler : public MacroAssem
         PopRegsInMaskIgnore(set, ignore, FloatRegisterSet());
     }
 
     void branchIfFunctionHasNoScript(Register fun, Label *label) {
         // 16-bit loads are slow and unaligned 32-bit loads may be too so
         // perform an aligned 32-bit load and adjust the bitmask accordingly.
         JS_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0);
         JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
-        JS_STATIC_ASSERT(IS_LITTLE_ENDIAN);
         Address address(fun, JSFunction::offsetOfNargs());
-        uint32_t bit = JSFunction::INTERPRETED << 16;
+        int32_t bit = IMM32_16ADJ(JSFunction::INTERPRETED);
         branchTest32(Assembler::Zero, address, Imm32(bit), label);
     }
     void branchIfInterpreted(Register fun, Label *label) {
         // 16-bit loads are slow and unaligned 32-bit loads may be too so
         // perform an aligned 32-bit load and adjust the bitmask accordingly.
         JS_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0);
         JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
-        JS_STATIC_ASSERT(IS_LITTLE_ENDIAN);
         Address address(fun, JSFunction::offsetOfNargs());
-        uint32_t bit = JSFunction::INTERPRETED << 16;
+        int32_t bit = IMM32_16ADJ(JSFunction::INTERPRETED);
         branchTest32(Assembler::NonZero, address, Imm32(bit), label);
     }
 
     void branchIfNotInterpretedConstructor(Register fun, Register scratch, Label *label);
 
     using MacroAssemblerSpecific::Push;
     using MacroAssemblerSpecific::Pop;
 
--- a/js/src/jit/none/MacroAssembler-none.h
+++ b/js/src/jit/none/MacroAssembler-none.h
@@ -9,16 +9,18 @@
 
 #include "jit/MoveResolver.h"
 
 #include "jit/shared/Assembler-shared.h"
 
 namespace js {
 namespace jit {
 
+class MDefinition;
+
 static MOZ_CONSTEXPR_VAR Register StackPointer = { 0 };
 static MOZ_CONSTEXPR_VAR Register FramePointer = { 0 };
 static MOZ_CONSTEXPR_VAR Register ReturnReg = { 0 };
 static MOZ_CONSTEXPR_VAR FloatRegister ReturnFloat32Reg = { 0 };
 static MOZ_CONSTEXPR_VAR FloatRegister ReturnDoubleReg = { 0 };
 static MOZ_CONSTEXPR_VAR FloatRegister ScratchFloat32Reg = { 0 };
 static MOZ_CONSTEXPR_VAR FloatRegister ScratchDoubleReg = { 0 };
 static MOZ_CONSTEXPR_VAR FloatRegister InvalidFloatReg = { 0 };