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 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1205 | 1205 |
1206 __ bind(&remainder_eq_dividend); | 1206 __ bind(&remainder_eq_dividend); |
1207 __ mov(result_reg, left_reg); | 1207 __ mov(result_reg, left_reg); |
1208 | 1208 |
1209 __ bind(&done); | 1209 __ bind(&done); |
1210 } | 1210 } |
1211 } | 1211 } |
1212 | 1212 |
1213 | 1213 |
1214 void LCodeGen::DoDivI(LDivI* instr) { | 1214 void LCodeGen::DoDivI(LDivI* instr) { |
1215 if (instr->hydrogen()->HasPowerOf2Divisor()) { | 1215 if (!instr->is_flooring() && instr->hydrogen()->HasPowerOf2Divisor()) { |
1216 Register dividend = ToRegister(instr->left()); | 1216 Register dividend = ToRegister(instr->left()); |
1217 int32_t divisor = | 1217 int32_t divisor = |
1218 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); | 1218 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
1219 int32_t test_value = 0; | 1219 int32_t test_value = 0; |
1220 int32_t power = 0; | 1220 int32_t power = 0; |
1221 | 1221 |
1222 if (divisor > 0) { | 1222 if (divisor > 0) { |
1223 test_value = divisor - 1; | 1223 test_value = divisor - 1; |
1224 power = WhichPowerOf2(divisor); | 1224 power = WhichPowerOf2(divisor); |
1225 } else { | 1225 } else { |
(...skipping 26 matching lines...) Expand all Loading... | |
1252 LOperand* right = instr->right(); | 1252 LOperand* right = instr->right(); |
1253 ASSERT(ToRegister(instr->result()).is(eax)); | 1253 ASSERT(ToRegister(instr->result()).is(eax)); |
1254 ASSERT(ToRegister(instr->left()).is(eax)); | 1254 ASSERT(ToRegister(instr->left()).is(eax)); |
1255 ASSERT(!ToRegister(instr->right()).is(eax)); | 1255 ASSERT(!ToRegister(instr->right()).is(eax)); |
1256 ASSERT(!ToRegister(instr->right()).is(edx)); | 1256 ASSERT(!ToRegister(instr->right()).is(edx)); |
1257 | 1257 |
1258 Register left_reg = eax; | 1258 Register left_reg = eax; |
1259 | 1259 |
1260 // Check for x / 0. | 1260 // Check for x / 0. |
1261 Register right_reg = ToRegister(right); | 1261 Register right_reg = ToRegister(right); |
1262 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | 1262 if (instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { |
1263 __ test(right_reg, ToOperand(right)); | 1263 __ test(right_reg, ToOperand(right)); |
1264 DeoptimizeIf(zero, instr->environment()); | 1264 DeoptimizeIf(zero, instr->environment()); |
1265 } | 1265 } |
1266 | 1266 |
1267 // Check for (0 / -x) that will produce negative zero. | 1267 // Check for (0 / -x) that will produce negative zero. |
1268 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1268 if (instr->hydrogen_value()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1269 Label left_not_zero; | 1269 Label left_not_zero; |
1270 __ test(left_reg, Operand(left_reg)); | 1270 __ test(left_reg, Operand(left_reg)); |
1271 __ j(not_zero, &left_not_zero, Label::kNear); | 1271 __ j(not_zero, &left_not_zero, Label::kNear); |
1272 __ test(right_reg, ToOperand(right)); | 1272 __ test(right_reg, ToOperand(right)); |
1273 DeoptimizeIf(sign, instr->environment()); | 1273 DeoptimizeIf(sign, instr->environment()); |
1274 __ bind(&left_not_zero); | 1274 __ bind(&left_not_zero); |
1275 } | 1275 } |
1276 | 1276 |
1277 // Check for (kMinInt / -1). | 1277 // Check for (kMinInt / -1). |
1278 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | 1278 if (instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)) { |
1279 Label left_not_min_int; | 1279 Label left_not_min_int; |
1280 __ cmp(left_reg, kMinInt); | 1280 __ cmp(left_reg, kMinInt); |
1281 __ j(not_zero, &left_not_min_int, Label::kNear); | 1281 __ j(not_zero, &left_not_min_int, Label::kNear); |
1282 __ cmp(right_reg, -1); | 1282 __ cmp(right_reg, -1); |
1283 DeoptimizeIf(zero, instr->environment()); | 1283 DeoptimizeIf(zero, instr->environment()); |
1284 __ bind(&left_not_min_int); | 1284 __ bind(&left_not_min_int); |
1285 } | 1285 } |
1286 | 1286 |
1287 // Sign extend to edx. | 1287 // Sign extend to edx. |
1288 __ cdq(); | 1288 __ cdq(); |
1289 __ idiv(right_reg); | 1289 __ idiv(right_reg); |
1290 | 1290 |
1291 // Deoptimize if remainder is not 0. | 1291 if (!instr->is_flooring()) { |
1292 __ test(edx, Operand(edx)); | 1292 // Deoptimize if remainder is not 0. |
1293 DeoptimizeIf(not_zero, instr->environment()); | 1293 __ test(edx, Operand(edx)); |
1294 DeoptimizeIf(not_zero, instr->environment()); | |
1295 } else { | |
1296 Label done; | |
Yang
2012/12/27 14:41:53
Tests, especially targetting this code path, would
| |
1297 __ test(edx, edx); | |
1298 __ j(zero, &done, Label::kNear); | |
1299 __ xor_(edx, right_reg); | |
1300 __ sar(edx, 31); | |
1301 __ add(eax, edx); | |
1302 __ bind(&done); | |
1303 } | |
1294 } | 1304 } |
1295 | 1305 |
1296 | 1306 |
1297 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { | 1307 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
1298 ASSERT(instr->right()->IsConstantOperand()); | 1308 ASSERT(instr->right()->IsConstantOperand()); |
1299 | 1309 |
1300 Register dividend = ToRegister(instr->left()); | 1310 Register dividend = ToRegister(instr->left()); |
1301 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); | 1311 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
1302 Register result = ToRegister(instr->result()); | 1312 Register result = ToRegister(instr->result()); |
1303 | 1313 |
(...skipping 4637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5941 FixedArray::kHeaderSize - kPointerSize)); | 5951 FixedArray::kHeaderSize - kPointerSize)); |
5942 __ bind(&done); | 5952 __ bind(&done); |
5943 } | 5953 } |
5944 | 5954 |
5945 | 5955 |
5946 #undef __ | 5956 #undef __ |
5947 | 5957 |
5948 } } // namespace v8::internal | 5958 } } // namespace v8::internal |
5949 | 5959 |
5950 #endif // V8_TARGET_ARCH_IA32 | 5960 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |