Chromium Code Reviews

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

Issue 12052032: Improve integer division on ARM in favor of power of 2 constant divisor (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « src/arm/lithium-arm.cc ('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 1314 matching lines...)
1325 // This sequence could be replaced with 'mls' when 1325 // This sequence could be replaced with 'mls' when
1326 // it gets implemented. 1326 // it gets implemented.
1327 __ mul(scratch, result, ip); 1327 __ mul(scratch, result, ip);
1328 __ sub(remainder, dividend, scratch); 1328 __ sub(remainder, dividend, scratch);
1329 } 1329 }
1330 } 1330 }
1331 } 1331 }
1332 1332
1333 1333
1334 void LCodeGen::DoDivI(LDivI* instr) { 1334 void LCodeGen::DoDivI(LDivI* instr) {
1335 if (instr->hydrogen()->HasPowerOf2Divisor()) {
1336 Register dividend = ToRegister(instr->left());
1337 int32_t divisor =
1338 HConstant::cast(instr->hydrogen()->right())->Integer32Value();
1339 int32_t test_value = 0;
1340 int32_t power = 0;
1341
1342 if (divisor > 0) {
1343 test_value = divisor - 1;
1344 power = WhichPowerOf2(divisor);
1345 } else {
1346 // Check for (0 / -x) that will produce negative zero.
1347 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1348 __ tst(dividend, Operand(dividend));
1349 DeoptimizeIf(eq, instr->environment());
1350 }
1351 // Check for (kMinInt / -1).
1352 if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1353 __ cmp(dividend, Operand(kMinInt));
1354 DeoptimizeIf(eq, instr->environment());
1355 }
1356 test_value = - divisor - 1;
1357 power = WhichPowerOf2(-divisor);
1358 }
1359
1360 if (test_value != 0) {
1361 // Deoptimize if remainder is not 0.
1362 __ tst(dividend, Operand(test_value));
1363 DeoptimizeIf(ne, instr->environment());
1364 __ mov(dividend, Operand(dividend, ASR, power));
1365 }
1366 if (divisor < 0) __ rsb(dividend, dividend, Operand(0));
1367
1368 return;
1369 }
1370
1335 class DeferredDivI: public LDeferredCode { 1371 class DeferredDivI: public LDeferredCode {
ulan 2013/02/27 14:12:32 Please move this class up to the beginning of the
1336 public: 1372 public:
1337 DeferredDivI(LCodeGen* codegen, LDivI* instr) 1373 DeferredDivI(LCodeGen* codegen, LDivI* instr)
1338 : LDeferredCode(codegen), instr_(instr) { } 1374 : LDeferredCode(codegen), instr_(instr) { }
1339 virtual void Generate() { 1375 virtual void Generate() {
1340 codegen()->DoDeferredBinaryOpStub(instr_->pointer_map(), 1376 codegen()->DoDeferredBinaryOpStub(instr_->pointer_map(),
1341 instr_->left(), 1377 instr_->left(),
1342 instr_->right(), 1378 instr_->right(),
1343 Token::DIV); 1379 Token::DIV);
1344 } 1380 }
1345 virtual LInstruction* instr() { return instr_; } 1381 virtual LInstruction* instr() { return instr_; }
(...skipping 4755 matching lines...)
6101 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); 6137 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize));
6102 __ ldr(result, FieldMemOperand(scratch, 6138 __ ldr(result, FieldMemOperand(scratch,
6103 FixedArray::kHeaderSize - kPointerSize)); 6139 FixedArray::kHeaderSize - kPointerSize));
6104 __ bind(&done); 6140 __ bind(&done);
6105 } 6141 }
6106 6142
6107 6143
6108 #undef __ 6144 #undef __
6109 6145
6110 } } // namespace v8::internal 6146 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-arm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine