Commit a5f5f580 authored by Ilija.Pavlovic's avatar Ilija.Pavlovic Committed by Commit bot

MIPS: Fix simulator data trace for DSLL and BAL/BGEZAL.

In simulator data trace, DSLL did not print result and
BAL/BGEZAL omitted result from an instruction executed
in delay slot.

TEST=cctest/test-assembler-mips[64]
BUG=

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

Cr-Commit-Position: refs/heads/master@{#29796}
parent 0eacd754
...@@ -1346,9 +1346,13 @@ void Decoder::DecodeTypeImmediate(Instruction* instr) { ...@@ -1346,9 +1346,13 @@ void Decoder::DecodeTypeImmediate(Instruction* instr) {
case BGEZ: case BGEZ:
Format(instr, "bgez 'rs, 'imm16u -> 'imm16p4s2"); Format(instr, "bgez 'rs, 'imm16u -> 'imm16p4s2");
break; break;
case BGEZAL: case BGEZAL: {
Format(instr, "bgezal 'rs, 'imm16u -> 'imm16p4s2"); if (instr->RsValue() == 0)
Format(instr, "bal 'imm16s -> 'imm16p4s2");
else
Format(instr, "bgezal 'rs, 'imm16u -> 'imm16p4s2");
break; break;
}
case BGEZALL: case BGEZALL:
Format(instr, "bgezall 'rs, 'imm16u -> 'imm16p4s2"); Format(instr, "bgezall 'rs, 'imm16u -> 'imm16p4s2");
break; break;
......
...@@ -378,6 +378,7 @@ class Simulator { ...@@ -378,6 +378,7 @@ class Simulator {
instr->OpcodeValue()); instr->OpcodeValue());
} }
InstructionDecode(instr); InstructionDecode(instr);
SNPrintF(trace_buf_, " ");
} }
// ICache. // ICache.
......
...@@ -1510,9 +1510,13 @@ void Decoder::DecodeTypeImmediateREGIMM(Instruction* instr) { ...@@ -1510,9 +1510,13 @@ void Decoder::DecodeTypeImmediateREGIMM(Instruction* instr) {
case BGEZ: case BGEZ:
Format(instr, "bgez 'rs, 'imm16u -> 'imm16p4s2"); Format(instr, "bgez 'rs, 'imm16u -> 'imm16p4s2");
break; break;
case BGEZAL: case BGEZAL: {
Format(instr, "bgezal 'rs, 'imm16u -> 'imm16p4s2"); if (instr->RsValue() == 0)
Format(instr, "bal 'imm16s -> 'imm16p4s2");
else
Format(instr, "bgezal 'rs, 'imm16u -> 'imm16p4s2");
break; break;
}
case BGEZALL: case BGEZALL:
Format(instr, "bgezall 'rs, 'imm16u -> 'imm16p4s2"); Format(instr, "bgezall 'rs, 'imm16u -> 'imm16p4s2");
break; break;
......
...@@ -3791,6 +3791,7 @@ void Simulator::DecodeTypeRegisterSPECIAL( ...@@ -3791,6 +3791,7 @@ void Simulator::DecodeTypeRegisterSPECIAL(
break; break;
case DSLL: case DSLL:
set_register(rd_reg, alu_out); set_register(rd_reg, alu_out);
TraceRegWr(alu_out);
break; break;
case DIV: case DIV:
case DDIV: case DDIV:
...@@ -4412,7 +4413,6 @@ void Simulator::DecodeTypeImmediate(Instruction* instr) { ...@@ -4412,7 +4413,6 @@ void Simulator::DecodeTypeImmediate(Instruction* instr) {
UNREACHABLE(); UNREACHABLE();
} }
// ---------- Raise exceptions triggered. // ---------- Raise exceptions triggered.
SignalExceptions(); SignalExceptions();
......
...@@ -411,6 +411,7 @@ class Simulator { ...@@ -411,6 +411,7 @@ class Simulator {
instr->OpcodeValue()); instr->OpcodeValue());
} }
InstructionDecode(instr); InstructionDecode(instr);
SNPrintF(trace_buf_, " ");
} }
// ICache. // ICache.
......
...@@ -5059,4 +5059,56 @@ TEST(r6_balc) { ...@@ -5059,4 +5059,56 @@ TEST(r6_balc) {
} }
uint32_t run_bal(int16_t offset) {
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
MacroAssembler assm(isolate, NULL, 0);
__ mov(t0, ra);
__ bal(offset); // Equivalent for "BGEZAL zero_reg, offset".
__ nop();
__ mov(ra, t0);
__ jr(ra);
__ nop();
__ li(v0, 1);
__ jr(ra);
__ nop();
CodeDesc desc;
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
F2 f = FUNCTION_CAST<F2>(code->entry());
uint32_t res =
reinterpret_cast<uint32_t>(CALL_GENERATED_CODE(f, 0, 0, 0, 0, 0));
return res;
}
TEST(bal) {
CcTest::InitializeVM();
struct TestCaseBal {
int16_t offset;
uint32_t expected_res;
};
struct TestCaseBal tc[] = {
// offset, expected_res
{ 4, 1 },
};
size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseBal);
for (size_t i = 0; i < nr_test_cases; ++i) {
CHECK_EQ(tc[i].expected_res, run_bal(tc[i].offset));
}
}
#undef __ #undef __
...@@ -5366,4 +5366,104 @@ TEST(r6_balc) { ...@@ -5366,4 +5366,104 @@ TEST(r6_balc) {
} }
uint64_t run_dsll(uint64_t rt_value, uint16_t sa_value) {
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
MacroAssembler assm(isolate, NULL, 0);
__ dsll(v0, a0, sa_value);
__ jr(ra);
__ nop();
CodeDesc desc;
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
F2 f = FUNCTION_CAST<F2>(code->entry());
uint64_t res =
reinterpret_cast<uint64_t>(CALL_GENERATED_CODE(f, rt_value, 0, 0, 0, 0));
return res;
}
TEST(dsll) {
CcTest::InitializeVM();
struct TestCaseDsll {
uint64_t rt_value;
uint16_t sa_value;
uint64_t expected_res;
};
struct TestCaseDsll tc[] = {
// rt_value, sa_value, expected_res
{ 0xffffffffffffffff, 0, 0xffffffffffffffff },
{ 0xffffffffffffffff, 16, 0xffffffffffff0000 },
{ 0xffffffffffffffff, 31, 0xffffffff80000000 },
};
size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseDsll);
for (size_t i = 0; i < nr_test_cases; ++i) {
CHECK_EQ(tc[i].expected_res,
run_dsll(tc[i].rt_value, tc[i].sa_value));
}
}
uint64_t run_bal(int16_t offset) {
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
MacroAssembler assm(isolate, NULL, 0);
__ mov(t0, ra);
__ bal(offset); // Equivalent for "BGEZAL zero_reg, offset".
__ nop();
__ mov(ra, t0);
__ jr(ra);
__ nop();
__ li(v0, 1);
__ jr(ra);
__ nop();
CodeDesc desc;
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
F2 f = FUNCTION_CAST<F2>(code->entry());
uint64_t res =
reinterpret_cast<uint64_t>(CALL_GENERATED_CODE(f, 0, 0, 0, 0, 0));
return res;
}
TEST(bal) {
CcTest::InitializeVM();
struct TestCaseBal {
int16_t offset;
uint64_t expected_res;
};
struct TestCaseBal tc[] = {
// offset, expected_res
{ 4, 1 },
};
size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseBal);
for (size_t i = 0; i < nr_test_cases; ++i) {
CHECK_EQ(tc[i].expected_res, run_bal(tc[i].offset));
}
}
#undef __ #undef __
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment