Skip to content

Commit a8a3491

Browse files
committed
Revise as proposed comments, including
- Fix macros in assembler_riscv_c.hpp - Remove UncompressibleRegion - Modify comments - Change names: C-Ext to RVC
1 parent 238665d commit a8a3491

File tree

6 files changed

+35
-58
lines changed

6 files changed

+35
-58
lines changed

src/hotspot/cpu/riscv/assembler_riscv_c.hpp

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*
2424
*/
2525

26-
#ifndef CPU_RISCV_ASSEMBLER_RISCV_CEXT_HPP
27-
#define CPU_RISCV_ASSEMBLER_RISCV_CEXT_HPP
26+
#ifndef CPU_RISCV_ASSEMBLER_RISCV_C_HPP
27+
#define CPU_RISCV_ASSEMBLER_RISCV_C_HPP
2828

2929
private:
3030
bool _in_compressible_region;
@@ -33,7 +33,7 @@
3333
void set_in_compressible_region(bool b) { _in_compressible_region = b; }
3434
public:
3535

36-
// C-Ext: If an instruction is compressible, then
36+
// RVC: If an instruction is compressible, then
3737
// we will implicitly emit a 16-bit compressed instruction instead of the 32-bit
3838
// instruction in Assembler. All below logic follows Chapter -
3939
// "C" Standard Extension for Compressed Instructions, Version 2.0.
@@ -43,27 +43,20 @@
4343
// Note:
4444
// 1. When UseRVC is enabled, 32-bit instructions under 'CompressibleRegion's will be
4545
// transformed to 16-bit instructions if compressible.
46-
// 2. C-Ext's instructions in Assembler always begin with 'c_' prefix, as 'c_li',
46+
// 2. RVC instructions in Assembler always begin with 'c_' prefix, as 'c_li',
4747
// but most of time we have no need to explicitly use these instructions.
48-
// 3. In some cases, we need to force using one instruction's uncompressed version,
49-
// for instance code being patched should remain its general and longest version
50-
// to cover all possible cases, or code requiring a fixed length.
51-
// So we introduce 'UncompressibleRegion' to force instructions in its range
52-
// to remain its normal 4-byte version.
48+
// 3. We introduce 'CompressibleRegion' to hint instructions in this Region's RTTI range
49+
// are qualified to change to their 2-byte versions.
5350
// An example:
5451
//
5552
// CompressibleRegion cr(_masm);
56-
// __ andr(...); // this instruction could change to c.and if qualified
57-
// {
58-
// UncompressibleRegion ur(_masm);
59-
// __ andr(...); // this instruction would remain the normal 32-bit form of andr
60-
// }
53+
// __ andr(...); // this instruction could change to c.and if able to
6154
//
62-
// 4. Using -XX:PrintAssemblyOptions=no-aliases could print C-Ext instructions instead of
55+
// 4. Using -XX:PrintAssemblyOptions=no-aliases could print RVC instructions instead of
6356
// normal ones.
6457
//
6558

66-
// C-Ext: extract a 16-bit instruction.
59+
// RVC: extract a 16-bit instruction.
6760
static inline uint16_t c_extract(uint16_t val, unsigned msb, unsigned lsb) {
6861
assert_cond(msb >= lsb && msb <= 15);
6962
unsigned nbits = msb - lsb + 1;
@@ -80,7 +73,7 @@
8073
return result;
8174
}
8275

83-
// C-Ext: patch a 16-bit instruction.
76+
// RVC: patch a 16-bit instruction.
8477
static void c_patch(address a, unsigned msb, unsigned lsb, uint16_t val) {
8578
assert_cond(a != NULL);
8679
assert_cond(msb >= lsb && msb <= 15);
@@ -99,31 +92,31 @@
9992
c_patch(a, bit, bit, val);
10093
}
10194

102-
// C-Ext: patch a 16-bit instruction with a general purpose register ranging [0, 31] (5 bits)
95+
// RVC: patch a 16-bit instruction with a general purpose register ranging [0, 31] (5 bits)
10396
static void c_patch_reg(address a, unsigned lsb, Register reg) {
10497
c_patch(a, lsb + 4, lsb, reg->encoding_nocheck());
10598
}
10699

107-
// C-Ext: patch a 16-bit instruction with a general purpose register ranging [8, 15] (3 bits)
100+
// RVC: patch a 16-bit instruction with a general purpose register ranging [8, 15] (3 bits)
108101
static void c_patch_compressed_reg(address a, unsigned lsb, Register reg) {
109102
c_patch(a, lsb + 2, lsb, reg->compressed_encoding_nocheck());
110103
}
111104

112-
// C-Ext: patch a 16-bit instruction with a float register ranging [0, 31] (5 bits)
105+
// RVC: patch a 16-bit instruction with a float register ranging [0, 31] (5 bits)
113106
static void c_patch_reg(address a, unsigned lsb, FloatRegister reg) {
114107
c_patch(a, lsb + 4, lsb, reg->encoding_nocheck());
115108
}
116109

117-
// C-Ext: patch a 16-bit instruction with a float register ranging [8, 15] (3 bits)
110+
// RVC: patch a 16-bit instruction with a float register ranging [8, 15] (3 bits)
118111
static void c_patch_compressed_reg(address a, unsigned lsb, FloatRegister reg) {
119112
c_patch(a, lsb + 2, lsb, reg->compressed_encoding_nocheck());
120113
}
121114

122115
public:
123116

124-
// C-Ext: Compressed Instructions
117+
// RVC: Compressed Instructions
125118

126-
// -------------- C-Ext Instruction Definitions --------------
119+
// -------------- RVC Instruction Definitions --------------
127120

128121
void c_nop() {
129122
c_addi(x0, 0);
@@ -545,13 +538,13 @@
545538

546539
#undef INSN
547540

548-
// -------------- C-Ext Transformation Macros --------------
541+
// -------------- RVC Transformation Macros --------------
549542

550-
// two C-Ext macros
543+
// two RVC macros
551544
#define COMPRESSIBLE true
552545
#define NOT_COMPRESSIBLE false
553546

554-
// a pivotal dispatcher for C-Ext
547+
// a pivotal dispatcher for RVC
555548
#define EMIT_MAY_COMPRESS(C, NAME, ...) EMIT_MAY_COMPRESS_##C(NAME, __VA_ARGS__)
556549
#define EMIT_MAY_COMPRESS_true(NAME, ...) EMIT_MAY_COMPRESS_##NAME(__VA_ARGS__)
557550
#define EMIT_MAY_COMPRESS_false(NAME, ...)
@@ -560,7 +553,7 @@
560553
#define CHECK_CEXT_AND_COMPRESSIBLE(...) IS_COMPRESSIBLE(UseRVC && in_compressible_region() && __VA_ARGS__)
561554
#define CHECK_CEXT() if (UseRVC && in_compressible_region())
562555

563-
// C-Ext transformation macros
556+
// RVC transformation macros
564557
#define EMIT_RVC_cond(PREFIX, COND, EMIT) { \
565558
PREFIX \
566559
CHECK_CEXT_AND_COMPRESSIBLE(COND) { \
@@ -869,36 +862,20 @@
869862
// --------------------------
870863

871864
public:
872-
// C-Ext: an abstact compressible region
873-
class AbstractCompressibleRegion : public StackObj {
865+
// RVC: a compressible region
866+
class CompressibleRegion : public StackObj {
874867
protected:
875868
Assembler *_masm;
876869
bool _prev_in_compressible_region;
877-
protected:
878-
AbstractCompressibleRegion(Assembler *_masm)
879-
: _masm(_masm)
880-
, _prev_in_compressible_region(_masm->in_compressible_region()) {}
881-
};
882-
883-
class CompressibleRegion : public AbstractCompressibleRegion {
884870
public:
885-
CompressibleRegion(Assembler *_masm) : AbstractCompressibleRegion(_masm) {
871+
CompressibleRegion(Assembler *_masm)
872+
: _masm(_masm)
873+
, _prev_in_compressible_region(_masm->in_compressible_region()) {
886874
_masm->set_in_compressible_region(true);
887875
}
888876
~CompressibleRegion() {
889877
_masm->set_in_compressible_region(_prev_in_compressible_region);
890878
}
891879
};
892880

893-
// C-Ext: an uncompressible region
894-
class UncompressibleRegion : public AbstractCompressibleRegion {
895-
public:
896-
UncompressibleRegion(Assembler *_masm) : AbstractCompressibleRegion(_masm) {
897-
_masm->set_in_compressible_region(false);
898-
}
899-
~UncompressibleRegion() {
900-
_masm->set_in_compressible_region(_prev_in_compressible_region);
901-
}
902-
};
903-
904-
#endif // CPU_RISCV_ASSEMBLER_RISCV_CEXT_HPP
881+
#endif // CPU_RISCV_ASSEMBLER_RISCV_C_HPP

src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ void LIR_Assembler::comp_fl2i(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Op
13231323
}
13241324

13251325
void LIR_Assembler::align_call(LIR_Code code) {
1326-
// C-Ext: With C-Ext a call may get 2-byte aligned.
1326+
// RVC: With RVC a call may get 2-byte aligned.
13271327
// the address of jal itself (which will be patched later) should not span the cache line.
13281328
// See CallDynamicJavaDirectNode::compute_padding() for more info.
13291329
__ align(4);

src/hotspot/cpu/riscv/gc/shared/barrierSetAssembler_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) {
240240
return;
241241
}
242242

243-
// C-Ext: RISCV's amoswap instructions need an alignment for the memory address it swaps
243+
// RVC: RISCV's amoswap instructions need an alignment for the memory address it swaps
244244
// when we reach here we may get a 2-byte alignment so need to align it
245245
__ align(4, nmethod_barrier_guard_offset());
246246

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,7 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
29262926

29272927
// make sure 4 byte aligned here, so that the destination address would be
29282928
// 8 byte aligned after 3 intructions
2929-
// C-Ext: when we reach here we may get a 2-byte alignment so need to align it
2929+
// RVC: when we reach here we may get a 2-byte alignment so need to align it
29302930
align(wordSize, NativeCallTrampolineStub::data_offset);
29312931

29322932
relocate(trampoline_stub_Relocation::spec(code()->insts()->start() +

src/hotspot/cpu/riscv/register_riscv.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class RegisterImpl: public AbstractRegisterImpl {
6060
number_of_byte_registers = 32,
6161
max_slots_per_register = 2,
6262

63-
// C-Ext: integer registers in the range of [x8~x15] are correspond for RVC. Please see Table 16.2 in spec.
63+
// RVC: integer registers in the range of [x8~x15] correspond to RVC. Please see Table 16.2 in spec.
6464
compressed_register_base = 8,
6565
compressed_register_top = 15,
6666
};
@@ -140,7 +140,7 @@ class FloatRegisterImpl: public AbstractRegisterImpl {
140140
number_of_registers = 32,
141141
max_slots_per_register = 2,
142142

143-
// C-Ext: float registers in the range of [f8~f15] are correspond for RVC. Please see Table 16.2 in spec.
143+
// RVC: float registers in the range of [f8~f15] correspond to RVC. Please see Table 16.2 in spec.
144144
compressed_register_base = 8,
145145
compressed_register_top = 15,
146146
};

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ int MachCallNativeNode::ret_addr_offset() {
11901190
return -1;
11911191
}
11921192

1193-
// C-Ext: With C-Ext a call may get 2-byte aligned.
1193+
// RVC: With RVC a call may get 2-byte aligned.
11941194
// The offset encoding in jal ranges bits [12, 31], which could span the cache line.
11951195
// Patching this unaligned address will make the write operation not atomic.
11961196
// Other threads may be running the same piece of code at full speed, causing concurrency issues.
@@ -1201,7 +1201,7 @@ int CallStaticJavaDirectNode::compute_padding(int current_offset) const
12011201
return align_up(current_offset, alignment_required()) - current_offset;
12021202
}
12031203

1204-
// C-Ext: With C-Ext a call may get 2-byte aligned.
1204+
// RVC: With RVC a call may get 2-byte aligned.
12051205
// The offset encoding in jal ranges bits [12, 31], which could span the cache line.
12061206
// Patching this unaligned address will make the write operation not atomic.
12071207
// Other threads may be running the same piece of code at full speed, causing concurrency issues.
@@ -1210,7 +1210,7 @@ int CallDynamicJavaDirectNode::compute_padding(int current_offset) const
12101210
{
12111211
// skip the movptr in MacroAssembler::ic_call():
12121212
// lui + addi + slli + addi + slli + addi
1213-
// Though movptr() has already 4-byte aligned with or without C-Ext,
1213+
// Though movptr() has already 4-byte aligned with or without RVC,
12141214
// We need to prevent from further changes by explicitly calculating the size.
12151215
const int movptr_size = 6 * NativeInstruction::instruction_size;
12161216
current_offset += movptr_size;
@@ -1246,7 +1246,7 @@ uint MachBreakpointNode::size(PhaseRegAlloc *ra_) const {
12461246

12471247
void MachNopNode::emit(CodeBuffer &cbuf, PhaseRegAlloc*) const {
12481248
C2_MacroAssembler _masm(&cbuf);
1249-
Assembler::CompressibleRegion cr(&_masm);
1249+
Assembler::CompressibleRegion cr(&_masm); // RVC: nops shall be 2-byte under RVC for alignment purposes.
12501250
for (int i = 0; i < _count; i++) {
12511251
__ nop();
12521252
}

0 commit comments

Comments
 (0)