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
2929private:
3030 bool _in_compressible_region;
3333 void set_in_compressible_region (bool b) { _in_compressible_region = b; }
3434public:
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.
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 ;
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 );
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
122115public:
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 );
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, ...)
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) { \
869862// --------------------------
870863
871864public:
872- // C-Ext: an abstact compressible region
873- class AbstractCompressibleRegion : public StackObj {
865+ // RVC: a compressible region
866+ class CompressibleRegion : public StackObj {
874867protected:
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 {
884870public:
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
0 commit comments