| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2213 | 2213 |
| 2214 Label done; | 2214 Label done; |
| 2215 Register tmp = input_reg.is(eax) ? ecx : eax; | 2215 Register tmp = input_reg.is(eax) ? ecx : eax; |
| 2216 Register tmp2 = tmp.is(ecx) ? edx : input_reg.is(ecx) ? edx : ecx; | 2216 Register tmp2 = tmp.is(ecx) ? edx : input_reg.is(ecx) ? edx : ecx; |
| 2217 | 2217 |
| 2218 // Preserve the value of all registers. | 2218 // Preserve the value of all registers. |
| 2219 __ PushSafepointRegisters(); | 2219 __ PushSafepointRegisters(); |
| 2220 | 2220 |
| 2221 Label negative; | 2221 Label negative; |
| 2222 __ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset)); | 2222 __ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 2223 // Check the sign of the argument. If the argument is positive, | 2223 // Check the sign of the argument. If the argument is positive, just |
| 2224 // just return it. | 2224 // return it. We do not need to patch the stack since |input| and |
| 2225 // |result| are the same register and |input| will be restored |
| 2226 // unchanged by popping safepoint registers. |
| 2225 __ test(tmp, Immediate(HeapNumber::kSignMask)); | 2227 __ test(tmp, Immediate(HeapNumber::kSignMask)); |
| 2226 __ j(not_zero, &negative); | 2228 __ j(not_zero, &negative); |
| 2227 __ mov(tmp, input_reg); | |
| 2228 __ jmp(&done); | 2229 __ jmp(&done); |
| 2229 | 2230 |
| 2230 __ bind(&negative); | 2231 __ bind(&negative); |
| 2231 | 2232 |
| 2232 Label allocated, slow; | 2233 Label allocated, slow; |
| 2233 __ AllocateHeapNumber(tmp, tmp2, no_reg, &slow); | 2234 __ AllocateHeapNumber(tmp, tmp2, no_reg, &slow); |
| 2234 __ jmp(&allocated); | 2235 __ jmp(&allocated); |
| 2235 | 2236 |
| 2236 // Slow case: Call the runtime system to do the number allocation. | 2237 // Slow case: Call the runtime system to do the number allocation. |
| 2237 __ bind(&slow); | 2238 __ bind(&slow); |
| 2238 | 2239 |
| 2239 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 2240 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 2240 RecordSafepointWithRegisters( | 2241 RecordSafepointWithRegisters( |
| 2241 instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); | 2242 instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 2242 // Set the pointer to the new heap number in tmp. | 2243 // Set the pointer to the new heap number in tmp. |
| 2243 if (!tmp.is(eax)) __ mov(tmp, eax); | 2244 if (!tmp.is(eax)) __ mov(tmp, eax); |
| 2244 | 2245 |
| 2245 // Restore input_reg after call to runtime. | 2246 // Restore input_reg after call to runtime. |
| 2246 __ mov(input_reg, Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize)); | 2247 __ mov(input_reg, Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize)); |
| 2247 | 2248 |
| 2248 __ bind(&allocated); | 2249 __ bind(&allocated); |
| 2249 __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kExponentOffset)); | 2250 __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 2250 __ and_(tmp2, ~HeapNumber::kSignMask); | 2251 __ and_(tmp2, ~HeapNumber::kSignMask); |
| 2251 __ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2); | 2252 __ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2); |
| 2252 __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); | 2253 __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset)); |
| 2253 __ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2); | 2254 __ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2); |
| 2255 __ mov(Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize), tmp); |
| 2254 | 2256 |
| 2255 __ bind(&done); | 2257 __ bind(&done); |
| 2256 __ mov(Operand(esp, EspIndexForPushAll(input_reg) * kPointerSize), tmp); | 2258 __ PopSafepointRegisters(); |
| 2259 } |
| 2257 | 2260 |
| 2258 __ PopSafepointRegisters(); | 2261 |
| 2262 void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { |
| 2263 Register input_reg = ToRegister(instr->InputAt(0)); |
| 2264 __ test(input_reg, Operand(input_reg)); |
| 2265 Label is_positive; |
| 2266 __ j(not_sign, &is_positive); |
| 2267 __ neg(input_reg); |
| 2268 __ test(input_reg, Operand(input_reg)); |
| 2269 DeoptimizeIf(negative, instr->environment()); |
| 2270 __ bind(&is_positive); |
| 2259 } | 2271 } |
| 2260 | 2272 |
| 2261 | 2273 |
| 2262 void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { | 2274 void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { |
| 2263 // Class for deferred case. | 2275 // Class for deferred case. |
| 2264 class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { | 2276 class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
| 2265 public: | 2277 public: |
| 2266 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, | 2278 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, |
| 2267 LUnaryMathOperation* instr) | 2279 LUnaryMathOperation* instr) |
| 2268 : LDeferredCode(codegen), instr_(instr) { } | 2280 : LDeferredCode(codegen), instr_(instr) { } |
| 2269 virtual void Generate() { | 2281 virtual void Generate() { |
| 2270 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); | 2282 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 2271 } | 2283 } |
| 2272 private: | 2284 private: |
| 2273 LUnaryMathOperation* instr_; | 2285 LUnaryMathOperation* instr_; |
| 2274 }; | 2286 }; |
| 2275 | 2287 |
| 2276 ASSERT(instr->InputAt(0)->Equals(instr->result())); | 2288 ASSERT(instr->InputAt(0)->Equals(instr->result())); |
| 2277 Representation r = instr->hydrogen()->value()->representation(); | 2289 Representation r = instr->hydrogen()->value()->representation(); |
| 2278 | 2290 |
| 2279 if (r.IsDouble()) { | 2291 if (r.IsDouble()) { |
| 2280 XMMRegister scratch = xmm0; | 2292 XMMRegister scratch = xmm0; |
| 2281 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); | 2293 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
| 2282 __ pxor(scratch, scratch); | 2294 __ pxor(scratch, scratch); |
| 2283 __ subsd(scratch, input_reg); | 2295 __ subsd(scratch, input_reg); |
| 2284 __ pand(input_reg, scratch); | 2296 __ pand(input_reg, scratch); |
| 2285 } else if (r.IsInteger32()) { | 2297 } else if (r.IsInteger32()) { |
| 2286 Register input_reg = ToRegister(instr->InputAt(0)); | 2298 EmitIntegerMathAbs(instr); |
| 2287 __ test(input_reg, Operand(input_reg)); | |
| 2288 Label is_positive; | |
| 2289 __ j(not_sign, &is_positive); | |
| 2290 __ neg(input_reg); | |
| 2291 __ test(input_reg, Operand(input_reg)); | |
| 2292 DeoptimizeIf(negative, instr->environment()); | |
| 2293 __ bind(&is_positive); | |
| 2294 } else { // Tagged case. | 2299 } else { // Tagged case. |
| 2295 DeferredMathAbsTaggedHeapNumber* deferred = | 2300 DeferredMathAbsTaggedHeapNumber* deferred = |
| 2296 new DeferredMathAbsTaggedHeapNumber(this, instr); | 2301 new DeferredMathAbsTaggedHeapNumber(this, instr); |
| 2297 Label not_smi; | |
| 2298 Register input_reg = ToRegister(instr->InputAt(0)); | 2302 Register input_reg = ToRegister(instr->InputAt(0)); |
| 2299 // Smi check. | 2303 // Smi check. |
| 2300 __ test(input_reg, Immediate(kSmiTagMask)); | 2304 __ test(input_reg, Immediate(kSmiTagMask)); |
| 2301 __ j(not_zero, deferred->entry()); | 2305 __ j(not_zero, deferred->entry()); |
| 2302 __ test(input_reg, Operand(input_reg)); | 2306 EmitIntegerMathAbs(instr); |
| 2303 Label is_positive; | |
| 2304 __ j(not_sign, &is_positive); | |
| 2305 __ neg(input_reg); | |
| 2306 | |
| 2307 __ test(input_reg, Operand(input_reg)); | |
| 2308 DeoptimizeIf(negative, instr->environment()); | |
| 2309 | |
| 2310 __ bind(&is_positive); | |
| 2311 __ bind(deferred->exit()); | 2307 __ bind(deferred->exit()); |
| 2312 } | 2308 } |
| 2313 } | 2309 } |
| 2314 | 2310 |
| 2315 | 2311 |
| 2316 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { | 2312 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { |
| 2317 XMMRegister xmm_scratch = xmm0; | 2313 XMMRegister xmm_scratch = xmm0; |
| 2318 Register output_reg = ToRegister(instr->result()); | 2314 Register output_reg = ToRegister(instr->result()); |
| 2319 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); | 2315 XMMRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
| 2320 __ xorpd(xmm_scratch, xmm_scratch); // Zero the register. | 2316 __ xorpd(xmm_scratch, xmm_scratch); // Zero the register. |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3584 ASSERT(osr_pc_offset_ == -1); | 3580 ASSERT(osr_pc_offset_ == -1); |
| 3585 osr_pc_offset_ = masm()->pc_offset(); | 3581 osr_pc_offset_ = masm()->pc_offset(); |
| 3586 } | 3582 } |
| 3587 | 3583 |
| 3588 | 3584 |
| 3589 #undef __ | 3585 #undef __ |
| 3590 | 3586 |
| 3591 } } // namespace v8::internal | 3587 } } // namespace v8::internal |
| 3592 | 3588 |
| 3593 #endif // V8_TARGET_ARCH_IA32 | 3589 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |