MIPS[64]: Fix register overwrite in ShiftPair instructions

This patch fixes register overwrite in ShrPair, ShlPair and SarPair
instructions. Additionally, we rename kLithiumScratch register
register since lithium is not present anymore.

Change-Id: I65861c4f27d2161bcf49cf02ca8987eb82c997ea
Reviewed-on: https://chromium-review.googlesource.com/1012110
Reviewed-by: Sreten Kovacevic <sreten.kovacevic@mips.com>
Commit-Queue: Sreten Kovacevic <sreten.kovacevic@mips.com>
Cr-Commit-Position: refs/heads/master@{#52593}
This commit is contained in:
Ivica Bogosavljevic 2018-04-13 16:50:56 +02:00 committed by Commit Bot
parent a86fa96813
commit fcb8061e98
10 changed files with 84 additions and 90 deletions

View File

@ -2663,7 +2663,7 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
Register scratch = GetRegisterThatIsNotOneOf(result_reg);
Register scratch2 = GetRegisterThatIsNotOneOf(result_reg, scratch);
Register scratch3 = GetRegisterThatIsNotOneOf(result_reg, scratch, scratch2);
DoubleRegister double_scratch = kLithiumScratchDouble;
DoubleRegister double_scratch = kScratchDoubleReg;
// Account for saved regs.
const int kArgumentOffset = 4 * kPointerSize;

View File

@ -2682,7 +2682,7 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
Register scratch = GetRegisterThatIsNotOneOf(result_reg);
Register scratch2 = GetRegisterThatIsNotOneOf(result_reg, scratch);
Register scratch3 = GetRegisterThatIsNotOneOf(result_reg, scratch, scratch2);
DoubleRegister double_scratch = kLithiumScratchDouble;
DoubleRegister double_scratch = kScratchDoubleReg;
// Account for saved regs.
const int kArgumentOffset = 4 * kPointerSize;

View File

@ -19,13 +19,6 @@ namespace compiler {
#define __ tasm()->
// TODO(plind): Possibly avoid using these lithium names.
#define kScratchReg kLithiumScratchReg
#define kCompareReg kLithiumScratchReg2
#define kScratchReg2 kLithiumScratchReg2
#define kScratchDoubleReg kLithiumScratchDouble
// TODO(plind): consider renaming these macros.
#define TRACE_MSG(msg) \
PrintF("code_gen: \'%s\' in function %s at line %d\n", msg, __FUNCTION__, \
@ -1037,11 +1030,12 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
instr->OutputCount() >= 2 ? i.OutputRegister(1) : i.TempRegister(0);
if (instr->InputAt(2)->IsRegister()) {
__ ShlPair(i.OutputRegister(0), second_output, i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2));
i.InputRegister(1), i.InputRegister(2), kScratchReg,
kScratchReg2);
} else {
uint32_t imm = i.InputOperand(2).immediate();
__ ShlPair(i.OutputRegister(0), second_output, i.InputRegister(0),
i.InputRegister(1), imm);
i.InputRegister(1), imm, kScratchReg);
}
} break;
case kMipsShrPair: {
@ -1049,11 +1043,12 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
instr->OutputCount() >= 2 ? i.OutputRegister(1) : i.TempRegister(0);
if (instr->InputAt(2)->IsRegister()) {
__ ShrPair(i.OutputRegister(0), second_output, i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2));
i.InputRegister(1), i.InputRegister(2), kScratchReg,
kScratchReg2);
} else {
uint32_t imm = i.InputOperand(2).immediate();
__ ShrPair(i.OutputRegister(0), second_output, i.InputRegister(0),
i.InputRegister(1), imm);
i.InputRegister(1), imm, kScratchReg);
}
} break;
case kMipsSarPair: {
@ -1061,11 +1056,12 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
instr->OutputCount() >= 2 ? i.OutputRegister(1) : i.TempRegister(0);
if (instr->InputAt(2)->IsRegister()) {
__ SarPair(i.OutputRegister(0), second_output, i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2));
i.InputRegister(1), i.InputRegister(2), kScratchReg,
kScratchReg2);
} else {
uint32_t imm = i.InputOperand(2).immediate();
__ SarPair(i.OutputRegister(0), second_output, i.InputRegister(0),
i.InputRegister(1), imm);
i.InputRegister(1), imm, kScratchReg);
}
} break;
case kMipsExt:
@ -3485,7 +3481,7 @@ void CodeGenerator::AssembleSwap(InstructionOperand* source,
} else if (source->IsStackSlot()) {
DCHECK(destination->IsStackSlot());
Register temp_0 = kScratchReg;
Register temp_1 = kCompareReg;
Register temp_1 = kScratchReg2;
MemOperand src = g.ToMemOperand(source);
MemOperand dst = g.ToMemOperand(destination);
__ lw(temp_0, src);

View File

@ -19,11 +19,6 @@ namespace compiler {
#define __ tasm()->
// TODO(plind): Possibly avoid using these lithium names.
#define kScratchReg kLithiumScratchReg
#define kScratchReg2 kLithiumScratchReg2
#define kScratchDoubleReg kLithiumScratchDouble
// TODO(plind): consider renaming these macros.
#define TRACE_MSG(msg) \

View File

@ -320,9 +320,9 @@ const Simd128Register no_msareg = Simd128Register::no_reg();
// cp is assumed to be a callee saved register.
constexpr Register kRootRegister = s6;
constexpr Register cp = s7;
constexpr Register kLithiumScratchReg = s3;
constexpr Register kLithiumScratchReg2 = s4;
constexpr DoubleRegister kLithiumScratchDouble = f30;
constexpr Register kScratchReg = s3;
constexpr Register kScratchReg2 = s4;
constexpr DoubleRegister kScratchDoubleReg = f30;
constexpr DoubleRegister kDoubleRegZero = f28;
// Used on mips32r6 for compare operations.
constexpr DoubleRegister kDoubleCompareReg = f26;

View File

@ -1443,33 +1443,33 @@ void TurboAssembler::SubPair(Register dst_low, Register dst_high,
void TurboAssembler::ShlPair(Register dst_low, Register dst_high,
Register src_low, Register src_high,
Register shift) {
Register shift, Register scratch1,
Register scratch2) {
BlockTrampolinePoolScope block_trampoline_pool(this);
Label done;
Register kScratchReg = s3;
Register kScratchReg2 = s4;
And(shift, shift, 0x3F);
sllv(dst_low, src_low, shift);
Nor(kScratchReg2, zero_reg, shift);
srl(kScratchReg, src_low, 1);
srlv(kScratchReg, kScratchReg, kScratchReg2);
sllv(dst_high, src_high, shift);
Or(dst_high, dst_high, kScratchReg);
And(kScratchReg, shift, 32);
Register scratch3 = t8;
And(scratch3, shift, 0x3F);
sllv(dst_low, src_low, scratch3);
Nor(scratch2, zero_reg, scratch3);
srl(scratch1, src_low, 1);
srlv(scratch1, scratch1, scratch2);
sllv(dst_high, src_high, scratch3);
Or(dst_high, dst_high, scratch1);
And(scratch1, scratch3, 32);
if (IsMipsArchVariant(kLoongson) || IsMipsArchVariant(kMips32r6)) {
Branch(&done, eq, kScratchReg, Operand(zero_reg));
Branch(&done, eq, scratch1, Operand(zero_reg));
mov(dst_high, dst_low);
mov(dst_low, zero_reg);
} else {
movn(dst_high, dst_low, kScratchReg);
movn(dst_low, zero_reg, kScratchReg);
movn(dst_high, dst_low, scratch1);
movn(dst_low, zero_reg, scratch1);
}
bind(&done);
}
void TurboAssembler::ShlPair(Register dst_low, Register dst_high,
Register src_low, Register src_high,
uint32_t shift) {
Register kScratchReg = s3;
uint32_t shift, Register scratch) {
shift = shift & 0x3F;
if (shift == 0) {
mov(dst_low, src_low);
@ -1482,8 +1482,8 @@ void TurboAssembler::ShlPair(Register dst_low, Register dst_high,
} else {
sll(dst_high, src_high, shift);
sll(dst_low, src_low, shift);
srl(kScratchReg, src_low, 32 - shift);
Or(dst_high, dst_high, kScratchReg);
srl(scratch, src_low, 32 - shift);
Or(dst_high, dst_high, scratch);
}
} else if (shift == 32) {
mov(dst_low, zero_reg);
@ -1497,33 +1497,33 @@ void TurboAssembler::ShlPair(Register dst_low, Register dst_high,
void TurboAssembler::ShrPair(Register dst_low, Register dst_high,
Register src_low, Register src_high,
Register shift) {
Register shift, Register scratch1,
Register scratch2) {
BlockTrampolinePoolScope block_trampoline_pool(this);
Label done;
Register kScratchReg = s3;
Register kScratchReg2 = s4;
And(shift, shift, 0x3F);
srlv(dst_high, src_high, shift);
Nor(kScratchReg2, zero_reg, shift);
sll(kScratchReg, src_high, 1);
sllv(kScratchReg, kScratchReg, kScratchReg2);
srlv(dst_low, src_low, shift);
Or(dst_low, dst_low, kScratchReg);
And(kScratchReg, shift, 32);
Register scratch3 = t8;
And(scratch3, shift, 0x3F);
srlv(dst_high, src_high, scratch3);
Nor(scratch2, zero_reg, scratch3);
sll(scratch1, src_high, 1);
sllv(scratch1, scratch1, scratch2);
srlv(dst_low, src_low, scratch3);
Or(dst_low, dst_low, scratch1);
And(scratch1, scratch3, 32);
if (IsMipsArchVariant(kLoongson) || IsMipsArchVariant(kMips32r6)) {
Branch(&done, eq, kScratchReg, Operand(zero_reg));
Branch(&done, eq, scratch1, Operand(zero_reg));
mov(dst_low, dst_high);
mov(dst_high, zero_reg);
} else {
movn(dst_low, dst_high, kScratchReg);
movn(dst_high, zero_reg, kScratchReg);
movn(dst_low, dst_high, scratch1);
movn(dst_high, zero_reg, scratch1);
}
bind(&done);
}
void TurboAssembler::ShrPair(Register dst_low, Register dst_high,
Register src_low, Register src_high,
uint32_t shift) {
Register kScratchReg = s3;
uint32_t shift, Register scratch) {
shift = shift & 0x3F;
if (shift == 0) {
mov(dst_low, src_low);
@ -1537,8 +1537,8 @@ void TurboAssembler::ShrPair(Register dst_low, Register dst_high,
srl(dst_high, src_high, shift);
srl(dst_low, src_low, shift);
shift = 32 - shift;
sll(kScratchReg, src_high, shift);
Or(dst_low, dst_low, kScratchReg);
sll(scratch, src_high, shift);
Or(dst_low, dst_low, scratch);
}
} else if (shift == 32) {
mov(dst_high, zero_reg);
@ -1552,19 +1552,20 @@ void TurboAssembler::ShrPair(Register dst_low, Register dst_high,
void TurboAssembler::SarPair(Register dst_low, Register dst_high,
Register src_low, Register src_high,
Register shift) {
Register shift, Register scratch1,
Register scratch2) {
BlockTrampolinePoolScope block_trampoline_pool(this);
Label done;
Register kScratchReg = s3;
Register kScratchReg2 = s4;
And(shift, shift, 0x3F);
srav(dst_high, src_high, shift);
Nor(kScratchReg2, zero_reg, shift);
sll(kScratchReg, src_high, 1);
sllv(kScratchReg, kScratchReg, kScratchReg2);
srlv(dst_low, src_low, shift);
Or(dst_low, dst_low, kScratchReg);
And(kScratchReg, shift, 32);
Branch(&done, eq, kScratchReg, Operand(zero_reg));
Register scratch3 = t8;
And(scratch3, shift, 0x3F);
srav(dst_high, src_high, scratch3);
Nor(scratch2, zero_reg, scratch3);
sll(scratch1, src_high, 1);
sllv(scratch1, scratch1, scratch2);
srlv(dst_low, src_low, scratch3);
Or(dst_low, dst_low, scratch1);
And(scratch1, scratch3, 32);
Branch(&done, eq, scratch1, Operand(zero_reg));
mov(dst_low, dst_high);
sra(dst_high, dst_high, 31);
bind(&done);
@ -1572,8 +1573,7 @@ void TurboAssembler::SarPair(Register dst_low, Register dst_high,
void TurboAssembler::SarPair(Register dst_low, Register dst_high,
Register src_low, Register src_high,
uint32_t shift) {
Register kScratchReg = s3;
uint32_t shift, Register scratch) {
shift = shift & 0x3F;
if (shift == 0) {
mov(dst_low, src_low);
@ -1587,8 +1587,8 @@ void TurboAssembler::SarPair(Register dst_low, Register dst_high,
sra(dst_high, src_high, shift);
srl(dst_low, src_low, shift);
shift = 32 - shift;
sll(kScratchReg, src_high, shift);
Or(dst_low, dst_low, kScratchReg);
sll(scratch, src_high, shift);
Or(dst_low, dst_low, scratch);
}
} else if (shift == 32) {
sra(dst_high, src_high, 31);
@ -2629,7 +2629,7 @@ void MacroAssembler::EmitFPUTruncate(FPURoundingMode rounding_mode,
void TurboAssembler::TryInlineTruncateDoubleToI(Register result,
DoubleRegister double_input,
Label* done) {
DoubleRegister single_scratch = kLithiumScratchDouble.low();
DoubleRegister single_scratch = kScratchDoubleReg.low();
UseScratchRegisterScope temps(this);
Register scratch = temps.Acquire();
Register scratch2 = t9;

View File

@ -584,22 +584,25 @@ class TurboAssembler : public Assembler {
Register left_high, Register right_low, Register right_high);
void ShlPair(Register dst_low, Register dst_high, Register src_low,
Register src_high, Register shift);
Register src_high, Register shift, Register scratch1,
Register scratch2);
void ShlPair(Register dst_low, Register dst_high, Register src_low,
Register src_high, uint32_t shift);
Register src_high, uint32_t shift, Register scratch);
void ShrPair(Register dst_low, Register dst_high, Register src_low,
Register src_high, Register shift);
Register src_high, Register shift, Register scratch1,
Register scratch2);
void ShrPair(Register dst_low, Register dst_high, Register src_low,
Register src_high, uint32_t shift);
Register src_high, uint32_t shift, Register scratch);
void SarPair(Register dst_low, Register dst_high, Register src_low,
Register src_high, Register shift);
Register src_high, Register shift, Register scratch1,
Register scratch2);
void SarPair(Register dst_low, Register dst_high, Register src_low,
Register src_high, uint32_t shift);
Register src_high, uint32_t shift, Register scratch);
// MIPS32 R2 instruction macro.
void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);

View File

@ -325,9 +325,9 @@ const Simd128Register no_msareg = Simd128Register::no_reg();
// cp is assumed to be a callee saved register.
constexpr Register kRootRegister = s6;
constexpr Register cp = s7;
constexpr Register kLithiumScratchReg = s3;
constexpr Register kLithiumScratchReg2 = s4;
constexpr DoubleRegister kLithiumScratchDouble = f30;
constexpr Register kScratchReg = s3;
constexpr Register kScratchReg2 = s4;
constexpr DoubleRegister kScratchDoubleReg = f30;
constexpr DoubleRegister kDoubleRegZero = f28;
// Used on mips64r6 for compare operations.
// We use the last non-callee saved odd register for N64 ABI

View File

@ -3145,7 +3145,7 @@ void MacroAssembler::EmitFPUTruncate(FPURoundingMode rounding_mode,
void TurboAssembler::TryInlineTruncateDoubleToI(Register result,
DoubleRegister double_input,
Label* done) {
DoubleRegister single_scratch = kLithiumScratchDouble.low();
DoubleRegister single_scratch = kScratchDoubleReg.low();
UseScratchRegisterScope temps(this);
Register scratch = temps.Acquire();
Register scratch2 = t9;

View File

@ -604,7 +604,7 @@ inline void Emit64BitShiftOperation(
LiftoffAssembler* assm, LiftoffRegister dst, LiftoffRegister src,
Register amount,
void (TurboAssembler::*emit_shift)(Register, Register, Register, Register,
Register),
Register, Register, Register),
LiftoffRegList pinned) {
Label move, done;
pinned.set(dst);
@ -621,14 +621,14 @@ inline void Emit64BitShiftOperation(
// Do the actual shift.
(assm->*emit_shift)(tmp.low_gp(), tmp.high_gp(), src.low_gp(),
src.high_gp(), amount);
src.high_gp(), amount, kScratchReg, kScratchReg2);
// Place result in destination register.
assm->TurboAssembler::Move(dst.high_gp(), tmp.high_gp());
assm->TurboAssembler::Move(dst.low_gp(), tmp.low_gp());
} else {
(assm->*emit_shift)(dst.low_gp(), dst.high_gp(), src.low_gp(),
src.high_gp(), amount);
src.high_gp(), amount, kScratchReg, kScratchReg2);
}
assm->TurboAssembler::Branch(&done);