Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "jit/BaselineHelpers.h" |
michael@0 | 8 | #include "jit/BaselineIC.h" |
michael@0 | 9 | |
michael@0 | 10 | using namespace js; |
michael@0 | 11 | using namespace js::jit; |
michael@0 | 12 | |
michael@0 | 13 | namespace js { |
michael@0 | 14 | namespace jit { |
michael@0 | 15 | |
michael@0 | 16 | // ICCompare_Int32 |
michael@0 | 17 | |
michael@0 | 18 | bool |
michael@0 | 19 | ICCompare_Int32::Compiler::generateStubCode(MacroAssembler &masm) |
michael@0 | 20 | { |
michael@0 | 21 | // Guard that R0 is an integer and R1 is an integer. |
michael@0 | 22 | Label failure; |
michael@0 | 23 | masm.branchTestInt32(Assembler::NotEqual, R0, &failure); |
michael@0 | 24 | masm.branchTestInt32(Assembler::NotEqual, R1, &failure); |
michael@0 | 25 | |
michael@0 | 26 | // Directly compare the int32 payload of R0 and R1. |
michael@0 | 27 | Assembler::Condition cond = JSOpToCondition(op, /* signed = */true); |
michael@0 | 28 | masm.mov(ImmWord(0), ScratchReg); |
michael@0 | 29 | masm.cmpl(R0.valueReg(), R1.valueReg()); |
michael@0 | 30 | masm.setCC(cond, ScratchReg); |
michael@0 | 31 | |
michael@0 | 32 | // Box the result and return |
michael@0 | 33 | masm.boxValue(JSVAL_TYPE_BOOLEAN, ScratchReg, R0.valueReg()); |
michael@0 | 34 | EmitReturnFromIC(masm); |
michael@0 | 35 | |
michael@0 | 36 | // Failure case - jump to next stub |
michael@0 | 37 | masm.bind(&failure); |
michael@0 | 38 | EmitStubGuardFailure(masm); |
michael@0 | 39 | |
michael@0 | 40 | return true; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | // ICBinaryArith_Int32 |
michael@0 | 44 | |
michael@0 | 45 | bool |
michael@0 | 46 | ICBinaryArith_Int32::Compiler::generateStubCode(MacroAssembler &masm) |
michael@0 | 47 | { |
michael@0 | 48 | // Guard that R0 is an integer and R1 is an integer. |
michael@0 | 49 | Label failure; |
michael@0 | 50 | masm.branchTestInt32(Assembler::NotEqual, R0, &failure); |
michael@0 | 51 | masm.branchTestInt32(Assembler::NotEqual, R1, &failure); |
michael@0 | 52 | |
michael@0 | 53 | Label revertRegister, maybeNegZero; |
michael@0 | 54 | switch(op_) { |
michael@0 | 55 | case JSOP_ADD: |
michael@0 | 56 | masm.unboxInt32(R0, ExtractTemp0); |
michael@0 | 57 | // Just jump to failure on overflow. R0 and R1 are preserved, so we can just jump to |
michael@0 | 58 | // the next stub. |
michael@0 | 59 | masm.addl(R1.valueReg(), ExtractTemp0); |
michael@0 | 60 | masm.j(Assembler::Overflow, &failure); |
michael@0 | 61 | |
michael@0 | 62 | // Box the result |
michael@0 | 63 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 64 | break; |
michael@0 | 65 | case JSOP_SUB: |
michael@0 | 66 | masm.unboxInt32(R0, ExtractTemp0); |
michael@0 | 67 | masm.subl(R1.valueReg(), ExtractTemp0); |
michael@0 | 68 | masm.j(Assembler::Overflow, &failure); |
michael@0 | 69 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 70 | break; |
michael@0 | 71 | case JSOP_MUL: |
michael@0 | 72 | masm.unboxInt32(R0, ExtractTemp0); |
michael@0 | 73 | masm.imull(R1.valueReg(), ExtractTemp0); |
michael@0 | 74 | masm.j(Assembler::Overflow, &failure); |
michael@0 | 75 | |
michael@0 | 76 | masm.branchTest32(Assembler::Zero, ExtractTemp0, ExtractTemp0, &maybeNegZero); |
michael@0 | 77 | |
michael@0 | 78 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 79 | break; |
michael@0 | 80 | case JSOP_DIV: |
michael@0 | 81 | { |
michael@0 | 82 | JS_ASSERT(R2.scratchReg() == rax); |
michael@0 | 83 | JS_ASSERT(R0.valueReg() != rdx); |
michael@0 | 84 | JS_ASSERT(R1.valueReg() != rdx); |
michael@0 | 85 | masm.unboxInt32(R0, eax); |
michael@0 | 86 | masm.unboxInt32(R1, ExtractTemp0); |
michael@0 | 87 | |
michael@0 | 88 | // Prevent division by 0. |
michael@0 | 89 | masm.branchTest32(Assembler::Zero, ExtractTemp0, ExtractTemp0, &failure); |
michael@0 | 90 | |
michael@0 | 91 | // Prevent negative 0 and -2147483648 / -1. |
michael@0 | 92 | masm.branch32(Assembler::Equal, eax, Imm32(INT32_MIN), &failure); |
michael@0 | 93 | |
michael@0 | 94 | Label notZero; |
michael@0 | 95 | masm.branch32(Assembler::NotEqual, eax, Imm32(0), ¬Zero); |
michael@0 | 96 | masm.branchTest32(Assembler::Signed, ExtractTemp0, ExtractTemp0, &failure); |
michael@0 | 97 | masm.bind(¬Zero); |
michael@0 | 98 | |
michael@0 | 99 | // Sign extend eax into edx to make (edx:eax), since idiv is 64-bit. |
michael@0 | 100 | masm.cdq(); |
michael@0 | 101 | masm.idiv(ExtractTemp0); |
michael@0 | 102 | |
michael@0 | 103 | // A remainder implies a double result. |
michael@0 | 104 | masm.branchTest32(Assembler::NonZero, edx, edx, &failure); |
michael@0 | 105 | |
michael@0 | 106 | masm.boxValue(JSVAL_TYPE_INT32, eax, R0.valueReg()); |
michael@0 | 107 | break; |
michael@0 | 108 | } |
michael@0 | 109 | case JSOP_MOD: |
michael@0 | 110 | { |
michael@0 | 111 | JS_ASSERT(R2.scratchReg() == rax); |
michael@0 | 112 | JS_ASSERT(R0.valueReg() != rdx); |
michael@0 | 113 | JS_ASSERT(R1.valueReg() != rdx); |
michael@0 | 114 | masm.unboxInt32(R0, eax); |
michael@0 | 115 | masm.unboxInt32(R1, ExtractTemp0); |
michael@0 | 116 | |
michael@0 | 117 | // x % 0 always results in NaN. |
michael@0 | 118 | masm.branchTest32(Assembler::Zero, ExtractTemp0, ExtractTemp0, &failure); |
michael@0 | 119 | |
michael@0 | 120 | // Prevent negative 0 and -2147483648 % -1. |
michael@0 | 121 | masm.branchTest32(Assembler::Zero, eax, Imm32(0x7fffffff), &failure); |
michael@0 | 122 | |
michael@0 | 123 | // Sign extend eax into edx to make (edx:eax), since idiv is 64-bit. |
michael@0 | 124 | masm.cdq(); |
michael@0 | 125 | masm.idiv(ExtractTemp0); |
michael@0 | 126 | |
michael@0 | 127 | // Fail when we would need a negative remainder. |
michael@0 | 128 | Label done; |
michael@0 | 129 | masm.branchTest32(Assembler::NonZero, edx, edx, &done); |
michael@0 | 130 | masm.orl(ExtractTemp0, eax); |
michael@0 | 131 | masm.branchTest32(Assembler::Signed, eax, eax, &failure); |
michael@0 | 132 | |
michael@0 | 133 | masm.bind(&done); |
michael@0 | 134 | masm.boxValue(JSVAL_TYPE_INT32, edx, R0.valueReg()); |
michael@0 | 135 | break; |
michael@0 | 136 | } |
michael@0 | 137 | case JSOP_BITOR: |
michael@0 | 138 | // We can overide R0, because the instruction is unfailable. |
michael@0 | 139 | // Because the tag bits are the same, we don't need to retag. |
michael@0 | 140 | masm.orq(R1.valueReg(), R0.valueReg()); |
michael@0 | 141 | break; |
michael@0 | 142 | case JSOP_BITXOR: |
michael@0 | 143 | masm.xorl(R1.valueReg(), R0.valueReg()); |
michael@0 | 144 | masm.tagValue(JSVAL_TYPE_INT32, R0.valueReg(), R0); |
michael@0 | 145 | break; |
michael@0 | 146 | case JSOP_BITAND: |
michael@0 | 147 | masm.andq(R1.valueReg(), R0.valueReg()); |
michael@0 | 148 | break; |
michael@0 | 149 | case JSOP_LSH: |
michael@0 | 150 | masm.unboxInt32(R0, ExtractTemp0); |
michael@0 | 151 | masm.unboxInt32(R1, ecx); // Unboxing R1 to ecx, clobbers R0. |
michael@0 | 152 | masm.shll_cl(ExtractTemp0); |
michael@0 | 153 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 154 | break; |
michael@0 | 155 | case JSOP_RSH: |
michael@0 | 156 | masm.unboxInt32(R0, ExtractTemp0); |
michael@0 | 157 | masm.unboxInt32(R1, ecx); |
michael@0 | 158 | masm.sarl_cl(ExtractTemp0); |
michael@0 | 159 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 160 | break; |
michael@0 | 161 | case JSOP_URSH: |
michael@0 | 162 | if (!allowDouble_) |
michael@0 | 163 | masm.movq(R0.valueReg(), ScratchReg); |
michael@0 | 164 | |
michael@0 | 165 | masm.unboxInt32(R0, ExtractTemp0); |
michael@0 | 166 | masm.unboxInt32(R1, ecx); // This clobbers R0 |
michael@0 | 167 | |
michael@0 | 168 | masm.shrl_cl(ExtractTemp0); |
michael@0 | 169 | masm.testl(ExtractTemp0, ExtractTemp0); |
michael@0 | 170 | if (allowDouble_) { |
michael@0 | 171 | Label toUint; |
michael@0 | 172 | masm.j(Assembler::Signed, &toUint); |
michael@0 | 173 | |
michael@0 | 174 | // Box and return. |
michael@0 | 175 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 176 | EmitReturnFromIC(masm); |
michael@0 | 177 | |
michael@0 | 178 | masm.bind(&toUint); |
michael@0 | 179 | masm.convertUInt32ToDouble(ExtractTemp0, ScratchFloatReg); |
michael@0 | 180 | masm.boxDouble(ScratchFloatReg, R0); |
michael@0 | 181 | } else { |
michael@0 | 182 | masm.j(Assembler::Signed, &revertRegister); |
michael@0 | 183 | masm.boxValue(JSVAL_TYPE_INT32, ExtractTemp0, R0.valueReg()); |
michael@0 | 184 | } |
michael@0 | 185 | break; |
michael@0 | 186 | default: |
michael@0 | 187 | MOZ_ASSUME_UNREACHABLE("Unhandled op in BinaryArith_Int32"); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | // Return from stub. |
michael@0 | 191 | EmitReturnFromIC(masm); |
michael@0 | 192 | |
michael@0 | 193 | if (op_ == JSOP_MUL) { |
michael@0 | 194 | masm.bind(&maybeNegZero); |
michael@0 | 195 | |
michael@0 | 196 | // Result is -0 if exactly one of lhs or rhs is negative. |
michael@0 | 197 | masm.movl(R0.valueReg(), ScratchReg); |
michael@0 | 198 | masm.orl(R1.valueReg(), ScratchReg); |
michael@0 | 199 | masm.j(Assembler::Signed, &failure); |
michael@0 | 200 | |
michael@0 | 201 | // Result is +0. |
michael@0 | 202 | masm.moveValue(Int32Value(0), R0); |
michael@0 | 203 | EmitReturnFromIC(masm); |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | // Revert the content of R0 in the fallible >>> case. |
michael@0 | 207 | if (op_ == JSOP_URSH && !allowDouble_) { |
michael@0 | 208 | masm.bind(&revertRegister); |
michael@0 | 209 | // Restore tag and payload. |
michael@0 | 210 | masm.movq(ScratchReg, R0.valueReg()); |
michael@0 | 211 | // Fall through to failure. |
michael@0 | 212 | } |
michael@0 | 213 | // Failure case - jump to next stub |
michael@0 | 214 | masm.bind(&failure); |
michael@0 | 215 | EmitStubGuardFailure(masm); |
michael@0 | 216 | |
michael@0 | 217 | return true; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | bool |
michael@0 | 221 | ICUnaryArith_Int32::Compiler::generateStubCode(MacroAssembler &masm) |
michael@0 | 222 | { |
michael@0 | 223 | Label failure; |
michael@0 | 224 | masm.branchTestInt32(Assembler::NotEqual, R0, &failure); |
michael@0 | 225 | |
michael@0 | 226 | switch (op) { |
michael@0 | 227 | case JSOP_BITNOT: |
michael@0 | 228 | masm.notl(R0.valueReg()); |
michael@0 | 229 | break; |
michael@0 | 230 | case JSOP_NEG: |
michael@0 | 231 | // Guard against 0 and MIN_INT, both result in a double. |
michael@0 | 232 | masm.branchTest32(Assembler::Zero, R0.valueReg(), Imm32(0x7fffffff), &failure); |
michael@0 | 233 | masm.negl(R0.valueReg()); |
michael@0 | 234 | break; |
michael@0 | 235 | default: |
michael@0 | 236 | MOZ_ASSUME_UNREACHABLE("Unexpected op"); |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | masm.tagValue(JSVAL_TYPE_INT32, R0.valueReg(), R0); |
michael@0 | 240 | |
michael@0 | 241 | EmitReturnFromIC(masm); |
michael@0 | 242 | |
michael@0 | 243 | masm.bind(&failure); |
michael@0 | 244 | EmitStubGuardFailure(masm); |
michael@0 | 245 | return true; |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | } // namespace jit |
michael@0 | 249 | } // namespace js |