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 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2444 | 2444 |
2445 | 2445 |
2446 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { | 2446 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
2447 ASSERT(ToRegister(instr->result()).is(r0)); | 2447 ASSERT(ToRegister(instr->result()).is(r0)); |
2448 __ mov(r1, Operand(instr->function())); | 2448 __ mov(r1, Operand(instr->function())); |
2449 CallKnownFunction(instr->function(), instr->arity(), instr); | 2449 CallKnownFunction(instr->function(), instr->arity(), instr); |
2450 } | 2450 } |
2451 | 2451 |
2452 | 2452 |
2453 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { | 2453 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { |
2454 Abort("DoDeferredMathAbsTaggedHeapNumber unimplemented."); | 2454 Register input = ToRegister(instr->input()); |
2455 Register scratch = scratch0(); | |
2456 | |
2457 // Deoptimize if not a heap number. | |
2458 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | |
2459 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | |
2460 __ cmp(scratch, Operand(ip)); | |
2461 DeoptimizeIf(ne, instr->environment()); | |
2462 | |
2463 Label done; | |
2464 Register tmp = input.is(r0) ? r1 : r0; | |
2465 Register tmp2 = r2; | |
2466 Register tmp3 = r3; | |
2467 | |
2468 Label negative; | |
2469 __ ldr(scratch, FieldMemOperand(input, HeapNumber::kExponentOffset)); | |
2470 // Check the sign of the argument. If the argument is positive, just | |
2471 // return it. We do not need to patch the stack since |input| and | |
2472 // |result| are the same register and |input| will be restored | |
2473 // unchanged by popping safepoint registers. | |
2474 __ tst(scratch, Operand(HeapNumber::kSignMask)); | |
2475 __ b(ne, &negative); | |
2476 __ jmp(&done); | |
Alexandre
2011/01/20 10:45:34
b(eq, &done);
would be enough.
"done" could be ren
| |
2477 | |
2478 __ bind(&negative); | |
2479 // Preserve the value of all registers. | |
2480 __ PushSafepointRegisters(); | |
2481 | |
2482 Label allocated, slow; | |
2483 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); | |
2484 __ AllocateHeapNumber(tmp, tmp2, tmp3, scratch, &slow); | |
2485 __ b(&allocated); | |
2486 | |
2487 // Slow case: Call the runtime system to do the number allocation. | |
2488 __ bind(&slow); | |
2489 | |
2490 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | |
2491 RecordSafepointWithRegisters( | |
2492 instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); | |
2493 // Set the pointer to the new heap number in tmp. | |
2494 if (!tmp.is(r0)) __ mov(tmp, Operand(r0)); | |
2495 | |
2496 // Restore input_reg after call to runtime. | |
2497 MemOperand input_register_slot = masm()->SafepointRegisterSlot(input); | |
2498 __ ldr(input, input_register_slot); | |
2499 | |
2500 __ bind(&allocated); | |
2501 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kExponentOffset)); | |
2502 __ bic(tmp2, tmp2, Operand(HeapNumber::kSignMask)); | |
2503 __ str(tmp2, FieldMemOperand(tmp, HeapNumber::kExponentOffset)); | |
2504 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); | |
2505 __ str(tmp2, FieldMemOperand(tmp, HeapNumber::kMantissaOffset)); | |
2506 | |
2507 __ str(tmp, input_register_slot); | |
2508 __ PopSafepointRegisters(); | |
2509 | |
2510 __ bind(&done); | |
2511 } | |
2512 | |
2513 | |
2514 void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { | |
2515 Label is_positive; | |
2516 uint32_t kSignMask = 0x80000000u; | |
2517 Register input = ToRegister(instr->input()); | |
2518 __ tst(input, Operand(kSignMask)); | |
2519 __ b(eq, &is_positive); | |
2520 __ rsb(input, input, Operand(0), SetCC); | |
2521 // Deoptimize on overflow. | |
2522 DeoptimizeIf(vs, instr->environment()); | |
2523 __ bind(&is_positive); | |
2455 } | 2524 } |
2456 | 2525 |
2457 | 2526 |
2458 void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { | 2527 void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { |
2459 Abort("DoMathAbs unimplemented."); | 2528 // Class for deferred case. |
2529 class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { | |
2530 public: | |
2531 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, | |
2532 LUnaryMathOperation* instr) | |
2533 : LDeferredCode(codegen), instr_(instr) { } | |
2534 virtual void Generate() { | |
2535 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); | |
2536 } | |
2537 private: | |
2538 LUnaryMathOperation* instr_; | |
2539 }; | |
2540 | |
2541 ASSERT(instr->input()->Equals(instr->result())); | |
2542 Representation r = instr->hydrogen()->value()->representation(); | |
2543 if (r.IsDouble()) { | |
2544 DwVfpRegister input = ToDoubleRegister(instr->input()); | |
2545 // __ vabs(input, input); | |
2546 Abort("Double DoMathAbs unimplemented"); | |
2547 } else if (r.IsInteger32()) { | |
2548 EmitIntegerMathAbs(instr); | |
2549 } else { | |
2550 // Representation is tagged. | |
2551 DeferredMathAbsTaggedHeapNumber* deferred = | |
2552 new DeferredMathAbsTaggedHeapNumber(this, instr); | |
2553 Register input = ToRegister(instr->input()); | |
2554 // Smi check. | |
2555 __ BranchOnNotSmi(input, deferred->entry()); | |
2556 // If smi, handle it directly. | |
2557 EmitIntegerMathAbs(instr); | |
2558 __ bind(deferred->exit()); | |
2559 } | |
2460 } | 2560 } |
2461 | 2561 |
2462 | 2562 |
2463 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { | 2563 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { |
2464 DoubleRegister input = ToDoubleRegister(instr->input()); | 2564 DoubleRegister input = ToDoubleRegister(instr->input()); |
2465 Register result = ToRegister(instr->result()); | 2565 Register result = ToRegister(instr->result()); |
2466 Register prev_fpscr = ToRegister(instr->temp()); | 2566 Register prev_fpscr = ToRegister(instr->temp()); |
2467 SwVfpRegister single_scratch = double_scratch0().low(); | 2567 SwVfpRegister single_scratch = double_scratch0().low(); |
2468 Register scratch = scratch0(); | 2568 Register scratch = scratch0(); |
2469 | 2569 |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3364 | 3464 |
3365 | 3465 |
3366 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 3466 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
3367 Abort("DoOsrEntry unimplemented."); | 3467 Abort("DoOsrEntry unimplemented."); |
3368 } | 3468 } |
3369 | 3469 |
3370 | 3470 |
3371 #undef __ | 3471 #undef __ |
3372 | 3472 |
3373 } } // namespace v8::internal | 3473 } } // namespace v8::internal |
OLD | NEW |