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

Side by Side Diff: src/mips/lithium-codegen-mips.cc

Issue 322403006: MIPS: Fixed flooring division by a power of 2, once again... (Closed) Base URL: https://github.com/v8/v8.git@gbl
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | 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.7 1 // Copyright 2012 the V8 project authors. All rights reserved.7
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 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 ASSERT(addend.is(ToDoubleRegister(instr->result()))); 1302 ASSERT(addend.is(ToDoubleRegister(instr->result())));
1303 1303
1304 __ madd_d(addend, addend, multiplier, multiplicand); 1304 __ madd_d(addend, addend, multiplier, multiplicand);
1305 } 1305 }
1306 1306
1307 1307
1308 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { 1308 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
1309 Register dividend = ToRegister(instr->dividend()); 1309 Register dividend = ToRegister(instr->dividend());
1310 Register result = ToRegister(instr->result()); 1310 Register result = ToRegister(instr->result());
1311 int32_t divisor = instr->divisor(); 1311 int32_t divisor = instr->divisor();
1312 Register scratch = scratch0(); 1312 Register scratch = result.is(dividend) ? scratch0() : dividend;
1313 ASSERT(!scratch.is(dividend)); 1313 ASSERT(!result.is(dividend) || !scratch.is(dividend));
1314 1314
1315 // If the divisor is 1, return the dividend. 1315 // If the divisor is 1, return the dividend.
1316 if (divisor == 1) { 1316 if (divisor == 1) {
1317 __ Move(result, dividend); 1317 __ Move(result, dividend);
1318 return; 1318 return;
1319 } 1319 }
1320 1320
1321 // If the divisor is positive, things are easy: There can be no deopts and we 1321 // If the divisor is positive, things are easy: There can be no deopts and we
1322 // can simply do an arithmetic right shift. 1322 // can simply do an arithmetic right shift.
1323 uint16_t shift = WhichPowerOf2Abs(divisor); 1323 uint16_t shift = WhichPowerOf2Abs(divisor);
1324 if (divisor > 1) { 1324 if (divisor > 1) {
1325 __ sra(result, dividend, shift); 1325 __ sra(result, dividend, shift);
1326 return; 1326 return;
1327 } 1327 }
1328 1328
1329 // If the divisor is negative, we have to negate and handle edge cases. 1329 // If the divisor is negative, we have to negate and handle edge cases.
1330 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { 1330 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1331 // divident can be the same register as result so save the value of it
1332 // for checking overflow.
1331 __ Move(scratch, dividend); 1333 __ Move(scratch, dividend);
1332 } 1334 }
1333 __ Subu(result, zero_reg, dividend); 1335 __ Subu(result, zero_reg, dividend);
1334 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { 1336 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1335 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); 1337 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg));
1336 } 1338 }
1337 1339
1338 // If the negation could not overflow, simply shifting is OK.
1339 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1340 __ sra(result, dividend, shift);
1341 return;
1342 }
1343
1344 // Dividing by -1 is basically negation, unless we overflow. 1340 // Dividing by -1 is basically negation, unless we overflow.
1345 __ Xor(at, scratch, result); 1341 __ Xor(at, scratch, result);
1346 if (divisor == -1) { 1342 if (divisor == -1) {
1347 DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg)); 1343 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1344 DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg));
1345 }
1348 return; 1346 return;
1349 } 1347 }
1350 1348
1349 // If the negation could not overflow, simply shifting is OK.
1350 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1351 __ sra(result, result, shift);
1352 return;
1353 }
1354
1351 Label no_overflow, done; 1355 Label no_overflow, done;
1352 __ Branch(&no_overflow, lt, at, Operand(zero_reg)); 1356 __ Branch(&no_overflow, lt, at, Operand(zero_reg));
1353 __ li(result, Operand(kMinInt / divisor)); 1357 __ li(result, Operand(kMinInt / divisor));
1354 __ Branch(&done); 1358 __ Branch(&done);
1355 __ bind(&no_overflow); 1359 __ bind(&no_overflow);
1356 __ sra(result, dividend, shift); 1360 __ sra(result, result, shift);
1357 __ bind(&done); 1361 __ bind(&done);
1358 } 1362 }
1359 1363
1360 1364
1361 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { 1365 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
1362 Register dividend = ToRegister(instr->dividend()); 1366 Register dividend = ToRegister(instr->dividend());
1363 int32_t divisor = instr->divisor(); 1367 int32_t divisor = instr->divisor();
1364 Register result = ToRegister(instr->result()); 1368 Register result = ToRegister(instr->result());
1365 ASSERT(!dividend.is(result)); 1369 ASSERT(!dividend.is(result));
1366 1370
(...skipping 4520 matching lines...) Expand 10 before | Expand all | Expand 10 after
5887 __ li(at, scope_info); 5891 __ li(at, scope_info);
5888 __ Push(at, ToRegister(instr->function())); 5892 __ Push(at, ToRegister(instr->function()));
5889 CallRuntime(Runtime::kHiddenPushBlockContext, 2, instr); 5893 CallRuntime(Runtime::kHiddenPushBlockContext, 2, instr);
5890 RecordSafepoint(Safepoint::kNoLazyDeopt); 5894 RecordSafepoint(Safepoint::kNoLazyDeopt);
5891 } 5895 }
5892 5896
5893 5897
5894 #undef __ 5898 #undef __
5895 5899
5896 } } // namespace v8::internal 5900 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698