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

Unified Diff: src/x64/macro-assembler-x64.cc

Issue 532003004: Generalized division via multiplication. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mips/macro-assembler-mips.cc ('k') | src/x87/macro-assembler-x87.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/x64/macro-assembler-x64.cc
diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc
index aee3e9efe5bce58957fa347b0947f25452edbaab..e8739e14f70642fd261e3595dec61aad0ff132b2 100644
--- a/src/x64/macro-assembler-x64.cc
+++ b/src/x64/macro-assembler-x64.cc
@@ -7,6 +7,7 @@
#if V8_TARGET_ARCH_X64
#include "src/base/bits.h"
+#include "src/base/division-by-constant.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/cpu-profiler.h"
@@ -5368,12 +5369,14 @@ void MacroAssembler::JumpIfDictionaryInPrototypeChain(
void MacroAssembler::TruncatingDiv(Register dividend, int32_t divisor) {
DCHECK(!dividend.is(rax));
DCHECK(!dividend.is(rdx));
- MultiplierAndShift ms(divisor);
- movl(rax, Immediate(ms.multiplier()));
+ base::MagicNumbersForDivision<uint32_t> mag =
+ base::SignedDivisionByConstant(static_cast<uint32_t>(divisor));
+ movl(rax, Immediate(mag.multiplier));
imull(dividend);
- if (divisor > 0 && ms.multiplier() < 0) addl(rdx, dividend);
- if (divisor < 0 && ms.multiplier() > 0) subl(rdx, dividend);
- if (ms.shift() > 0) sarl(rdx, Immediate(ms.shift()));
+ bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0;
+ if (divisor > 0 && neg) addl(rdx, dividend);
+ if (divisor < 0 && !neg && mag.multiplier > 0) subl(rdx, dividend);
+ if (mag.shift > 0) sarl(rdx, Immediate(mag.shift));
movl(rax, dividend);
shrl(rax, Immediate(31));
addl(rdx, rax);
« no previous file with comments | « src/mips/macro-assembler-mips.cc ('k') | src/x87/macro-assembler-x87.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698