23
23
*
24
24
*/
25
25
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
28
28
29
29
private:
30
30
bool _in_compressible_region;
33
33
void set_in_compressible_region (bool b) { _in_compressible_region = b; }
34
34
public:
35
35
36
- // C-Ext : If an instruction is compressible, then
36
+ // RVC : If an instruction is compressible, then
37
37
// we will implicitly emit a 16-bit compressed instruction instead of the 32-bit
38
38
// instruction in Assembler. All below logic follows Chapter -
39
39
// "C" Standard Extension for Compressed Instructions, Version 2.0.
43
43
// Note:
44
44
// 1. When UseRVC is enabled, 32-bit instructions under 'CompressibleRegion's will be
45
45
// 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',
47
47
// 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.
53
50
// An example:
54
51
//
55
52
// 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
61
54
//
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
63
56
// normal ones.
64
57
//
65
58
66
- // C-Ext : extract a 16-bit instruction.
59
+ // RVC : extract a 16-bit instruction.
67
60
static inline uint16_t c_extract (uint16_t val, unsigned msb, unsigned lsb) {
68
61
assert_cond (msb >= lsb && msb <= 15 );
69
62
unsigned nbits = msb - lsb + 1 ;
80
73
return result;
81
74
}
82
75
83
- // C-Ext : patch a 16-bit instruction.
76
+ // RVC : patch a 16-bit instruction.
84
77
static void c_patch (address a, unsigned msb, unsigned lsb, uint16_t val) {
85
78
assert_cond (a != NULL );
86
79
assert_cond (msb >= lsb && msb <= 15 );
99
92
c_patch (a, bit, bit, val);
100
93
}
101
94
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)
103
96
static void c_patch_reg (address a, unsigned lsb, Register reg) {
104
97
c_patch (a, lsb + 4 , lsb, reg->encoding_nocheck ());
105
98
}
106
99
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)
108
101
static void c_patch_compressed_reg (address a, unsigned lsb, Register reg) {
109
102
c_patch (a, lsb + 2 , lsb, reg->compressed_encoding_nocheck ());
110
103
}
111
104
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)
113
106
static void c_patch_reg (address a, unsigned lsb, FloatRegister reg) {
114
107
c_patch (a, lsb + 4 , lsb, reg->encoding_nocheck ());
115
108
}
116
109
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)
118
111
static void c_patch_compressed_reg (address a, unsigned lsb, FloatRegister reg) {
119
112
c_patch (a, lsb + 2 , lsb, reg->compressed_encoding_nocheck ());
120
113
}
121
114
122
115
public:
123
116
124
- // C-Ext : Compressed Instructions
117
+ // RVC : Compressed Instructions
125
118
126
- // -------------- C-Ext Instruction Definitions --------------
119
+ // -------------- RVC Instruction Definitions --------------
127
120
128
121
void c_nop () {
129
122
c_addi (x0, 0 );
545
538
546
539
#undef INSN
547
540
548
- // -------------- C-Ext Transformation Macros --------------
541
+ // -------------- RVC Transformation Macros --------------
549
542
550
- // two C-Ext macros
543
+ // two RVC macros
551
544
#define COMPRESSIBLE true
552
545
#define NOT_COMPRESSIBLE false
553
546
554
- // a pivotal dispatcher for C-Ext
547
+ // a pivotal dispatcher for RVC
555
548
#define EMIT_MAY_COMPRESS (C, NAME, ...) EMIT_MAY_COMPRESS_##C(NAME, __VA_ARGS__)
556
549
#define EMIT_MAY_COMPRESS_true (NAME, ...) EMIT_MAY_COMPRESS_##NAME(__VA_ARGS__)
557
550
#define EMIT_MAY_COMPRESS_false (NAME, ...)
560
553
#define CHECK_CEXT_AND_COMPRESSIBLE (...) IS_COMPRESSIBLE(UseRVC && in_compressible_region() && __VA_ARGS__)
561
554
#define CHECK_CEXT () if (UseRVC && in_compressible_region())
562
555
563
- // C-Ext transformation macros
556
+ // RVC transformation macros
564
557
#define EMIT_RVC_cond (PREFIX, COND, EMIT ) { \
565
558
PREFIX \
566
559
CHECK_CEXT_AND_COMPRESSIBLE (COND) { \
869
862
// --------------------------
870
863
871
864
public:
872
- // C-Ext: an abstact compressible region
873
- class AbstractCompressibleRegion : public StackObj {
865
+ // RVC: a compressible region
866
+ class CompressibleRegion : public StackObj {
874
867
protected:
875
868
Assembler *_masm;
876
869
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 {
884
870
public:
885
- CompressibleRegion (Assembler *_masm) : AbstractCompressibleRegion(_masm) {
871
+ CompressibleRegion (Assembler *_masm)
872
+ : _masm (_masm)
873
+ , _prev_in_compressible_region (_masm->in_compressible_region ()) {
886
874
_masm->set_in_compressible_region (true );
887
875
}
888
876
~CompressibleRegion () {
889
877
_masm->set_in_compressible_region (_prev_in_compressible_region);
890
878
}
891
879
};
892
880
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
0 commit comments