Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: src/x64/lithium-x64.cc

Issue 175143002: Consistenly handle power-of-2 divisors in division-like operations (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/lithium-x64.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 1235
1236 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); 1236 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1237 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); 1237 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1238 return DefineSameAsFirst(new(zone()) LBitI(left, right)); 1238 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1239 } else { 1239 } else {
1240 return DoArithmeticT(instr->op(), instr); 1240 return DoArithmeticT(instr->op(), instr);
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 1244
1245 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1246 ASSERT(instr->representation().IsSmiOrInteger32());
1247 ASSERT(instr->left()->representation().Equals(instr->representation()));
1248 ASSERT(instr->right()->representation().Equals(instr->representation()));
1249 LOperand* dividend = UseRegister(instr->left());
1250 int32_t divisor = instr->right()->GetInteger32Constant();
1251 LInstruction* result =
1252 DefineAsRegister(new(zone()) LDivByPowerOf2I(dividend, divisor));
1253 bool can_deopt =
1254 (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1255 instr->left()->RangeCanInclude(0) && divisor < 0) ||
1256 (instr->CheckFlag(HValue::kCanOverflow) &&
1257 instr->left()->RangeCanInclude(kMinInt) && divisor == -1) ||
1258 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1259 divisor != 1 && divisor != -1);
1260 return can_deopt ? AssignEnvironment(result) : result;
1261 }
1262
1263
1264 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) {
1265 ASSERT(instr->representation().IsSmiOrInteger32());
1266 ASSERT(instr->left()->representation().Equals(instr->representation()));
1267 ASSERT(instr->right()->representation().Equals(instr->representation()));
1268 LOperand* dividend = UseFixed(instr->left(), rax);
1269 LOperand* divisor = UseRegister(instr->right());
1270 LOperand* temp = FixedTemp(rdx);
1271 LInstruction* result =
1272 DefineFixed(new(zone()) LDivI(dividend, divisor, temp), rax);
1273 return AssignEnvironment(result);
1274 }
1275
1276
1245 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { 1277 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1246 if (instr->representation().IsSmiOrInteger32()) { 1278 if (instr->representation().IsSmiOrInteger32()) {
1247 ASSERT(instr->left()->representation().Equals(instr->representation())); 1279 return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr);
1248 ASSERT(instr->right()->representation().Equals(instr->representation()));
1249 if (instr->RightIsPowerOf2()) {
1250 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
1251 LOperand* value = UseRegister(instr->left());
1252 LDivI* div =
1253 new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL);
1254 return AssignEnvironment(DefineAsRegister(div));
1255 }
1256 // The temporary operand is necessary to ensure that right is not allocated
1257 // into rdx.
1258 LOperand* temp = FixedTemp(rdx);
1259 LOperand* dividend = UseFixed(instr->left(), rax);
1260 LOperand* divisor = UseRegister(instr->right());
1261 LDivI* result = new(zone()) LDivI(dividend, divisor, temp);
1262 return AssignEnvironment(DefineFixed(result, rax));
1263 } else if (instr->representation().IsDouble()) { 1280 } else if (instr->representation().IsDouble()) {
1264 return DoArithmeticD(Token::DIV, instr); 1281 return DoArithmeticD(Token::DIV, instr);
1265 } else { 1282 } else {
1266 return DoArithmeticT(Token::DIV, instr); 1283 return DoArithmeticT(Token::DIV, instr);
1267 } 1284 }
1268 } 1285 }
1269 1286
1270 1287
1288 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1289 LOperand* dividend = UseRegisterAtStart(instr->left());
1290 int32_t divisor = instr->right()->GetInteger32Constant();
1291 LInstruction* result =
1292 DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
1293 bool can_deopt =
1294 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1295 (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
1296 return can_deopt ? AssignEnvironment(result) : result;
1297 }
1298
1299
1300 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1301 LOperand* dividend = UseRegisterAtStart(instr->left());
1302 int32_t divisor = instr->right()->GetInteger32Constant();
1303 LOperand* temp = TempRegister();
1304 LInstruction* result =
1305 DefineAsRegister(
1306 new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
1307 bool can_deopt = divisor <= 0;
1308 return can_deopt ? AssignEnvironment(result) : result;
1309 }
1310
1311
1271 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { 1312 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1272 HValue* right = instr->right(); 1313 if (instr->RightIsPowerOf2()) {
1273 if (!right->IsConstant()) { 1314 return DoFlooringDivByPowerOf2I(instr);
1274 ASSERT(right->representation().IsInteger32()); 1315 } else if (instr->right()->IsConstant()) {
1275 // The temporary operand is necessary to ensure that right is not allocated 1316 return DoFlooringDivByConstI(instr);
1276 // into rdx.
1277 LOperand* temp = FixedTemp(rdx);
1278 LOperand* dividend = UseFixed(instr->left(), rax);
1279 LOperand* divisor = UseRegister(instr->right());
1280 LDivI* flooring_div = new(zone()) LDivI(dividend, divisor, temp);
1281 return AssignEnvironment(DefineFixed(flooring_div, rax));
1282 }
1283
1284 ASSERT(right->IsConstant() && HConstant::cast(right)->HasInteger32Value());
1285 LOperand* divisor = chunk_->DefineConstantOperand(HConstant::cast(right));
1286 int32_t divisor_si = HConstant::cast(right)->Integer32Value();
1287 if (divisor_si == 0) {
1288 LOperand* dividend = UseRegister(instr->left());
1289 return AssignEnvironment(DefineAsRegister(
1290 new(zone()) LMathFloorOfDiv(dividend, divisor, NULL)));
1291 } else if (IsPowerOf2(abs(divisor_si))) {
1292 LOperand* dividend = UseRegisterAtStart(instr->left());
1293 LInstruction* result = DefineAsRegister(
1294 new(zone()) LMathFloorOfDiv(dividend, divisor, NULL));
1295 return divisor_si < 0 ? AssignEnvironment(result) : result;
1296 } else { 1317 } else {
1297 // use two r64 1318 return DoDivI(instr);
1298 LOperand* dividend = UseRegisterAtStart(instr->left());
1299 LOperand* temp = TempRegister();
1300 LInstruction* result = DefineAsRegister(
1301 new(zone()) LMathFloorOfDiv(dividend, divisor, temp));
1302 return divisor_si < 0 ? AssignEnvironment(result) : result;
1303 } 1319 }
1304 } 1320 }
1305 1321
1306 1322
1323 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1324 ASSERT(instr->representation().IsSmiOrInteger32());
1325 ASSERT(instr->left()->representation().Equals(instr->representation()));
1326 ASSERT(instr->right()->representation().Equals(instr->representation()));
1327 LOperand* dividend = UseRegisterAtStart(instr->left());
1328 int32_t divisor = instr->right()->GetInteger32Constant();
1329 LInstruction* result =
1330 DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor));
1331 bool can_deopt =
1332 instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1333 instr->left()->CanBeNegative();
1334 return can_deopt ? AssignEnvironment(result) : result;
1335 }
1336
1337
1338 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1339 ASSERT(instr->representation().IsSmiOrInteger32());
1340 ASSERT(instr->left()->representation().Equals(instr->representation()));
1341 ASSERT(instr->right()->representation().Equals(instr->representation()));
1342 LOperand* dividend = UseFixed(instr->left(), rax);
1343 LOperand* divisor = UseRegister(instr->right());
1344 LOperand* temp = FixedTemp(rdx);
1345 LInstruction* result =
1346 DefineFixed(new(zone()) LModI(dividend, divisor, temp), rdx);
1347 bool can_deopt = (instr->right()->CanBeZero() ||
1348 (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1349 instr->left()->RangeCanInclude(kMinInt) &&
1350 instr->right()->RangeCanInclude(-1)) ||
1351 (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1352 instr->left()->CanBeNegative() &&
1353 instr->CanBeZero()));
1354 return can_deopt ? AssignEnvironment(result) : result;
1355 }
1356
1357
1307 LInstruction* LChunkBuilder::DoMod(HMod* instr) { 1358 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1308 HValue* left = instr->left();
1309 HValue* right = instr->right();
1310 if (instr->representation().IsSmiOrInteger32()) { 1359 if (instr->representation().IsSmiOrInteger32()) {
1311 ASSERT(left->representation().Equals(instr->representation())); 1360 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr);
1312 ASSERT(right->representation().Equals(instr->representation()));
1313 if (instr->RightIsPowerOf2()) {
1314 ASSERT(!right->CanBeZero());
1315 LModI* mod = new(zone()) LModI(UseRegisterAtStart(left),
1316 UseOrConstant(right),
1317 NULL);
1318 LInstruction* result = DefineSameAsFirst(mod);
1319 return (left->CanBeNegative() &&
1320 instr->CheckFlag(HValue::kBailoutOnMinusZero))
1321 ? AssignEnvironment(result)
1322 : result;
1323 } else {
1324 // The temporary operand is necessary to ensure that right is not
1325 // allocated into edx.
1326 LModI* mod = new(zone()) LModI(UseFixed(left, rax),
1327 UseRegister(right),
1328 FixedTemp(rdx));
1329 LInstruction* result = DefineFixed(mod, rdx);
1330 return (right->CanBeZero() ||
1331 (left->RangeCanInclude(kMinInt) &&
1332 right->RangeCanInclude(-1) &&
1333 instr->CheckFlag(HValue::kBailoutOnMinusZero)) ||
1334 (left->CanBeNegative() &&
1335 instr->CanBeZero() &&
1336 instr->CheckFlag(HValue::kBailoutOnMinusZero)))
1337 ? AssignEnvironment(result)
1338 : result;
1339 }
1340 } else if (instr->representation().IsDouble()) { 1361 } else if (instr->representation().IsDouble()) {
1341 return DoArithmeticD(Token::MOD, instr); 1362 return DoArithmeticD(Token::MOD, instr);
1342 } else { 1363 } else {
1343 return DoArithmeticT(Token::MOD, instr); 1364 return DoArithmeticT(Token::MOD, instr);
1344 } 1365 }
1345 } 1366 }
1346 1367
1347 1368
1348 LInstruction* LChunkBuilder::DoMul(HMul* instr) { 1369 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1349 if (instr->representation().IsSmiOrInteger32()) { 1370 if (instr->representation().IsSmiOrInteger32()) {
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { 2457 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2437 LOperand* object = UseRegister(instr->object()); 2458 LOperand* object = UseRegister(instr->object());
2438 LOperand* index = UseTempRegister(instr->index()); 2459 LOperand* index = UseTempRegister(instr->index());
2439 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); 2460 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index));
2440 } 2461 }
2441 2462
2442 2463
2443 } } // namespace v8::internal 2464 } } // namespace v8::internal
2444 2465
2445 #endif // V8_TARGET_ARCH_X64 2466 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/lithium-x64.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698