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 | |
1284 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { | 1264 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
1285 ASSERT(instr->representation().IsSmiOrInteger32()); | 1265 ASSERT(instr->representation().IsSmiOrInteger32()); |
1286 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1266 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1287 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1267 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1288 LOperand* dividend = UseFixed(instr->left(), rax); | 1268 LOperand* dividend = UseFixed(instr->left(), rax); |
1289 LOperand* divisor = UseRegister(instr->right()); | 1269 LOperand* divisor = UseRegister(instr->right()); |
1290 LOperand* temp = FixedTemp(rdx); | 1270 LOperand* temp = FixedTemp(rdx); |
1291 LInstruction* result = | 1271 LInstruction* result = |
1292 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), rax); | 1272 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), rax); |
1293 return AssignEnvironment(result); | 1273 return AssignEnvironment(result); |
1294 } | 1274 } |
1295 | 1275 |
1296 | 1276 |
1297 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | 1277 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
1298 if (instr->representation().IsSmiOrInteger32()) { | 1278 if (instr->representation().IsSmiOrInteger32()) { |
1299 if (instr->RightIsPowerOf2()) { | 1279 return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); |
1300 return DoDivByPowerOf2I(instr); | |
1301 } else if (instr->right()->IsConstant()) { | |
1302 return DoDivByConstI(instr); | |
1303 } else { | |
1304 return DoDivI(instr); | |
1305 } | |
1306 } else if (instr->representation().IsDouble()) { | 1280 } else if (instr->representation().IsDouble()) { |
1307 return DoArithmeticD(Token::DIV, instr); | 1281 return DoArithmeticD(Token::DIV, instr); |
1308 } else { | 1282 } else { |
1309 return DoArithmeticT(Token::DIV, instr); | 1283 return DoArithmeticT(Token::DIV, instr); |
1310 } | 1284 } |
1311 } | 1285 } |
1312 | 1286 |
1313 | 1287 |
1314 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { | 1288 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
1315 LOperand* dividend = UseRegisterAtStart(instr->left()); | 1289 LOperand* dividend = UseRegisterAtStart(instr->left()); |
1316 int32_t divisor = instr->right()->GetInteger32Constant(); | 1290 int32_t divisor = instr->right()->GetInteger32Constant(); |
1317 LInstruction* result = | 1291 LInstruction* result = |
1318 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); | 1292 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); |
1319 bool can_deopt = | 1293 bool can_deopt = |
1320 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || | 1294 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || |
1321 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); | 1295 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); |
1322 return can_deopt ? AssignEnvironment(result) : result; | 1296 return can_deopt ? AssignEnvironment(result) : result; |
1323 } | 1297 } |
1324 | 1298 |
1325 | 1299 |
1326 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { | 1300 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { |
1327 ASSERT(instr->representation().IsInteger32()); | 1301 LOperand* dividend = UseRegisterAtStart(instr->left()); |
1328 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
1329 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
1330 LOperand* dividend = UseRegister(instr->left()); | |
1331 int32_t divisor = instr->right()->GetInteger32Constant(); | 1302 int32_t divisor = instr->right()->GetInteger32Constant(); |
1332 LOperand* temp1 = FixedTemp(rax); | 1303 LOperand* temp = TempRegister(); |
1333 LOperand* temp2 = FixedTemp(rdx); | |
1334 LInstruction* result = | 1304 LInstruction* result = |
1335 DefineFixed(new(zone()) LFlooringDivByConstI(dividend, | 1305 DefineAsRegister( |
1336 divisor, | 1306 new(zone()) LFlooringDivByConstI(dividend, divisor, temp)); |
1337 temp1, | 1307 bool can_deopt = divisor <= 0; |
1338 temp2), | |
1339 rdx); | |
1340 bool can_deopt = | |
1341 divisor == 0 || | |
1342 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | |
1343 instr->left()->RangeCanInclude(0) && divisor < 0); | |
1344 return can_deopt ? AssignEnvironment(result) : result; | 1308 return can_deopt ? AssignEnvironment(result) : result; |
1345 } | 1309 } |
1346 | 1310 |
1347 | 1311 |
1348 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { | 1312 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
1349 if (instr->RightIsPowerOf2()) { | 1313 if (instr->RightIsPowerOf2()) { |
1350 return DoFlooringDivByPowerOf2I(instr); | 1314 return DoFlooringDivByPowerOf2I(instr); |
1351 } else if (instr->right()->IsConstant()) { | 1315 } else if (instr->right()->IsConstant()) { |
1352 return DoFlooringDivByConstI(instr); | 1316 return DoFlooringDivByConstI(instr); |
1353 } else { | 1317 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
1364 int32_t divisor = instr->right()->GetInteger32Constant(); | 1328 int32_t divisor = instr->right()->GetInteger32Constant(); |
1365 LInstruction* result = | 1329 LInstruction* result = |
1366 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); | 1330 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); |
1367 bool can_deopt = | 1331 bool can_deopt = |
1368 instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1332 instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1369 instr->left()->CanBeNegative(); | 1333 instr->left()->CanBeNegative(); |
1370 return can_deopt ? AssignEnvironment(result) : result; | 1334 return can_deopt ? AssignEnvironment(result) : result; |
1371 } | 1335 } |
1372 | 1336 |
1373 | 1337 |
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 | |
1393 LInstruction* LChunkBuilder::DoModI(HMod* instr) { | 1338 LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
1394 ASSERT(instr->representation().IsSmiOrInteger32()); | 1339 ASSERT(instr->representation().IsSmiOrInteger32()); |
1395 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1340 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1396 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1341 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1397 LOperand* dividend = UseFixed(instr->left(), rax); | 1342 LOperand* dividend = UseFixed(instr->left(), rax); |
1398 LOperand* divisor = UseRegister(instr->right()); | 1343 LOperand* divisor = UseRegister(instr->right()); |
1399 LOperand* temp = FixedTemp(rdx); | 1344 LOperand* temp = FixedTemp(rdx); |
1400 LInstruction* result = | 1345 LInstruction* result = |
1401 DefineFixed(new(zone()) LModI(dividend, divisor, temp), rdx); | 1346 DefineFixed(new(zone()) LModI(dividend, divisor, temp), rdx); |
1402 bool can_deopt = (instr->right()->CanBeZero() || | 1347 bool can_deopt = (instr->right()->CanBeZero() || |
1403 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1348 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1404 instr->left()->RangeCanInclude(kMinInt) && | 1349 instr->left()->RangeCanInclude(kMinInt) && |
1405 instr->right()->RangeCanInclude(-1)) || | 1350 instr->right()->RangeCanInclude(-1)) || |
1406 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1351 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
1407 instr->left()->CanBeNegative() && | 1352 instr->left()->CanBeNegative() && |
1408 instr->CanBeZero())); | 1353 instr->CanBeZero())); |
1409 return can_deopt ? AssignEnvironment(result) : result; | 1354 return can_deopt ? AssignEnvironment(result) : result; |
1410 } | 1355 } |
1411 | 1356 |
1412 | 1357 |
1413 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | 1358 LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
1414 if (instr->representation().IsSmiOrInteger32()) { | 1359 if (instr->representation().IsSmiOrInteger32()) { |
1415 if (instr->RightIsPowerOf2()) { | 1360 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); |
1416 return DoModByPowerOf2I(instr); | |
1417 } else if (instr->right()->IsConstant()) { | |
1418 return DoModByConstI(instr); | |
1419 } else { | |
1420 return DoModI(instr); | |
1421 } | |
1422 } else if (instr->representation().IsDouble()) { | 1361 } else if (instr->representation().IsDouble()) { |
1423 return DoArithmeticD(Token::MOD, instr); | 1362 return DoArithmeticD(Token::MOD, instr); |
1424 } else { | 1363 } else { |
1425 return DoArithmeticT(Token::MOD, instr); | 1364 return DoArithmeticT(Token::MOD, instr); |
1426 } | 1365 } |
1427 } | 1366 } |
1428 | 1367 |
1429 | 1368 |
1430 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1369 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1431 if (instr->representation().IsSmiOrInteger32()) { | 1370 if (instr->representation().IsSmiOrInteger32()) { |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2518 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2457 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2519 LOperand* object = UseRegister(instr->object()); | 2458 LOperand* object = UseRegister(instr->object()); |
2520 LOperand* index = UseTempRegister(instr->index()); | 2459 LOperand* index = UseTempRegister(instr->index()); |
2521 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); | 2460 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); |
2522 } | 2461 } |
2523 | 2462 |
2524 | 2463 |
2525 } } // namespace v8::internal | 2464 } } // namespace v8::internal |
2526 | 2465 |
2527 #endif // V8_TARGET_ARCH_X64 | 2466 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |