Skip to content

Commit d79411a

Browse files
committed
RVC: basic instruction set
1 parent 8e0df0d commit d79411a

File tree

8 files changed

+624
-20
lines changed

8 files changed

+624
-20
lines changed

src/hotspot/cpu/riscv/assembler_riscv.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ class InternalAddress: public Address {
255255

256256
class Assembler : public AbstractAssembler {
257257
public:
258+
#include "assembler_riscv_c.hpp"
258259

259260
enum { instruction_size = 4 };
260261

@@ -1238,7 +1239,7 @@ enum operand_size { int8, int16, int32, uint32, int64 };
12381239
void sub(Register Rd, Register Rn, int64_t decrement, Register temp = t0);
12391240
void subw(Register Rd, Register Rn, int64_t decrement, Register temp = t0);
12401241

1241-
Assembler(CodeBuffer* code) : AbstractAssembler(code) {
1242+
Assembler(CodeBuffer* code) : AbstractAssembler(code), _in_compressible_region(false) {
12421243
}
12431244

12441245
// Stack overflow checking
@@ -1263,6 +1264,4 @@ enum operand_size { int8, int16, int32, uint32, int64 };
12631264

12641265
};
12651266

1266-
class BiasedLockingCounters;
1267-
12681267
#endif // CPU_RISCV_ASSEMBLER_RISCV_HPP

src/hotspot/cpu/riscv/assembler_riscv_c.hpp

Lines changed: 581 additions & 0 deletions
Large diffs are not rendered by default.

src/hotspot/cpu/riscv/globals_riscv.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ define_pd_global(intx, InlineSmallCode, 1000);
9191
product(bool, AvoidUnalignedAccesses, true, \
9292
"Avoid generating unaligned memory accesses") \
9393
product(bool, UseRVV, false, EXPERIMENTAL, "Use RVV instructions") \
94-
product(bool, UseRVB, false, EXPERIMENTAL, "Use RVB instructions")
94+
product(bool, UseRVB, false, EXPERIMENTAL, "Use RVB instructions") \
95+
product(bool, UseRVC, false, EXPERIMENTAL, "Use RVC instructions") \
9596

9697
#endif // CPU_RISCV_GLOBALS_RISCV_HPP

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,10 @@ int MacroAssembler::pd_patch_instruction_size(address branch, address target) {
13201320
int64_t imm = (intptr_t)target;
13211321
return patch_imm_in_li32(branch, (int32_t)imm);
13221322
} else {
1323-
tty->print_cr("pd_patch_instruction_size: instruction 0x%x could not be patched!\n", *(unsigned*)branch);
1323+
#ifdef ASSERT
1324+
tty->print_cr("pd_patch_instruction_size: instruction 0x%x at " INTPTR_FORMAT " could not be patched!\n", *(unsigned*)branch, p2i(branch));
1325+
Disassembler::decode(branch - 10, branch + 10);
1326+
#endif
13241327
ShouldNotReachHere();
13251328
}
13261329
return -1;

src/hotspot/cpu/riscv/nativeInst_riscv.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class NativeInstruction {
5353
friend bool is_NativeCallTrampolineStub_at(address);
5454
public:
5555
enum {
56-
instruction_size = 4
56+
instruction_size = 4,
57+
compressed_instruction_size = 2,
5758
};
5859

5960
juint encoding() const {
@@ -422,10 +423,10 @@ inline NativeMovRegMem* nativeMovRegMem_at (address addr) {
422423
class NativeJump: public NativeInstruction {
423424
public:
424425
enum RISCV64_specific_constants {
425-
instruction_size = 4,
426+
instruction_size = NativeInstruction::instruction_size,
426427
instruction_offset = 0,
427428
data_offset = 0,
428-
next_instruction_offset = 4
429+
next_instruction_offset = NativeInstruction::instruction_size
429430
};
430431

431432
address instruction_address() const { return addr_at(instruction_offset); }

src/hotspot/cpu/riscv/register_riscv.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ class RegisterImpl: public AbstractRegisterImpl {
5858
enum {
5959
number_of_registers = 32,
6060
number_of_byte_registers = 32,
61-
max_slots_per_register = 2
61+
max_slots_per_register = 2,
62+
63+
// C-Ext: integer registers in the range of [x8~x15] are correspond for RVC. Please see Table 16.2 in spec.
64+
compressed_register_base = 8,
65+
compressed_register_top = 15,
6266
};
6367

6468
// derived registers, offsets, and addresses
@@ -71,10 +75,13 @@ class RegisterImpl: public AbstractRegisterImpl {
7175

7276
// accessors
7377
int encoding() const { assert(is_valid(), "invalid register"); return (intptr_t)this; }
78+
int compressed_encoding() const { assert(is_compressed_valid(), "invalid compressed register"); return ((intptr_t)this - compressed_register_base); }
7479
bool is_valid() const { return 0 <= (intptr_t)this && (intptr_t)this < number_of_registers; }
80+
bool is_compressed_valid() const { return compressed_register_base <= (intptr_t)this && (intptr_t)this <= compressed_register_top; }
7581
bool has_byte_register() const { return 0 <= (intptr_t)this && (intptr_t)this < number_of_byte_registers; }
7682
const char* name() const;
7783
int encoding_nocheck() const { return (intptr_t)this; }
84+
int compressed_encoding_nocheck() const { return ((intptr_t)this - compressed_register_base); }
7885

7986
// Return the bit which represents this register. This is intended
8087
// to be ORed into a bitmask: for usage see class RegSet below.
@@ -131,7 +138,11 @@ class FloatRegisterImpl: public AbstractRegisterImpl {
131138
public:
132139
enum {
133140
number_of_registers = 32,
134-
max_slots_per_register = 2
141+
max_slots_per_register = 2,
142+
143+
// C-Ext: float registers in the range of [f8~f15] are correspond for RVC. Please see Table 16.2 in spec.
144+
compressed_register_base = 8,
145+
compressed_register_top = 15,
135146
};
136147

137148
// construction
@@ -144,8 +155,11 @@ class FloatRegisterImpl: public AbstractRegisterImpl {
144155

145156
// accessors
146157
int encoding() const { assert(is_valid(), "invalid register"); return (intptr_t)this; }
158+
int compressed_encoding() const { assert(is_compressed_valid(), "invalid compressed register"); return ((intptr_t)this - compressed_register_base); }
147159
int encoding_nocheck() const { return (intptr_t)this; }
160+
int compressed_encoding_nocheck() const { return ((intptr_t)this - compressed_register_base); }
148161
bool is_valid() const { return 0 <= (intptr_t)this && (intptr_t)this < number_of_registers; }
162+
bool is_compressed_valid() const { return compressed_register_base <= (intptr_t)this && (intptr_t)this <= compressed_register_top; }
149163
const char* name() const;
150164

151165
};

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,28 +1156,27 @@ bool needs_acquiring_load_reserved(const Node *n)
11561156

11571157
int MachCallStaticJavaNode::ret_addr_offset()
11581158
{
1159-
// call should be a simple jal
1160-
int off = 4;
1161-
return off;
1159+
// jal
1160+
return 1 * NativeInstruction::instruction_size;
11621161
}
11631162

11641163
int MachCallDynamicJavaNode::ret_addr_offset()
11651164
{
1166-
return 28; // movptr, jal
1165+
return 7 * NativeInstruction::instruction_size; // movptr, jal
11671166
}
11681167

11691168
int MachCallRuntimeNode::ret_addr_offset() {
11701169
// for generated stubs the call will be
11711170
// jal(addr)
11721171
// or with far branches
11731172
// jal(trampoline_stub)
1174-
// for real runtime callouts it will be five instructions
1173+
// for real runtime callouts it will be 11 instructions
11751174
// see riscv64_enc_java_to_runtime
1176-
// la(t1, retaddr)
1177-
// la(t0, RuntimeAddress(addr))
1178-
// addi(sp, sp, -2 * wordSize)
1179-
// sd(t1, Address(sp, wordSize))
1180-
// jalr(t0)
1175+
// la(t1, retaddr) -> auipc + addi
1176+
// la(t0, RuntimeAddress(addr)) -> lui + addi + slli + addi + slli + addi
1177+
// addi(sp, sp, -2 * wordSize) -> addi
1178+
// sd(t1, Address(sp, wordSize)) -> sd
1179+
// jalr(t0) -> jalr
11811180
CodeBlob *cb = CodeCache::find_blob(_entry_point);
11821181
if (cb != NULL) {
11831182
return 1 * NativeInstruction::instruction_size;

src/hotspot/cpu/riscv/vm_version_riscv.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ void VM_Version::initialize() {
106106
FLAG_SET_DEFAULT(UseMD5Intrinsics, false);
107107
}
108108

109+
// compressed instruction extension
110+
if (UseRVC && !(_features & CPU_C)) {
111+
warning("RVC is not supported on this CPU");
112+
FLAG_SET_DEFAULT(UseRVC, false);
113+
}
114+
109115
if (UseRVV) {
110116
if (!(_features & CPU_V)) {
111117
warning("RVV is not supported on this CPU");

0 commit comments

Comments
 (0)