Commit c7d85563 authored by QiuJi's avatar QiuJi Committed by V8 LUCI CQ

[riscv64] Add flag to control disassembling of C-ext

Also handling kArchStackPointerGreaterThan in AssembleArchBoolean

Change-Id: I253c1a6cb924364eead3b9fe58c7cf7d6f0696af
Bug: v8:11737
Bug: v8:11747
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2876854Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarBrice Dobry <brice.dobry@futurewei.com>
Commit-Queue: Brice Dobry <brice.dobry@futurewei.com>
Cr-Commit-Position: refs/heads/master@{#74543}
parent 0b92905b
...@@ -747,7 +747,7 @@ bool Assembler::MustUseReg(RelocInfo::Mode rmode) { ...@@ -747,7 +747,7 @@ bool Assembler::MustUseReg(RelocInfo::Mode rmode) {
} }
void Assembler::disassembleInstr(Instr instr) { void Assembler::disassembleInstr(Instr instr) {
if (!FLAG_debug_riscv) return; if (!FLAG_riscv_debug) return;
disasm::NameConverter converter; disasm::NameConverter converter;
disasm::Disassembler disasm(converter); disasm::Disassembler disasm(converter);
EmbeddedVector<char, 128> disasm_buffer; EmbeddedVector<char, 128> disasm_buffer;
......
...@@ -107,7 +107,7 @@ int FPURegisters::Number(const char* name) { ...@@ -107,7 +107,7 @@ int FPURegisters::Number(const char* name) {
InstructionBase::Type InstructionBase::InstructionType() const { InstructionBase::Type InstructionBase::InstructionType() const {
// RV64C Instruction // RV64C Instruction
if (IsShortInstruction()) { if (FLAG_riscv_c_extension && IsShortInstruction()) {
switch (InstructionBits() & kRvcOpcodeMask) { switch (InstructionBits() & kRvcOpcodeMask) {
case RO_C_ADDI4SPN: case RO_C_ADDI4SPN:
return kCIWType; return kCIWType;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/base/logging.h" #include "src/base/logging.h"
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/flags/flags.h"
// UNIMPLEMENTED_ macro for RISCV. // UNIMPLEMENTED_ macro for RISCV.
#ifdef DEBUG #ifdef DEBUG
...@@ -732,12 +733,14 @@ class InstructionBase { ...@@ -732,12 +733,14 @@ class InstructionBase {
} }
inline uint8_t InstructionSize() const { inline uint8_t InstructionSize() const {
return this->IsShortInstruction() ? kShortInstrSize : kInstrSize; return (FLAG_riscv_c_extension && this->IsShortInstruction())
? kShortInstrSize
: kInstrSize;
} }
// Get the raw instruction bits. // Get the raw instruction bits.
inline Instr InstructionBits() const { inline Instr InstructionBits() const {
if (this->IsShortInstruction()) { if (FLAG_riscv_c_extension && this->IsShortInstruction()) {
return 0x0000FFFF & (*reinterpret_cast<const ShortInstr*>(this)); return 0x0000FFFF & (*reinterpret_cast<const ShortInstr*>(this));
} }
return *reinterpret_cast<const Instr*>(this); return *reinterpret_cast<const Instr*>(this);
......
...@@ -2296,6 +2296,16 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr, ...@@ -2296,6 +2296,16 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
UNREACHABLE(); UNREACHABLE();
} }
return; return;
} else if (instr->arch_opcode() == kArchStackPointerGreaterThan) {
cc = FlagsConditionToConditionCmp(condition);
Register lhs_register = sp;
uint32_t offset;
if (ShouldApplyOffsetToStackCheck(instr, &offset)) {
lhs_register = i.TempRegister(0);
__ Sub64(lhs_register, sp, offset);
}
__ Sgtu(result, lhs_register, Operand(i.InputRegister(0)));
return;
} else if (instr->arch_opcode() == kRiscvCmpD || } else if (instr->arch_opcode() == kRiscvCmpD ||
instr->arch_opcode() == kRiscvCmpS) { instr->arch_opcode() == kRiscvCmpS) {
FPURegister left = i.InputOrZeroDoubleRegister(0); FPURegister left = i.InputOrZeroDoubleRegister(0);
......
...@@ -1328,6 +1328,9 @@ DEFINE_BOOL(riscv_debug, false, "enable debug prints") ...@@ -1328,6 +1328,9 @@ DEFINE_BOOL(riscv_debug, false, "enable debug prints")
DEFINE_BOOL(riscv_constant_pool, true, DEFINE_BOOL(riscv_constant_pool, true,
"enable constant pool (RISCV only)") "enable constant pool (RISCV only)")
DEFINE_BOOL(riscv_c_extension, false,
"enable compressed extension isa variant (RISCV only)")
#endif #endif
// Controlling source positions for Torque/CSA code. // Controlling source positions for Torque/CSA code.
......
...@@ -76,6 +76,16 @@ using F5 = void*(void* p0, void* p1, int p2, int p3, int p4); ...@@ -76,6 +76,16 @@ using F5 = void*(void* p0, void* p1, int p2, int p3, int p4);
CHECK_EQ(expected_res, res); \ CHECK_EQ(expected_res, res); \
} }
#define UTEST_R1_FORM_WITH_RES_C(instr_name, in_type, out_type, rs1_val, \
expected_res) \
TEST(RISCV_UTEST_##instr_name) { \
i::FLAG_riscv_c_extension = true; \
CcTest::InitializeVM(); \
auto fn = [](MacroAssembler& assm) { __ instr_name(a0, a0); }; \
auto res = GenAndRunTest<out_type, in_type>(rs1_val, fn); \
CHECK_EQ(expected_res, res); \
}
#define UTEST_I_FORM_WITH_RES(instr_name, type, rs1_val, imm12, expected_res) \ #define UTEST_I_FORM_WITH_RES(instr_name, type, rs1_val, imm12, expected_res) \
TEST(RISCV_UTEST_##instr_name) { \ TEST(RISCV_UTEST_##instr_name) { \
CcTest::InitializeVM(); \ CcTest::InitializeVM(); \
...@@ -554,8 +564,8 @@ UTEST_CONV_F_FROM_I(fcvt_d_lu, uint64_t, double, ...@@ -554,8 +564,8 @@ UTEST_CONV_F_FROM_I(fcvt_d_lu, uint64_t, double,
(double)(std::numeric_limits<uint64_t>::max())) (double)(std::numeric_limits<uint64_t>::max()))
// -- RV64C Standard Extension -- // -- RV64C Standard Extension --
UTEST_R1_FORM_WITH_RES(c_mv, int64_t, int64_t, 0x0f5600ab123400, UTEST_R1_FORM_WITH_RES_C(c_mv, int64_t, int64_t, 0x0f5600ab123400,
0x0f5600ab123400) 0x0f5600ab123400)
// -- Assembler Pseudo Instructions -- // -- Assembler Pseudo Instructions --
UTEST_R1_FORM_WITH_RES(mv, int64_t, int64_t, 0x0f5600ab123400, 0x0f5600ab123400) UTEST_R1_FORM_WITH_RES(mv, int64_t, int64_t, 0x0f5600ab123400, 0x0f5600ab123400)
...@@ -1201,6 +1211,7 @@ TEST(NAN_BOX) { ...@@ -1201,6 +1211,7 @@ TEST(NAN_BOX) {
TEST(RVC_CI) { TEST(RVC_CI) {
// Test RV64C extension CI type instructions. // Test RV64C extension CI type instructions.
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
// Test c.addi // Test c.addi
...@@ -1253,6 +1264,7 @@ TEST(RVC_CI) { ...@@ -1253,6 +1264,7 @@ TEST(RVC_CI) {
} }
TEST(RVC_CIW) { TEST(RVC_CIW) {
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
// Test c.addi4spn // Test c.addi4spn
...@@ -1270,6 +1282,7 @@ TEST(RVC_CIW) { ...@@ -1270,6 +1282,7 @@ TEST(RVC_CIW) {
TEST(RVC_CR) { TEST(RVC_CR) {
// Test RV64C extension CR type instructions. // Test RV64C extension CR type instructions.
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
// Test c.add // Test c.add
...@@ -1285,6 +1298,7 @@ TEST(RVC_CR) { ...@@ -1285,6 +1298,7 @@ TEST(RVC_CR) {
TEST(RVC_CA) { TEST(RVC_CA) {
// Test RV64C extension CA type instructions. // Test RV64C extension CA type instructions.
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
// Test c.sub // Test c.sub
...@@ -1350,6 +1364,7 @@ TEST(RVC_CA) { ...@@ -1350,6 +1364,7 @@ TEST(RVC_CA) {
TEST(RVC_LOAD_STORE_SP) { TEST(RVC_LOAD_STORE_SP) {
// Test RV64C extension fldsp/fsdsp, lwsp/swsp, ldsp/sdsp. // Test RV64C extension fldsp/fsdsp, lwsp/swsp, ldsp/sdsp.
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
{ {
...@@ -1382,6 +1397,8 @@ TEST(RVC_LOAD_STORE_SP) { ...@@ -1382,6 +1397,8 @@ TEST(RVC_LOAD_STORE_SP) {
TEST(RVC_LOAD_STORE_COMPRESSED) { TEST(RVC_LOAD_STORE_COMPRESSED) {
// Test RV64C extension fld, lw, ld. // Test RV64C extension fld, lw, ld.
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate); HandleScope scope(isolate);
...@@ -1462,6 +1479,7 @@ TEST(RVC_LOAD_STORE_COMPRESSED) { ...@@ -1462,6 +1479,7 @@ TEST(RVC_LOAD_STORE_COMPRESSED) {
} }
TEST(RVC_JUMP) { TEST(RVC_JUMP) {
i::FLAG_riscv_c_extension = true;
CcTest::InitializeVM(); CcTest::InitializeVM();
Label L, C; Label L, C;
......
...@@ -465,6 +465,7 @@ TEST(PSEUDO) { ...@@ -465,6 +465,7 @@ TEST(PSEUDO) {
} }
TEST(RV64C) { TEST(RV64C) {
i::FLAG_riscv_c_extension = true;
SET_UP(); SET_UP();
COMPARE(c_nop(), "00000001 nop"); COMPARE(c_nop(), "00000001 nop");
......
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