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 4007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4018 } | 4018 } |
4019 } | 4019 } |
4020 | 4020 |
4021 | 4021 |
4022 void LCodeGen::DoMathRound(LMathRound* instr) { | 4022 void LCodeGen::DoMathRound(LMathRound* instr) { |
4023 // TODO(jbramley): We could provide a double result here using frint. | 4023 // TODO(jbramley): We could provide a double result here using frint. |
4024 DoubleRegister input = ToDoubleRegister(instr->value()); | 4024 DoubleRegister input = ToDoubleRegister(instr->value()); |
4025 DoubleRegister temp1 = ToDoubleRegister(instr->temp1()); | 4025 DoubleRegister temp1 = ToDoubleRegister(instr->temp1()); |
4026 Register result = ToRegister(instr->result()); | 4026 Register result = ToRegister(instr->result()); |
4027 Label try_rounding; | 4027 Label try_rounding; |
4028 Label deopt; | |
4029 Label done; | 4028 Label done; |
4030 | 4029 |
4031 // Math.round() rounds to the nearest integer, with ties going towards | 4030 // Math.round() rounds to the nearest integer, with ties going towards |
4032 // +infinity. This does not match any IEEE-754 rounding mode. | 4031 // +infinity. This does not match any IEEE-754 rounding mode. |
4033 // - Infinities and NaNs are propagated unchanged, but cause deopts because | 4032 // - Infinities and NaNs are propagated unchanged, but cause deopts because |
4034 // they can't be represented as integers. | 4033 // they can't be represented as integers. |
4035 // - The sign of the result is the same as the sign of the input. This means | 4034 // - The sign of the result is the same as the sign of the input. This means |
4036 // that -0.0 rounds to itself, and values -0.5 <= input < 0 also produce a | 4035 // that -0.0 rounds to itself, and values -0.5 <= input < 0 also produce a |
4037 // result of -0.0. | 4036 // result of -0.0. |
4038 | 4037 |
4039 DoubleRegister dot_five = double_scratch(); | 4038 DoubleRegister dot_five = double_scratch(); |
4040 __ Fmov(dot_five, 0.5); | 4039 __ Fmov(dot_five, 0.5); |
4041 __ Fabs(temp1, input); | 4040 __ Fabs(temp1, input); |
4042 __ Fcmp(temp1, dot_five); | 4041 __ Fcmp(temp1, dot_five); |
4043 // If input is in [-0.5, -0], the result is -0. | 4042 // If input is in [-0.5, -0], the result is -0. |
4044 // If input is in [+0, +0.5[, the result is +0. | 4043 // If input is in [+0, +0.5[, the result is +0. |
4045 // If the input is +0.5, the result is 1. | 4044 // If the input is +0.5, the result is 1. |
4046 __ B(hi, &try_rounding); // hi so NaN will also branch. | 4045 __ B(hi, &try_rounding); // hi so NaN will also branch. |
4047 | 4046 |
4048 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 4047 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
4049 __ Fmov(result, input); | 4048 __ Fmov(result, input); |
4050 __ Cmp(result, 0); | 4049 DeoptimizeIfNegative(result, instr->environment()); // [-0.5, -0.0]. |
4051 DeoptimizeIf(mi, instr->environment()); // [-0.5, -0.0]. | |
4052 } | 4050 } |
4053 __ Fcmp(input, dot_five); | 4051 __ Fcmp(input, dot_five); |
4054 __ Mov(result, 1); // +0.5. | 4052 __ Mov(result, 1); // +0.5. |
4055 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on | 4053 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on |
4056 // flag kBailoutOnMinusZero, will return 0 (xzr). | 4054 // flag kBailoutOnMinusZero, will return 0 (xzr). |
4057 __ Csel(result, result, xzr, eq); | 4055 __ Csel(result, result, xzr, eq); |
4058 __ B(&done); | 4056 __ B(&done); |
4059 | 4057 |
4060 __ Bind(&deopt); | |
4061 Deoptimize(instr->environment()); | |
4062 | |
4063 __ Bind(&try_rounding); | 4058 __ Bind(&try_rounding); |
4064 // Since we're providing a 32-bit result, we can implement ties-to-infinity by | 4059 // Since we're providing a 32-bit result, we can implement ties-to-infinity by |
4065 // adding 0.5 to the input, then taking the floor of the result. This does not | 4060 // adding 0.5 to the input, then taking the floor of the result. This does not |
4066 // work for very large positive doubles because adding 0.5 would cause an | 4061 // work for very large positive doubles because adding 0.5 would cause an |
4067 // intermediate rounding stage, so a different approach will be necessary if a | 4062 // intermediate rounding stage, so a different approach will be necessary if a |
4068 // double result is needed. | 4063 // double result is needed. |
4069 __ Fadd(temp1, input, dot_five); | 4064 __ Fadd(temp1, input, dot_five); |
4070 __ Fcvtms(result, temp1); | 4065 __ Fcvtms(result, temp1); |
4071 | 4066 |
4072 // Deopt if | 4067 // Deopt if |
4073 // * the input was NaN | 4068 // * the input was NaN |
4074 // * the result is not representable using a 32-bit integer. | 4069 // * the result is not representable using a 32-bit integer. |
4075 __ Fcmp(input, 0.0); | 4070 __ Fcmp(input, 0.0); |
4076 __ Ccmp(result, Operand(result.W(), SXTW), NoFlag, vc); | 4071 __ Ccmp(result, Operand(result.W(), SXTW), NoFlag, vc); |
4077 __ B(ne, &deopt); | 4072 DeoptimizeIf(ne, instr->environment()); |
4078 | 4073 |
4079 __ Bind(&done); | 4074 __ Bind(&done); |
4080 } | 4075 } |
4081 | 4076 |
4082 | 4077 |
4083 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { | 4078 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
4084 DoubleRegister input = ToDoubleRegister(instr->value()); | 4079 DoubleRegister input = ToDoubleRegister(instr->value()); |
4085 DoubleRegister result = ToDoubleRegister(instr->result()); | 4080 DoubleRegister result = ToDoubleRegister(instr->result()); |
4086 __ Fsqrt(result, input); | 4081 __ Fsqrt(result, input); |
4087 } | 4082 } |
(...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5837 __ Bind(&out_of_object); | 5832 __ Bind(&out_of_object); |
5838 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 5833 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
5839 // Index is equal to negated out of object property index plus 1. | 5834 // Index is equal to negated out of object property index plus 1. |
5840 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); | 5835 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
5841 __ Ldr(result, FieldMemOperand(result, | 5836 __ Ldr(result, FieldMemOperand(result, |
5842 FixedArray::kHeaderSize - kPointerSize)); | 5837 FixedArray::kHeaderSize - kPointerSize)); |
5843 __ Bind(&done); | 5838 __ Bind(&done); |
5844 } | 5839 } |
5845 | 5840 |
5846 } } // namespace v8::internal | 5841 } } // namespace v8::internal |
OLD | NEW |