OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 // Result just fit in r64, because it's int32 * uint32. | 1126 // Result just fit in r64, because it's int32 * uint32. |
1127 __ imul(reg2, reg1); | 1127 __ imul(reg2, reg1); |
1128 | 1128 |
1129 __ addq(reg2, Immediate(1 << 30)); | 1129 __ addq(reg2, Immediate(1 << 30)); |
1130 __ sar(reg2, Immediate(shift)); | 1130 __ sar(reg2, Immediate(shift)); |
1131 } | 1131 } |
1132 } | 1132 } |
1133 | 1133 |
1134 | 1134 |
1135 void LCodeGen::DoDivI(LDivI* instr) { | 1135 void LCodeGen::DoDivI(LDivI* instr) { |
1136 if (instr->hydrogen()->HasPowerOf2Divisor()) { | |
1137 Register dividend = ToRegister(instr->left()); | |
1138 int32_t divisor = | |
1139 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); | |
1140 int32_t test_value = 0; | |
1141 int32_t power = 0; | |
1142 | |
1143 if (divisor > 0) { | |
1144 test_value = divisor - 1; | |
1145 power = WhichPowerOf2(divisor); | |
1146 } else { | |
1147 // Check for (0 / -x) that will produce negative zero. | |
1148 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
1149 __ testl(dividend, dividend); | |
1150 DeoptimizeIf(zero, instr->environment()); | |
1151 } | |
1152 // Check for (kMinInt / -1). | |
1153 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | |
1154 __ cmpl(dividend, Immediate(kMinInt)); | |
1155 DeoptimizeIf(zero, instr->environment()); | |
1156 } | |
1157 test_value = - divisor - 1; | |
1158 power = WhichPowerOf2(-divisor); | |
1159 } | |
1160 | |
1161 if (test_value != 0) { | |
Yang
2012/12/10 09:47:28
Ditto.
| |
1162 // Deoptimize if remainder is not 0. | |
1163 __ testl(dividend, Immediate(test_value)); | |
1164 DeoptimizeIf(not_zero, instr->environment()); | |
1165 __ sarl(dividend, Immediate(power)); | |
1166 } | |
1167 | |
1168 if (divisor < 0) __ negl(dividend); | |
1169 | |
1170 return; | |
1171 } | |
1172 | |
1136 LOperand* right = instr->right(); | 1173 LOperand* right = instr->right(); |
1137 ASSERT(ToRegister(instr->result()).is(rax)); | 1174 ASSERT(ToRegister(instr->result()).is(rax)); |
1138 ASSERT(ToRegister(instr->left()).is(rax)); | 1175 ASSERT(ToRegister(instr->left()).is(rax)); |
1139 ASSERT(!ToRegister(instr->right()).is(rax)); | 1176 ASSERT(!ToRegister(instr->right()).is(rax)); |
1140 ASSERT(!ToRegister(instr->right()).is(rdx)); | 1177 ASSERT(!ToRegister(instr->right()).is(rdx)); |
1141 | 1178 |
1142 Register left_reg = rax; | 1179 Register left_reg = rax; |
1143 | 1180 |
1144 // Check for x / 0. | 1181 // Check for x / 0. |
1145 Register right_reg = ToRegister(right); | 1182 Register right_reg = ToRegister(right); |
1146 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | 1183 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
1147 __ testl(right_reg, right_reg); | 1184 __ testl(right_reg, right_reg); |
1148 DeoptimizeIf(zero, instr->environment()); | 1185 DeoptimizeIf(zero, instr->environment()); |
1149 } | 1186 } |
1150 | 1187 |
1151 // Check for (0 / -x) that will produce negative zero. | 1188 // Check for (0 / -x) that will produce negative zero. |
1152 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1189 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1153 Label left_not_zero; | 1190 Label left_not_zero; |
1154 __ testl(left_reg, left_reg); | 1191 __ testl(left_reg, left_reg); |
1155 __ j(not_zero, &left_not_zero, Label::kNear); | 1192 __ j(not_zero, &left_not_zero, Label::kNear); |
1156 __ testl(right_reg, right_reg); | 1193 __ testl(right_reg, right_reg); |
1157 DeoptimizeIf(sign, instr->environment()); | 1194 DeoptimizeIf(sign, instr->environment()); |
1158 __ bind(&left_not_zero); | 1195 __ bind(&left_not_zero); |
1159 } | 1196 } |
1160 | 1197 |
1161 // Check for (-kMinInt / -1). | 1198 // Check for (kMinInt / -1). |
1162 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | 1199 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
1163 Label left_not_min_int; | 1200 Label left_not_min_int; |
1164 __ cmpl(left_reg, Immediate(kMinInt)); | 1201 __ cmpl(left_reg, Immediate(kMinInt)); |
1165 __ j(not_zero, &left_not_min_int, Label::kNear); | 1202 __ j(not_zero, &left_not_min_int, Label::kNear); |
1166 __ cmpl(right_reg, Immediate(-1)); | 1203 __ cmpl(right_reg, Immediate(-1)); |
1167 DeoptimizeIf(zero, instr->environment()); | 1204 DeoptimizeIf(zero, instr->environment()); |
1168 __ bind(&left_not_min_int); | 1205 __ bind(&left_not_min_int); |
1169 } | 1206 } |
1170 | 1207 |
1171 // Sign extend to rdx. | 1208 // Sign extend to rdx. |
(...skipping 4319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5491 FixedArray::kHeaderSize - kPointerSize)); | 5528 FixedArray::kHeaderSize - kPointerSize)); |
5492 __ bind(&done); | 5529 __ bind(&done); |
5493 } | 5530 } |
5494 | 5531 |
5495 | 5532 |
5496 #undef __ | 5533 #undef __ |
5497 | 5534 |
5498 } } // namespace v8::internal | 5535 } } // namespace v8::internal |
5499 | 5536 |
5500 #endif // V8_TARGET_ARCH_X64 | 5537 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |