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 3873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3884 return; | 3884 return; |
3885 } | 3885 } |
3886 | 3886 |
3887 // Check for (0 / -x) that will produce negative zero. | 3887 // Check for (0 / -x) that will produce negative zero. |
3888 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 3888 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
3889 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 3889 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
3890 __ Cmp(dividend, 0); | 3890 __ Cmp(dividend, 0); |
3891 DeoptimizeIf(eq, instr->environment()); | 3891 DeoptimizeIf(eq, instr->environment()); |
3892 } | 3892 } |
3893 | 3893 |
3894 // TODO(svenpanne) Add correction terms. | 3894 // Easy case: We need no dynamic check for the dividend and the flooring |
3895 __ TruncatingDiv(result, dividend, divisor); | 3895 // division is the same as the truncating division. |
| 3896 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 3897 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 3898 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 3899 if (divisor < 0) __ Neg(result, result); |
| 3900 return; |
| 3901 } |
| 3902 |
| 3903 // In the general case we may need to adjust before and after the truncating |
| 3904 // division to get a flooring division. |
| 3905 Register temp = ToRegister32(instr->temp()); |
| 3906 ASSERT(!AreAliased(temp, dividend, result)); |
| 3907 Label needs_adjustment, done; |
| 3908 __ Cmp(dividend, 0); |
| 3909 __ B(divisor > 0 ? lt : gt, &needs_adjustment); |
| 3910 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 3911 if (divisor < 0) __ Neg(result, result); |
| 3912 __ B(&done); |
| 3913 __ bind(&needs_adjustment); |
| 3914 __ Add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
| 3915 __ TruncatingDiv(result, temp, Abs(divisor)); |
| 3916 if (divisor < 0) __ Neg(result, result); |
| 3917 __ Sub(result, result, Operand(1)); |
| 3918 __ bind(&done); |
3896 } | 3919 } |
3897 | 3920 |
3898 | 3921 |
3899 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { | 3922 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
3900 Register dividend = ToRegister32(instr->dividend()); | 3923 Register dividend = ToRegister32(instr->dividend()); |
3901 Register divisor = ToRegister32(instr->divisor()); | 3924 Register divisor = ToRegister32(instr->divisor()); |
3902 Register remainder = ToRegister32(instr->temp()); | 3925 Register remainder = ToRegister32(instr->temp()); |
3903 Register result = ToRegister32(instr->result()); | 3926 Register result = ToRegister32(instr->result()); |
3904 | 3927 |
3905 // This can't cause an exception on ARM, so we can speculatively | 3928 // This can't cause an exception on ARM, so we can speculatively |
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5832 __ Bind(&out_of_object); | 5855 __ Bind(&out_of_object); |
5833 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 5856 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
5834 // Index is equal to negated out of object property index plus 1. | 5857 // Index is equal to negated out of object property index plus 1. |
5835 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); | 5858 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
5836 __ Ldr(result, FieldMemOperand(result, | 5859 __ Ldr(result, FieldMemOperand(result, |
5837 FixedArray::kHeaderSize - kPointerSize)); | 5860 FixedArray::kHeaderSize - kPointerSize)); |
5838 __ Bind(&done); | 5861 __ Bind(&done); |
5839 } | 5862 } |
5840 | 5863 |
5841 } } // namespace v8::internal | 5864 } } // namespace v8::internal |
OLD | NEW |