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 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 return; | 1153 return; |
1154 } | 1154 } |
1155 | 1155 |
1156 // Check for (0 / -x) that will produce negative zero. | 1156 // Check for (0 / -x) that will produce negative zero. |
1157 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1157 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
1158 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1158 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
1159 __ testl(dividend, dividend); | 1159 __ testl(dividend, dividend); |
1160 DeoptimizeIf(zero, instr->environment()); | 1160 DeoptimizeIf(zero, instr->environment()); |
1161 } | 1161 } |
1162 | 1162 |
1163 // TODO(svenpanne) Add correction terms. | 1163 // Easy case: We need no dynamic check for the dividend and the flooring |
1164 __ TruncatingDiv(dividend, divisor); | 1164 // division is the same as the truncating division. |
| 1165 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1166 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1167 __ TruncatingDiv(dividend, Abs(divisor)); |
| 1168 if (divisor < 0) __ negl(rdx); |
| 1169 return; |
| 1170 } |
| 1171 |
| 1172 // In the general case we may need to adjust before and after the truncating |
| 1173 // division to get a flooring division. |
| 1174 Register temp = ToRegister(instr->temp3()); |
| 1175 ASSERT(!temp.is(dividend) && !temp.is(rax) && !temp.is(rdx)); |
| 1176 Label needs_adjustment, done; |
| 1177 __ cmpl(dividend, Immediate(0)); |
| 1178 __ j(divisor > 0 ? less : greater, &needs_adjustment, Label::kNear); |
| 1179 __ TruncatingDiv(dividend, Abs(divisor)); |
| 1180 if (divisor < 0) __ negl(rdx); |
| 1181 __ jmp(&done, Label::kNear); |
| 1182 __ bind(&needs_adjustment); |
| 1183 __ leal(temp, Operand(dividend, divisor > 0 ? 1 : -1)); |
| 1184 __ TruncatingDiv(temp, Abs(divisor)); |
| 1185 if (divisor < 0) __ negl(rdx); |
| 1186 __ decl(rdx); |
| 1187 __ bind(&done); |
1165 } | 1188 } |
1166 | 1189 |
1167 | 1190 |
1168 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { | 1191 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
1169 Register dividend = ToRegister(instr->dividend()); | 1192 Register dividend = ToRegister(instr->dividend()); |
1170 int32_t divisor = instr->divisor(); | 1193 int32_t divisor = instr->divisor(); |
1171 Register result = ToRegister(instr->result()); | 1194 Register result = ToRegister(instr->result()); |
1172 ASSERT(divisor == kMinInt || (divisor != 0 && IsPowerOf2(Abs(divisor)))); | 1195 ASSERT(divisor == kMinInt || (divisor != 0 && IsPowerOf2(Abs(divisor)))); |
1173 ASSERT(!result.is(dividend)); | 1196 ASSERT(!result.is(dividend)); |
1174 | 1197 |
(...skipping 4461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5636 FixedArray::kHeaderSize - kPointerSize)); | 5659 FixedArray::kHeaderSize - kPointerSize)); |
5637 __ bind(&done); | 5660 __ bind(&done); |
5638 } | 5661 } |
5639 | 5662 |
5640 | 5663 |
5641 #undef __ | 5664 #undef __ |
5642 | 5665 |
5643 } } // namespace v8::internal | 5666 } } // namespace v8::internal |
5644 | 5667 |
5645 #endif // V8_TARGET_ARCH_X64 | 5668 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |