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

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

Issue 227583003: MIPS: Fixed flooring division by -1. (Closed) Base URL: https://github.com/v8/v8.git@gbl
Patch Set: Created 6 years, 8 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 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 } 1315 }
1316 1316
1317 // If the divisor is negative, we have to negate and handle edge cases. 1317 // If the divisor is negative, we have to negate and handle edge cases.
1318 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { 1318 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1319 __ Move(scratch, dividend); 1319 __ Move(scratch, dividend);
1320 } 1320 }
1321 __ Subu(result, zero_reg, dividend); 1321 __ Subu(result, zero_reg, dividend);
1322 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { 1322 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1323 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); 1323 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg));
1324 } 1324 }
1325 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { 1325
1326 // Note that we could emit branch-free code, but that would need one more 1326 // If the negation could not overflow, simply shifting is OK.
1327 // register. 1327 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1328 __ Xor(at, scratch, result);
1329 if (divisor == -1) {
1330 DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg));
1331 __ sra(result, dividend, shift);
1332 } else {
1333 Label no_overflow, done;
1334 __ Branch(&no_overflow, lt, at, Operand(zero_reg));
1335 __ li(result, Operand(kMinInt / divisor));
1336 __ Branch(&done);
1337 __ bind(&no_overflow);
1338 __ sra(result, dividend, shift);
1339 __ bind(&done);
1340 }
1341 } else {
1342 __ sra(result, dividend, shift); 1328 __ sra(result, dividend, shift);
1329 return;
1343 } 1330 }
1331
1332 // Dividing by -1 is basically negation, unless we overflow.
1333 __ Xor(at, scratch, result);
1334 if (divisor == -1) {
1335 DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg));
1336 return;
1337 }
1338
1339 Label no_overflow, done;
1340 __ Branch(&no_overflow, lt, at, Operand(zero_reg));
1341 __ li(result, Operand(kMinInt / divisor));
1342 __ Branch(&done);
1343 __ bind(&no_overflow);
1344 __ sra(result, dividend, shift);
1345 __ bind(&done);
1344 } 1346 }
1345 1347
1346 1348
1347 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { 1349 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
1348 Register dividend = ToRegister(instr->dividend()); 1350 Register dividend = ToRegister(instr->dividend());
1349 int32_t divisor = instr->divisor(); 1351 int32_t divisor = instr->divisor();
1350 Register result = ToRegister(instr->result()); 1352 Register result = ToRegister(instr->result());
1351 ASSERT(!dividend.is(result)); 1353 ASSERT(!dividend.is(result));
1352 1354
1353 if (divisor == 0) { 1355 if (divisor == 0) {
(...skipping 4552 matching lines...) Expand 10 before | Expand all | Expand 10 after
5906 __ lw(result, FieldMemOperand(scratch, 5908 __ lw(result, FieldMemOperand(scratch,
5907 FixedArray::kHeaderSize - kPointerSize)); 5909 FixedArray::kHeaderSize - kPointerSize));
5908 __ bind(deferred->exit()); 5910 __ bind(deferred->exit());
5909 __ bind(&done); 5911 __ bind(&done);
5910 } 5912 }
5911 5913
5912 5914
5913 #undef __ 5915 #undef __
5914 5916
5915 } } // namespace v8::internal 5917 } } // 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