@@ -1342,15 +1342,15 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1342
1342
class CompressibleRegion : public StackObj {
1343
1343
protected:
1344
1344
Assembler *_masm;
1345
- bool _prev_in_compressible_region ;
1345
+ bool _saved_in_compressible_region ;
1346
1346
public:
1347
1347
CompressibleRegion (Assembler *_masm)
1348
1348
: _masm(_masm)
1349
- , _prev_in_compressible_region (_masm->in_compressible_region ()) {
1349
+ , _saved_in_compressible_region (_masm->in_compressible_region ()) {
1350
1350
_masm->set_in_compressible_region (true );
1351
1351
}
1352
1352
~CompressibleRegion () {
1353
- _masm->set_in_compressible_region (_prev_in_compressible_region );
1353
+ _masm->set_in_compressible_region (_saved_in_compressible_region );
1354
1354
}
1355
1355
};
1356
1356
@@ -1837,10 +1837,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1837
1837
// --------------------------
1838
1838
// Register instructions
1839
1839
// --------------------------
1840
- // add -> c.add
1841
1840
#define INSN (NAME ) \
1842
1841
void NAME (Register Rd, Register Rs1, Register Rs2) { \
1843
- if (check_rvc ()) { \
1842
+ /* add -> c.add */ \
1843
+ if (do_compress ()) { \
1844
1844
Register src = noreg; \
1845
1845
if (Rs1 != x0 && Rs2 != x0 && ((src = Rs1, Rs2 == Rd) || (src = Rs2, Rs1 == Rd))) { \
1846
1846
c_add (Rd, src); \
@@ -1855,10 +1855,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1855
1855
#undef INSN
1856
1856
1857
1857
// --------------------------
1858
- // sub/subw -> c.sub/c.subw
1859
1858
#define INSN (NAME, C_NAME, NORMAL_NAME ) \
1860
1859
void NAME (Register Rd, Register Rs1, Register Rs2) { \
1861
- if (check_rvc () && \
1860
+ /* sub/subw -> c.sub/c.subw */ \
1861
+ if (do_compress () && \
1862
1862
(Rd == Rs1 && Rd->is_compressed_valid () && Rs2->is_compressed_valid ())) { \
1863
1863
C_NAME (Rd, Rs2); \
1864
1864
return ; \
@@ -1872,10 +1872,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1872
1872
#undef INSN
1873
1873
1874
1874
// --------------------------
1875
- // xor/or/and/addw -> c.xor/c.or/c.and/c.addw
1876
1875
#define INSN (NAME, C_NAME, NORMAL_NAME ) \
1877
1876
void NAME (Register Rd, Register Rs1, Register Rs2) { \
1878
- if (check_rvc ()) { \
1877
+ /* and/or/xor/addw -> c.and/c.or/c.xor/c.addw */ \
1878
+ if (do_compress ()) { \
1879
1879
Register src = noreg; \
1880
1880
if (Rs1->is_compressed_valid () && Rs2->is_compressed_valid () && \
1881
1881
((src = Rs1, Rs2 == Rd) || (src = Rs2, Rs1 == Rd))) { \
@@ -1895,7 +1895,7 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1895
1895
1896
1896
private:
1897
1897
// some helper functions
1898
- bool check_rvc () const {
1898
+ bool do_compress () const {
1899
1899
return UseRVC && in_compressible_region ();
1900
1900
}
1901
1901
@@ -1941,10 +1941,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1941
1941
// --------------------------
1942
1942
// Load/store register
1943
1943
// --------------------------
1944
- // lw -> c.lwsp/c.lw
1945
1944
#define INSN (NAME ) \
1946
1945
void NAME (Register Rd, Register Rs, const int32_t offset) { \
1947
- if (check_rvc ()) { \
1946
+ /* lw -> c.lwsp/c.lw */ \
1947
+ if (do_compress ()) { \
1948
1948
if (is_c_lwswsp (Rs, Rd, offset, true )) { \
1949
1949
c_lwsp (Rd, offset); \
1950
1950
return ; \
@@ -1961,10 +1961,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1961
1961
#undef INSN
1962
1962
1963
1963
// --------------------------
1964
- // ld -> c.ldsp/c.ld
1965
1964
#define INSN (NAME ) \
1966
1965
void NAME (Register Rd, Register Rs, const int32_t offset) { \
1967
- if (check_rvc ()) { \
1966
+ /* ld -> c.ldsp/c.ld */ \
1967
+ if (do_compress ()) { \
1968
1968
if (is_c_ldsdsp (Rs, Rd, offset, true )) { \
1969
1969
c_ldsp (Rd, offset); \
1970
1970
return ; \
@@ -1981,10 +1981,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
1981
1981
#undef INSN
1982
1982
1983
1983
// --------------------------
1984
- // fld -> c.fldsp/c.fld
1985
1984
#define INSN (NAME ) \
1986
1985
void NAME (FloatRegister Rd, Register Rs, const int32_t offset) { \
1987
- if (check_rvc ()) { \
1986
+ /* fld -> c.fldsp/c.fld */ \
1987
+ if (do_compress ()) { \
1988
1988
if (is_c_fldsdsp (Rs, offset)) { \
1989
1989
c_fldsp (Rd, offset); \
1990
1990
return ; \
@@ -2001,10 +2001,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2001
2001
#undef INSN
2002
2002
2003
2003
// --------------------------
2004
- // sd -> c.sdsp/c.sd
2005
2004
#define INSN (NAME ) \
2006
2005
void NAME (Register Rd, Register Rs, const int32_t offset) { \
2007
- if (check_rvc ()) { \
2006
+ /* sd -> c.sdsp/c.sd */ \
2007
+ if (do_compress ()) { \
2008
2008
if (is_c_ldsdsp (Rs, Rd, offset, false )) { \
2009
2009
c_sdsp (Rd, offset); \
2010
2010
return ; \
@@ -2021,10 +2021,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2021
2021
#undef INSN
2022
2022
2023
2023
// --------------------------
2024
- // sw -> c.swsp/c.sw
2025
2024
#define INSN (NAME ) \
2026
2025
void NAME (Register Rd, Register Rs, const int32_t offset) { \
2027
- if (check_rvc ()) { \
2026
+ /* sw -> c.swsp/c.sw */ \
2027
+ if (do_compress ()) { \
2028
2028
if (is_c_lwswsp (Rs, Rd, offset, false )) { \
2029
2029
c_swsp (Rd, offset); \
2030
2030
return ; \
@@ -2041,10 +2041,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2041
2041
#undef INSN
2042
2042
2043
2043
// --------------------------
2044
- // fsd -> c.fsdsp/c.fsd
2045
2044
#define INSN (NAME ) \
2046
2045
void NAME (FloatRegister Rd, Register Rs, const int32_t offset) { \
2047
- if (check_rvc ()) { \
2046
+ /* fsd -> c.fsdsp/c.fsd */ \
2047
+ if (do_compress ()) { \
2048
2048
if (is_c_fldsdsp (Rs, offset)) { \
2049
2049
c_fsdsp (Rd, offset); \
2050
2050
return ; \
@@ -2063,11 +2063,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2063
2063
// --------------------------
2064
2064
// Conditional branch instructions
2065
2065
// --------------------------
2066
- // beq/bne -> c.beqz/c.bnez
2067
-
2068
2066
#define INSN (NAME, C_NAME, NORMAL_NAME ) \
2069
2067
void NAME (Register Rs1, Register Rs2, const int64_t offset) { \
2070
- if (check_rvc () && \
2068
+ /* beq/bne -> c.beqz/c.bnez */ \
2069
+ if (do_compress () && \
2071
2070
(offset != 0 && Rs2 == x0 && Rs1->is_compressed_valid () && \
2072
2071
is_imm_in_range (offset, 8 , 1 ))) { \
2073
2072
C_NAME (Rs1, offset); \
@@ -2084,10 +2083,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2084
2083
// --------------------------
2085
2084
// Unconditional branch instructions
2086
2085
// --------------------------
2087
- // jal -> c.j
2088
2086
#define INSN (NAME ) \
2089
2087
void NAME (Register Rd, const int32_t offset) { \
2090
- if (check_rvc () && offset != 0 && Rd == x0 && is_imm_in_range (offset, 11 , 1 )) { \
2088
+ /* jal -> c.j */ \
2089
+ if (do_compress () && offset != 0 && Rd == x0 && is_imm_in_range (offset, 11 , 1 )) { \
2091
2090
c_j (offset); \
2092
2091
return ; \
2093
2092
} \
@@ -2099,10 +2098,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2099
2098
#undef INSN
2100
2099
2101
2100
// --------------------------
2102
- // jalr -> c.jr/c.jalr
2103
2101
#define INSN (NAME ) \
2104
2102
void NAME (Register Rd, Register Rs, const int32_t offset) { \
2105
- if (check_rvc () && (offset == 0 && Rs != x0)) { \
2103
+ /* jalr -> c.jr/c.jalr */ \
2104
+ if (do_compress () && (offset == 0 && Rs != x0)) { \
2106
2105
if (Rd == x1) { \
2107
2106
c_jalr (Rs); \
2108
2107
return ; \
@@ -2121,10 +2120,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2121
2120
// --------------------------
2122
2121
// Miscellaneous Instructions
2123
2122
// --------------------------
2124
- // ebreak -> c.ebreak
2125
2123
#define INSN (NAME ) \
2126
2124
void NAME () { \
2127
- if (check_rvc ()) { \
2125
+ /* ebreak -> c.ebreak */ \
2126
+ if (do_compress ()) { \
2128
2127
c_ebreak (); \
2129
2128
return ; \
2130
2129
} \
@@ -2138,10 +2137,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2138
2137
// --------------------------
2139
2138
// Immediate Instructions
2140
2139
// --------------------------
2141
- // li -> c.li
2142
2140
#define INSN (NAME ) \
2143
2141
void NAME (Register Rd, int64_t imm) { \
2144
- if (check_rvc () && (is_imm_in_range (imm, 6 , 0 ) && Rd != x0)) { \
2142
+ /* li -> c.li */ \
2143
+ if (do_compress () && (is_imm_in_range (imm, 6 , 0 ) && Rd != x0)) { \
2145
2144
c_li (Rd, imm); \
2146
2145
return ; \
2147
2146
} \
@@ -2152,10 +2151,11 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2152
2151
2153
2152
#undef INSN
2154
2153
2155
- // addi -> c.addi/c.nop/c.mv/c.addi16sp/c.addi4spn.
2154
+ // --------------------------
2156
2155
#define INSN (NAME ) \
2157
2156
void NAME (Register Rd, Register Rs1, int32_t imm) { \
2158
- if (check_rvc ()) { \
2157
+ /* addi -> c.addi/c.nop/c.mv/c.addi16sp/c.addi4spn */ \
2158
+ if (do_compress ()) { \
2159
2159
if (Rd == Rs1 && is_imm_in_range (imm, 6 , 0 )) { \
2160
2160
c_addi (Rd, imm); \
2161
2161
return ; \
@@ -2180,10 +2180,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2180
2180
#undef INSN
2181
2181
2182
2182
// --------------------------
2183
- // addiw -> c.addiw
2184
2183
#define INSN (NAME ) \
2185
2184
void NAME (Register Rd, Register Rs1, int32_t imm) { \
2186
- if (check_rvc () && (Rd == Rs1 && Rd != x0 && is_imm_in_range (imm, 6 , 0 ))) { \
2185
+ /* addiw -> c.addiw */ \
2186
+ if (do_compress () && (Rd == Rs1 && Rd != x0 && is_imm_in_range (imm, 6 , 0 ))) { \
2187
2187
c_addiw (Rd, imm); \
2188
2188
return ; \
2189
2189
} \
@@ -2195,10 +2195,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2195
2195
#undef INSN
2196
2196
2197
2197
// --------------------------
2198
- // and_imm12 -> c.andi
2199
2198
#define INSN (NAME ) \
2200
2199
void NAME (Register Rd, Register Rs1, int32_t imm) { \
2201
- if (check_rvc () && \
2200
+ /* and_imm12 -> c.andi */ \
2201
+ if (do_compress () && \
2202
2202
(Rd == Rs1 && Rd->is_compressed_valid () && is_imm_in_range (imm, 6 , 0 ))) { \
2203
2203
c_andi (Rd, imm); \
2204
2204
return ; \
@@ -2213,10 +2213,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2213
2213
// --------------------------
2214
2214
// Shift Immediate Instructions
2215
2215
// --------------------------
2216
- // slli -> c.slli
2217
2216
#define INSN (NAME ) \
2218
2217
void NAME (Register Rd, Register Rs1, unsigned shamt) { \
2219
- if (check_rvc () && (Rd == Rs1 && Rd != x0 && shamt != 0 )) { \
2218
+ /* slli -> c.slli */ \
2219
+ if (do_compress () && (Rd == Rs1 && Rd != x0 && shamt != 0 )) { \
2220
2220
c_slli (Rd, shamt); \
2221
2221
return ; \
2222
2222
} \
@@ -2228,10 +2228,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2228
2228
#undef INSN
2229
2229
2230
2230
// --------------------------
2231
- // srai/srli -> c.srai/c.srli
2232
2231
#define INSN (NAME, C_NAME, NORMAL_NAME ) \
2233
2232
void NAME (Register Rd, Register Rs1, unsigned shamt) { \
2234
- if (check_rvc () && (Rd == Rs1 && Rd->is_compressed_valid () && shamt != 0 )) { \
2233
+ /* srai/srli -> c.srai/c.srli */ \
2234
+ if (do_compress () && (Rd == Rs1 && Rd->is_compressed_valid () && shamt != 0 )) { \
2235
2235
C_NAME (Rd, shamt); \
2236
2236
return ; \
2237
2237
} \
@@ -2246,10 +2246,10 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2246
2246
// --------------------------
2247
2247
// Upper Immediate Instruction
2248
2248
// --------------------------
2249
- // lui -> c.lui
2250
2249
#define INSN (NAME ) \
2251
2250
void NAME (Register Rd, int32_t imm) { \
2252
- if (check_rvc () && (Rd != x0 && Rd != x2 && imm != 0 && is_imm_in_range (imm, 18 , 0 ))) { \
2251
+ /* lui -> c.lui */ \
2252
+ if (do_compress () && (Rd != x0 && Rd != x2 && imm != 0 && is_imm_in_range (imm, 18 , 0 ))) { \
2253
2253
c_lui (Rd, imm); \
2254
2254
return ; \
2255
2255
} \
@@ -2262,7 +2262,8 @@ enum operand_size { int8, int16, int32, uint32, int64 };
2262
2262
2263
2263
#define INSN (NAME ) \
2264
2264
void NAME () { \
2265
- if (check_rvc ()) { \
2265
+ /* The illegal instruction in RVC is presented by a 16-bit 0. */ \
2266
+ if (do_compress ()) { \
2266
2267
emit_int16 (0 ); \
2267
2268
return ; \
2268
2269
} \
0 commit comments