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 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1254 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1255 instr->left()->RangeCanInclude(0) && divisor < 0) || | 1255 instr->left()->RangeCanInclude(0) && divisor < 0) || |
1256 (instr->CheckFlag(HValue::kCanOverflow) && | 1256 (instr->CheckFlag(HValue::kCanOverflow) && |
1257 instr->left()->RangeCanInclude(kMinInt) && divisor == -1) || | 1257 instr->left()->RangeCanInclude(kMinInt) && divisor == -1) || |
1258 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | 1258 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
1259 divisor != 1 && divisor != -1); | 1259 divisor != 1 && divisor != -1); |
1260 return can_deopt ? AssignEnvironment(result) : result; | 1260 return can_deopt ? AssignEnvironment(result) : result; |
1261 } | 1261 } |
1262 | 1262 |
1263 | 1263 |
| 1264 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) { |
| 1265 ASSERT(instr->representation().IsInteger32()); |
| 1266 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1267 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1268 LOperand* dividend = UseRegister(instr->left()); |
| 1269 int32_t divisor = instr->right()->GetInteger32Constant(); |
| 1270 LOperand* temp1 = FixedTemp(rax); |
| 1271 LOperand* temp2 = FixedTemp(rdx); |
| 1272 LInstruction* result = |
| 1273 DefineFixed( |
| 1274 new(zone()) LDivByConstI(dividend, divisor, temp1, temp2), rdx); |
| 1275 bool can_deopt = |
| 1276 divisor == 0 || |
| 1277 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1278 instr->left()->RangeCanInclude(0) && divisor < 0) || |
| 1279 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32); |
| 1280 return can_deopt ? AssignEnvironment(result) : result; |
| 1281 } |
| 1282 |
| 1283 |
1264 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { | 1284 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
1265 ASSERT(instr->representation().IsSmiOrInteger32()); | 1285 ASSERT(instr->representation().IsSmiOrInteger32()); |
1266 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1286 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1267 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1287 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1268 LOperand* dividend = UseFixed(instr->left(), rax); | 1288 LOperand* dividend = UseFixed(instr->left(), rax); |
1269 LOperand* divisor = UseRegister(instr->right()); | 1289 LOperand* divisor = UseRegister(instr->right()); |
1270 LOperand* temp = FixedTemp(rdx); | 1290 LOperand* temp = FixedTemp(rdx); |
1271 LInstruction* result = | 1291 LInstruction* result = |
1272 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), rax); | 1292 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), rax); |
1273 return AssignEnvironment(result); | 1293 return AssignEnvironment(result); |
1274 } | 1294 } |
1275 | 1295 |
1276 | 1296 |
1277 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | 1297 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
1278 if (instr->representation().IsSmiOrInteger32()) { | 1298 if (instr->representation().IsSmiOrInteger32()) { |
1279 return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); | 1299 if (instr->RightIsPowerOf2()) { |
| 1300 return DoDivByPowerOf2I(instr); |
| 1301 } else if (instr->right()->IsConstant()) { |
| 1302 return DoDivByConstI(instr); |
| 1303 } else { |
| 1304 return DoDivI(instr); |
| 1305 } |
1280 } else if (instr->representation().IsDouble()) { | 1306 } else if (instr->representation().IsDouble()) { |
1281 return DoArithmeticD(Token::DIV, instr); | 1307 return DoArithmeticD(Token::DIV, instr); |
1282 } else { | 1308 } else { |
1283 return DoArithmeticT(Token::DIV, instr); | 1309 return DoArithmeticT(Token::DIV, instr); |
1284 } | 1310 } |
1285 } | 1311 } |
1286 | 1312 |
1287 | 1313 |
1288 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { | 1314 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
1289 LOperand* dividend = UseRegisterAtStart(instr->left()); | 1315 LOperand* dividend = UseRegisterAtStart(instr->left()); |
1290 int32_t divisor = instr->right()->GetInteger32Constant(); | 1316 int32_t divisor = instr->right()->GetInteger32Constant(); |
1291 LInstruction* result = | 1317 LInstruction* result = |
1292 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); | 1318 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); |
1293 bool can_deopt = | 1319 bool can_deopt = |
1294 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || | 1320 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || |
1295 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); | 1321 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); |
1296 return can_deopt ? AssignEnvironment(result) : result; | 1322 return can_deopt ? AssignEnvironment(result) : result; |
1297 } | 1323 } |
1298 | 1324 |
1299 | 1325 |
1300 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { | 1326 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { |
1301 LOperand* dividend = UseRegisterAtStart(instr->left()); | 1327 ASSERT(instr->representation().IsInteger32()); |
| 1328 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1329 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1330 LOperand* dividend = UseRegister(instr->left()); |
1302 int32_t divisor = instr->right()->GetInteger32Constant(); | 1331 int32_t divisor = instr->right()->GetInteger32Constant(); |
1303 LOperand* temp = TempRegister(); | 1332 LOperand* temp1 = FixedTemp(rax); |
| 1333 LOperand* temp2 = FixedTemp(rdx); |
1304 LInstruction* result = | 1334 LInstruction* result = |
1305 DefineAsRegister( | 1335 DefineFixed(new(zone()) LFlooringDivByConstI(dividend, |
1306 new(zone()) LFlooringDivByConstI(dividend, divisor, temp)); | 1336 divisor, |
1307 bool can_deopt = divisor <= 0; | 1337 temp1, |
| 1338 temp2), |
| 1339 rdx); |
| 1340 bool can_deopt = |
| 1341 divisor == 0 || |
| 1342 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1343 instr->left()->RangeCanInclude(0) && divisor < 0); |
1308 return can_deopt ? AssignEnvironment(result) : result; | 1344 return can_deopt ? AssignEnvironment(result) : result; |
1309 } | 1345 } |
1310 | 1346 |
1311 | 1347 |
1312 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { | 1348 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
1313 if (instr->RightIsPowerOf2()) { | 1349 if (instr->RightIsPowerOf2()) { |
1314 return DoFlooringDivByPowerOf2I(instr); | 1350 return DoFlooringDivByPowerOf2I(instr); |
1315 } else if (instr->right()->IsConstant()) { | 1351 } else if (instr->right()->IsConstant()) { |
1316 return DoFlooringDivByConstI(instr); | 1352 return DoFlooringDivByConstI(instr); |
1317 } else { | 1353 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
1328 int32_t divisor = instr->right()->GetInteger32Constant(); | 1364 int32_t divisor = instr->right()->GetInteger32Constant(); |
1329 LInstruction* result = | 1365 LInstruction* result = |
1330 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); | 1366 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); |
1331 bool can_deopt = | 1367 bool can_deopt = |
1332 instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1368 instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1333 instr->left()->CanBeNegative(); | 1369 instr->left()->CanBeNegative(); |
1334 return can_deopt ? AssignEnvironment(result) : result; | 1370 return can_deopt ? AssignEnvironment(result) : result; |
1335 } | 1371 } |
1336 | 1372 |
1337 | 1373 |
| 1374 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) { |
| 1375 ASSERT(instr->representation().IsSmiOrInteger32()); |
| 1376 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1377 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1378 LOperand* dividend = UseRegister(instr->left()); |
| 1379 int32_t divisor = instr->right()->GetInteger32Constant(); |
| 1380 LOperand* temp1 = FixedTemp(rax); |
| 1381 LOperand* temp2 = FixedTemp(rdx); |
| 1382 LInstruction* result = |
| 1383 DefineFixed( |
| 1384 new(zone()) LModByConstI(dividend, divisor, temp1, temp2), rax); |
| 1385 bool can_deopt = |
| 1386 divisor == 0 || |
| 1387 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1388 instr->left()->CanBeNegative()); |
| 1389 return can_deopt ? AssignEnvironment(result) : result; |
| 1390 } |
| 1391 |
| 1392 |
1338 LInstruction* LChunkBuilder::DoModI(HMod* instr) { | 1393 LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
1339 ASSERT(instr->representation().IsSmiOrInteger32()); | 1394 ASSERT(instr->representation().IsSmiOrInteger32()); |
1340 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1395 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1341 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1396 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1342 LOperand* dividend = UseFixed(instr->left(), rax); | 1397 LOperand* dividend = UseFixed(instr->left(), rax); |
1343 LOperand* divisor = UseRegister(instr->right()); | 1398 LOperand* divisor = UseRegister(instr->right()); |
1344 LOperand* temp = FixedTemp(rdx); | 1399 LOperand* temp = FixedTemp(rdx); |
1345 LInstruction* result = | 1400 LInstruction* result = |
1346 DefineFixed(new(zone()) LModI(dividend, divisor, temp), rdx); | 1401 DefineFixed(new(zone()) LModI(dividend, divisor, temp), rdx); |
1347 bool can_deopt = (instr->right()->CanBeZero() || | 1402 bool can_deopt = (instr->right()->CanBeZero() || |
1348 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1403 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1349 instr->left()->RangeCanInclude(kMinInt) && | 1404 instr->left()->RangeCanInclude(kMinInt) && |
1350 instr->right()->RangeCanInclude(-1)) || | 1405 instr->right()->RangeCanInclude(-1)) || |
1351 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1406 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1352 instr->left()->CanBeNegative() && | 1407 instr->left()->CanBeNegative() && |
1353 instr->CanBeZero())); | 1408 instr->CanBeZero())); |
1354 return can_deopt ? AssignEnvironment(result) : result; | 1409 return can_deopt ? AssignEnvironment(result) : result; |
1355 } | 1410 } |
1356 | 1411 |
1357 | 1412 |
1358 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | 1413 LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
1359 if (instr->representation().IsSmiOrInteger32()) { | 1414 if (instr->representation().IsSmiOrInteger32()) { |
1360 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); | 1415 if (instr->RightIsPowerOf2()) { |
| 1416 return DoModByPowerOf2I(instr); |
| 1417 } else if (instr->right()->IsConstant()) { |
| 1418 return DoModByConstI(instr); |
| 1419 } else { |
| 1420 return DoModI(instr); |
| 1421 } |
1361 } else if (instr->representation().IsDouble()) { | 1422 } else if (instr->representation().IsDouble()) { |
1362 return DoArithmeticD(Token::MOD, instr); | 1423 return DoArithmeticD(Token::MOD, instr); |
1363 } else { | 1424 } else { |
1364 return DoArithmeticT(Token::MOD, instr); | 1425 return DoArithmeticT(Token::MOD, instr); |
1365 } | 1426 } |
1366 } | 1427 } |
1367 | 1428 |
1368 | 1429 |
1369 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1430 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1370 if (instr->representation().IsSmiOrInteger32()) { | 1431 if (instr->representation().IsSmiOrInteger32()) { |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2471 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2532 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2472 LOperand* object = UseRegister(instr->object()); | 2533 LOperand* object = UseRegister(instr->object()); |
2473 LOperand* index = UseTempRegister(instr->index()); | 2534 LOperand* index = UseTempRegister(instr->index()); |
2474 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); | 2535 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); |
2475 } | 2536 } |
2476 | 2537 |
2477 | 2538 |
2478 } } // namespace v8::internal | 2539 } } // namespace v8::internal |
2479 | 2540 |
2480 #endif // V8_TARGET_ARCH_X64 | 2541 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |