| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "arm64/lithium-codegen-arm64.h" | 7 #include "arm64/lithium-codegen-arm64.h" |
| 8 #include "arm64/lithium-gap-resolver-arm64.h" | 8 #include "arm64/lithium-gap-resolver-arm64.h" |
| 9 #include "code-stubs.h" | 9 #include "code-stubs.h" |
| 10 #include "stub-cache.h" | 10 #include "stub-cache.h" |
| (...skipping 4093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4104 // The range [-0.5, -0.0[ yielded +0.0. Force the sign to negative. | 4104 // The range [-0.5, -0.0[ yielded +0.0. Force the sign to negative. |
| 4105 __ Fabs(result, result); | 4105 __ Fabs(result, result); |
| 4106 __ Fneg(result, result); | 4106 __ Fneg(result, result); |
| 4107 | 4107 |
| 4108 __ Bind(&done); | 4108 __ Bind(&done); |
| 4109 } | 4109 } |
| 4110 | 4110 |
| 4111 | 4111 |
| 4112 void LCodeGen::DoMathRoundI(LMathRoundI* instr) { | 4112 void LCodeGen::DoMathRoundI(LMathRoundI* instr) { |
| 4113 DoubleRegister input = ToDoubleRegister(instr->value()); | 4113 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 4114 DoubleRegister temp1 = ToDoubleRegister(instr->temp1()); | 4114 DoubleRegister temp = ToDoubleRegister(instr->temp1()); |
| 4115 DoubleRegister dot_five = double_scratch(); |
| 4115 Register result = ToRegister(instr->result()); | 4116 Register result = ToRegister(instr->result()); |
| 4116 Label try_rounding; | |
| 4117 Label done; | 4117 Label done; |
| 4118 | 4118 |
| 4119 // Math.round() rounds to the nearest integer, with ties going towards | 4119 // Math.round() rounds to the nearest integer, with ties going towards |
| 4120 // +infinity. This does not match any IEEE-754 rounding mode. | 4120 // +infinity. This does not match any IEEE-754 rounding mode. |
| 4121 // - Infinities and NaNs are propagated unchanged, but cause deopts because | 4121 // - Infinities and NaNs are propagated unchanged, but cause deopts because |
| 4122 // they can't be represented as integers. | 4122 // they can't be represented as integers. |
| 4123 // - The sign of the result is the same as the sign of the input. This means | 4123 // - The sign of the result is the same as the sign of the input. This means |
| 4124 // that -0.0 rounds to itself, and values -0.5 <= input < 0 also produce a | 4124 // that -0.0 rounds to itself, and values -0.5 <= input < 0 also produce a |
| 4125 // result of -0.0. | 4125 // result of -0.0. |
| 4126 | 4126 |
| 4127 DoubleRegister dot_five = double_scratch(); | 4127 // Add 0.5 and round towards -infinity. |
| 4128 __ Fmov(dot_five, 0.5); | 4128 __ Fmov(dot_five, 0.5); |
| 4129 __ Fabs(temp1, input); | 4129 __ Fadd(temp, input, dot_five); |
| 4130 __ Fcmp(temp1, dot_five); | 4130 __ Fcvtms(result, temp); |
| 4131 // If input is in [-0.5, -0], the result is -0. | |
| 4132 // If input is in [+0, +0.5[, the result is +0. | |
| 4133 // If the input is +0.5, the result is 1. | |
| 4134 __ B(hi, &try_rounding); // hi so NaN will also branch. | |
| 4135 | 4131 |
| 4132 // The result is correct if: |
| 4133 // result is not 0, as the input could be NaN or [-0.5, -0.0]. |
| 4134 // result is not 1, as 0.499...94 will wrongly map to 1. |
| 4135 // result fits in 32 bits. |
| 4136 __ Cmp(result, Operand(result.W(), SXTW)); |
| 4137 __ Ccmp(result, 1, ZFlag, eq); |
| 4138 __ B(hi, &done); |
| 4139 |
| 4140 // At this point, we have to handle possible inputs of NaN or numbers in the |
| 4141 // range [-0.5, 1.5[, or numbers larger than 32 bits. |
| 4142 |
| 4143 // Deoptimize if the result > 1, as it must be larger than 32 bits. |
| 4144 __ Cmp(result, 1); |
| 4145 DeoptimizeIf(hi, instr->environment()); |
| 4146 |
| 4147 // Deoptimize for negative inputs, which at this point are only numbers in |
| 4148 // the range [-0.5, -0.0] |
| 4136 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 4149 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4137 __ Fmov(result, input); | 4150 __ Fmov(result, input); |
| 4138 DeoptimizeIfNegative(result, instr->environment()); // [-0.5, -0.0]. | 4151 DeoptimizeIfNegative(result, instr->environment()); |
| 4139 } | 4152 } |
| 4153 |
| 4154 // Deoptimize if the input was NaN. |
| 4140 __ Fcmp(input, dot_five); | 4155 __ Fcmp(input, dot_five); |
| 4141 __ Mov(result, 1); // +0.5. | 4156 DeoptimizeIf(vs, instr->environment()); |
| 4142 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on | |
| 4143 // flag kBailoutOnMinusZero, will return 0 (xzr). | |
| 4144 __ Csel(result, result, xzr, eq); | |
| 4145 __ B(&done); | |
| 4146 | 4157 |
| 4147 __ Bind(&try_rounding); | 4158 // Now, the only unhandled inputs are in the range [0.0, 1.5[ (or [-0.5, 1.5[ |
| 4148 // Since we're providing a 32-bit result, we can implement ties-to-infinity by | 4159 // if we didn't generate a -0.0 bailout). If input >= 0.5 then return 1, |
| 4149 // adding 0.5 to the input, then taking the floor of the result. This does not | 4160 // else 0; we avoid dealing with 0.499...94 directly. |
| 4150 // work for very large positive doubles because adding 0.5 would cause an | 4161 __ Cset(result, ge); |
| 4151 // intermediate rounding stage, so a different approach is necessary when a | |
| 4152 // double result is needed. | |
| 4153 __ Fadd(temp1, input, dot_five); | |
| 4154 __ Fcvtms(result, temp1); | |
| 4155 | |
| 4156 // Deopt if | |
| 4157 // * the input was NaN | |
| 4158 // * the result is not representable using a 32-bit integer. | |
| 4159 __ Fcmp(input, 0.0); | |
| 4160 __ Ccmp(result, Operand(result.W(), SXTW), NoFlag, vc); | |
| 4161 DeoptimizeIf(ne, instr->environment()); | |
| 4162 | |
| 4163 __ Bind(&done); | 4162 __ Bind(&done); |
| 4164 } | 4163 } |
| 4165 | 4164 |
| 4166 | 4165 |
| 4167 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { | 4166 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
| 4168 DoubleRegister input = ToDoubleRegister(instr->value()); | 4167 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 4169 DoubleRegister result = ToDoubleRegister(instr->result()); | 4168 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 4170 __ Fsqrt(result, input); | 4169 __ Fsqrt(result, input); |
| 4171 } | 4170 } |
| 4172 | 4171 |
| (...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6002 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 6001 __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 6003 // Index is equal to negated out of object property index plus 1. | 6002 // Index is equal to negated out of object property index plus 1. |
| 6004 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); | 6003 __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2)); |
| 6005 __ Ldr(result, FieldMemOperand(result, | 6004 __ Ldr(result, FieldMemOperand(result, |
| 6006 FixedArray::kHeaderSize - kPointerSize)); | 6005 FixedArray::kHeaderSize - kPointerSize)); |
| 6007 __ Bind(deferred->exit()); | 6006 __ Bind(deferred->exit()); |
| 6008 __ Bind(&done); | 6007 __ Bind(&done); |
| 6009 } | 6008 } |
| 6010 | 6009 |
| 6011 } } // namespace v8::internal | 6010 } } // namespace v8::internal |
| OLD | NEW |