MIPS: Generalized division via multiplication.

Port r23730 (967b787)

Original commit message:
We can now compute the magic numbers for all combinations of 32bit and
64bit (un)signed multiplications.

BUG=
R=dusan.milosavljevic@imgtec.com

Review URL: https://codereview.chromium.org/540343002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23738 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
balazs.kilvady@imgtec.com 2014-09-05 14:29:45 +00:00
parent 7d160cd9f2
commit f2fdb8b263

View File

@ -8,6 +8,7 @@
#if V8_TARGET_ARCH_MIPS64
#include "src/base/division-by-constant.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/cpu-profiler.h"
@ -6090,16 +6091,18 @@ void MacroAssembler::TruncatingDiv(Register result,
DCHECK(!dividend.is(result));
DCHECK(!dividend.is(at));
DCHECK(!result.is(at));
MultiplierAndShift ms(divisor);
li(at, Operand(ms.multiplier()));
base::MagicNumbersForDivision<uint32_t> mag =
base::SignedDivisionByConstant(static_cast<uint32_t>(divisor));
li(at, Operand(mag.multiplier));
Mulh(result, dividend, Operand(at));
if (divisor > 0 && ms.multiplier() < 0) {
bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0;
if (divisor > 0 && neg) {
Addu(result, result, Operand(dividend));
}
if (divisor < 0 && ms.multiplier() > 0) {
if (divisor < 0 && !neg && mag.multiplier > 0) {
Subu(result, result, Operand(dividend));
}
if (ms.shift() > 0) sra(result, result, ms.shift());
if (mag.shift > 0) sra(result, result, mag.shift);
srl(at, dividend, 31);
Addu(result, result, Operand(at));
}