Chromium Code Reviews| 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 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 | 1194 |
| 1195 __ bind(&remainder_eq_dividend); | 1195 __ bind(&remainder_eq_dividend); |
| 1196 __ mov(result_reg, left_reg); | 1196 __ mov(result_reg, left_reg); |
| 1197 | 1197 |
| 1198 __ bind(&done); | 1198 __ bind(&done); |
| 1199 } | 1199 } |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 | 1202 |
| 1203 void LCodeGen::DoDivI(LDivI* instr) { | 1203 void LCodeGen::DoDivI(LDivI* instr) { |
| 1204 if (instr->hydrogen()->HasPowerOf2Divisor()) { | |
| 1205 Register dividend = ToRegister(instr->left()); | |
| 1206 int32_t divisor = | |
| 1207 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); | |
| 1208 int32_t test_value = 0; | |
| 1209 int32_t power = 0; | |
| 1210 | |
| 1211 if (divisor > 0) { | |
| 1212 test_value = divisor - 1; | |
| 1213 power = WhichPowerOf2(divisor); | |
| 1214 } else { | |
| 1215 // Check for (0 / -x) that will produce negative zero. | |
| 1216 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1217 __ test(dividend, Operand(dividend)); | |
| 1218 DeoptimizeIf(zero, instr->environment()); | |
| 1219 } | |
| 1220 // Check for (kMinInt / -1). | |
| 1221 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | |
| 1222 __ cmp(dividend, kMinInt); | |
| 1223 DeoptimizeIf(zero, instr->environment()); | |
| 1224 } | |
| 1225 test_value = - divisor - 1; | |
| 1226 power = WhichPowerOf2(-divisor); | |
| 1227 } | |
| 1228 | |
| 1229 if (test_value != 0) { | |
|
Yang
2012/12/10 09:47:28
this if-block seems also unnecessary if divisor is
| |
| 1230 // Deoptimize if remainder is not 0. | |
| 1231 __ test(dividend, Immediate(test_value)); | |
| 1232 DeoptimizeIf(not_zero, instr->environment()); | |
| 1233 __ sar(dividend, power); | |
| 1234 } | |
| 1235 | |
| 1236 if (divisor < 0) __ neg(dividend); | |
| 1237 | |
| 1238 return; | |
| 1239 } | |
| 1240 | |
| 1204 LOperand* right = instr->right(); | 1241 LOperand* right = instr->right(); |
| 1205 ASSERT(ToRegister(instr->result()).is(eax)); | 1242 ASSERT(ToRegister(instr->result()).is(eax)); |
| 1206 ASSERT(ToRegister(instr->left()).is(eax)); | 1243 ASSERT(ToRegister(instr->left()).is(eax)); |
| 1207 ASSERT(!ToRegister(instr->right()).is(eax)); | 1244 ASSERT(!ToRegister(instr->right()).is(eax)); |
| 1208 ASSERT(!ToRegister(instr->right()).is(edx)); | 1245 ASSERT(!ToRegister(instr->right()).is(edx)); |
| 1209 | 1246 |
| 1210 Register left_reg = eax; | 1247 Register left_reg = eax; |
| 1211 | 1248 |
| 1212 // Check for x / 0. | 1249 // Check for x / 0. |
| 1213 Register right_reg = ToRegister(right); | 1250 Register right_reg = ToRegister(right); |
| 1214 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | 1251 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1215 __ test(right_reg, ToOperand(right)); | 1252 __ test(right_reg, ToOperand(right)); |
| 1216 DeoptimizeIf(zero, instr->environment()); | 1253 DeoptimizeIf(zero, instr->environment()); |
| 1217 } | 1254 } |
| 1218 | 1255 |
| 1219 // Check for (0 / -x) that will produce negative zero. | 1256 // Check for (0 / -x) that will produce negative zero. |
| 1220 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1257 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1221 Label left_not_zero; | 1258 Label left_not_zero; |
| 1222 __ test(left_reg, Operand(left_reg)); | 1259 __ test(left_reg, Operand(left_reg)); |
| 1223 __ j(not_zero, &left_not_zero, Label::kNear); | 1260 __ j(not_zero, &left_not_zero, Label::kNear); |
| 1224 __ test(right_reg, ToOperand(right)); | 1261 __ test(right_reg, ToOperand(right)); |
| 1225 DeoptimizeIf(sign, instr->environment()); | 1262 DeoptimizeIf(sign, instr->environment()); |
| 1226 __ bind(&left_not_zero); | 1263 __ bind(&left_not_zero); |
| 1227 } | 1264 } |
| 1228 | 1265 |
| 1229 // Check for (-kMinInt / -1). | 1266 // Check for (kMinInt / -1). |
| 1230 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | 1267 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1231 Label left_not_min_int; | 1268 Label left_not_min_int; |
| 1232 __ cmp(left_reg, kMinInt); | 1269 __ cmp(left_reg, kMinInt); |
| 1233 __ j(not_zero, &left_not_min_int, Label::kNear); | 1270 __ j(not_zero, &left_not_min_int, Label::kNear); |
| 1234 __ cmp(right_reg, -1); | 1271 __ cmp(right_reg, -1); |
| 1235 DeoptimizeIf(zero, instr->environment()); | 1272 DeoptimizeIf(zero, instr->environment()); |
| 1236 __ bind(&left_not_min_int); | 1273 __ bind(&left_not_min_int); |
| 1237 } | 1274 } |
| 1238 | 1275 |
| 1239 // Sign extend to edx. | 1276 // Sign extend to edx. |
| (...skipping 4653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5893 FixedArray::kHeaderSize - kPointerSize)); | 5930 FixedArray::kHeaderSize - kPointerSize)); |
| 5894 __ bind(&done); | 5931 __ bind(&done); |
| 5895 } | 5932 } |
| 5896 | 5933 |
| 5897 | 5934 |
| 5898 #undef __ | 5935 #undef __ |
| 5899 | 5936 |
| 5900 } } // namespace v8::internal | 5937 } } // namespace v8::internal |
| 5901 | 5938 |
| 5902 #endif // V8_TARGET_ARCH_IA32 | 5939 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |