OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 3416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3427 Register input_reg = ToRegister(instr->value()); | 3427 Register input_reg = ToRegister(instr->value()); |
3428 __ testl(input_reg, input_reg); | 3428 __ testl(input_reg, input_reg); |
3429 Label is_positive; | 3429 Label is_positive; |
3430 __ j(not_sign, &is_positive, Label::kNear); | 3430 __ j(not_sign, &is_positive, Label::kNear); |
3431 __ negl(input_reg); // Sets flags. | 3431 __ negl(input_reg); // Sets flags. |
3432 DeoptimizeIf(negative, instr->environment()); | 3432 DeoptimizeIf(negative, instr->environment()); |
3433 __ bind(&is_positive); | 3433 __ bind(&is_positive); |
3434 } | 3434 } |
3435 | 3435 |
3436 | 3436 |
| 3437 void LCodeGen::EmitInteger64MathAbs(LMathAbs* instr) { |
| 3438 Register input_reg = ToRegister(instr->value()); |
| 3439 __ testq(input_reg, input_reg); |
| 3440 Label is_positive; |
| 3441 __ j(not_sign, &is_positive, Label::kNear); |
| 3442 __ neg(input_reg); // Sets flags. |
| 3443 DeoptimizeIf(negative, instr->environment()); |
| 3444 __ bind(&is_positive); |
| 3445 } |
| 3446 |
| 3447 |
3437 void LCodeGen::DoMathAbs(LMathAbs* instr) { | 3448 void LCodeGen::DoMathAbs(LMathAbs* instr) { |
3438 // Class for deferred case. | 3449 // Class for deferred case. |
3439 class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { | 3450 class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
3440 public: | 3451 public: |
3441 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) | 3452 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
3442 : LDeferredCode(codegen), instr_(instr) { } | 3453 : LDeferredCode(codegen), instr_(instr) { } |
3443 virtual void Generate() { | 3454 virtual void Generate() { |
3444 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); | 3455 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
3445 } | 3456 } |
3446 virtual LInstruction* instr() { return instr_; } | 3457 virtual LInstruction* instr() { return instr_; } |
3447 private: | 3458 private: |
3448 LMathAbs* instr_; | 3459 LMathAbs* instr_; |
3449 }; | 3460 }; |
3450 | 3461 |
3451 ASSERT(instr->value()->Equals(instr->result())); | 3462 ASSERT(instr->value()->Equals(instr->result())); |
3452 Representation r = instr->hydrogen()->value()->representation(); | 3463 Representation r = instr->hydrogen()->value()->representation(); |
3453 | 3464 |
3454 if (r.IsDouble()) { | 3465 if (r.IsDouble()) { |
3455 XMMRegister scratch = xmm0; | 3466 XMMRegister scratch = xmm0; |
3456 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 3467 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
3457 __ xorps(scratch, scratch); | 3468 __ xorps(scratch, scratch); |
3458 __ subsd(scratch, input_reg); | 3469 __ subsd(scratch, input_reg); |
3459 __ andpd(input_reg, scratch); | 3470 __ andpd(input_reg, scratch); |
3460 } else if (r.IsInteger32()) { | 3471 } else if (r.IsInteger32()) { |
3461 EmitIntegerMathAbs(instr); | 3472 EmitIntegerMathAbs(instr); |
| 3473 } else if (r.IsSmi()) { |
| 3474 EmitInteger64MathAbs(instr); |
3462 } else { // Tagged case. | 3475 } else { // Tagged case. |
3463 DeferredMathAbsTaggedHeapNumber* deferred = | 3476 DeferredMathAbsTaggedHeapNumber* deferred = |
3464 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); | 3477 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
3465 Register input_reg = ToRegister(instr->value()); | 3478 Register input_reg = ToRegister(instr->value()); |
3466 // Smi check. | 3479 // Smi check. |
3467 __ JumpIfNotSmi(input_reg, deferred->entry()); | 3480 __ JumpIfNotSmi(input_reg, deferred->entry()); |
3468 __ SmiToInteger32(input_reg, input_reg); | 3481 __ SmiToInteger32(input_reg, input_reg); |
3469 EmitIntegerMathAbs(instr); | 3482 EmitIntegerMathAbs(instr); |
3470 __ Integer32ToSmi(input_reg, input_reg); | 3483 __ Integer32ToSmi(input_reg, input_reg); |
3471 __ bind(deferred->exit()); | 3484 __ bind(deferred->exit()); |
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5574 FixedArray::kHeaderSize - kPointerSize)); | 5587 FixedArray::kHeaderSize - kPointerSize)); |
5575 __ bind(&done); | 5588 __ bind(&done); |
5576 } | 5589 } |
5577 | 5590 |
5578 | 5591 |
5579 #undef __ | 5592 #undef __ |
5580 | 5593 |
5581 } } // namespace v8::internal | 5594 } } // namespace v8::internal |
5582 | 5595 |
5583 #endif // V8_TARGET_ARCH_X64 | 5596 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |