ab_riscv_primitives/instructions/rv32/c/zca.rs
1//! RV32 Zca extension
2
3#[cfg(test)]
4mod tests;
5
6use crate::instructions::Instruction;
7use crate::instructions::utils::I24;
8use crate::registers::general_purpose::Register;
9use ab_riscv_macros::instruction;
10use core::fmt;
11
12/// RISC-V RV32 Zca compressed instruction set
13#[instruction]
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15#[rustfmt::skip]
16pub enum Rv32ZcaInstruction<Reg> {
17 // Quadrant 00
18 /// C.ADDI4SPN rd' = sp + nzuimm (nzuimm != 0)
19 CAddi4spn { rd: Reg, nzuimm: u16 },
20 /// C.LW rd' = sext(mem32\[rs1' + uimm])
21 CLw { rd: Reg, rs1: Reg, uimm: u8 },
22 /// C.SW mem32\[rs1' + uimm] = rs2'
23 CSw { rs1: Reg, rs2: Reg, uimm: u8 },
24
25 // Quadrant 01
26 /// C.NOP (ADDI x0, x0, 0 with rd==x0 and nzimm==0)
27 CNop,
28 /// C.ADDI rd += nzimm (rd != x0)
29 CAddi { rd: Reg, nzimm: i8 },
30 /// C.JAL ra = pc+2; pc += imm
31 CJal { imm: i16 },
32 /// C.LI rd = sext(imm) (rd=x0 is a HINT)
33 CLi { rd: Reg, imm: i8 },
34 /// C.ADDI16SP sp += nzimm (nzimm != 0)
35 CAddi16sp { nzimm: i16 },
36 /// C.LUI rd = sext(nzimm << 12) (rd != x0, rd != x2, nzimm != 0)
37 CLui { rd: Reg, nzimm: I24 },
38 /// C.SRLI rd' >>= shamt (logical, 5-bit shamt; shamt=0 is a HINT)
39 CSrli { rd: Reg, shamt: u8 },
40 /// C.SRAI rd' >>= shamt (arithmetic, 5-bit shamt; shamt=0 is a HINT)
41 CSrai { rd: Reg, shamt: u8 },
42 /// C.ANDI rd' &= sext(imm)
43 CAndi { rd: Reg, imm: i8 },
44 /// C.SUB rd' -= rs2'
45 CSub { rd: Reg, rs2: Reg },
46 /// C.XOR rd' ^= rs2'
47 CXor { rd: Reg, rs2: Reg },
48 /// C.OR rd' |= rs2'
49 COr { rd: Reg, rs2: Reg },
50 /// C.AND rd' &= rs2'
51 CAnd { rd: Reg, rs2: Reg },
52 /// C.J pc += sext(imm)
53 CJ { imm: i16 },
54 /// C.BEQZ if rs1' == 0: pc += sext(imm)
55 CBeqz { rs1: Reg, imm: i16 },
56 /// C.BNEZ if rs1' != 0: pc += sext(imm)
57 CBnez { rs1: Reg, imm: i16 },
58
59 // Quadrant 10
60 /// C.SLLI rd <<= shamt (5-bit shamt; rd=x0 or shamt=0 is a HINT)
61 CSlli { rd: Reg, shamt: u8 },
62 /// C.LWSP rd = sext(mem32\[sp + uimm]) (rd != x0)
63 CLwsp { rd: Reg, uimm: u8 },
64 /// C.JR pc = rs1 (rs1 != x0)
65 CJr { rs1: Reg },
66 /// C.MV rd = rs2 (rs2 != x0; rd=x0 is a HINT)
67 CMv { rd: Reg, rs2: Reg },
68 /// C.EBREAK
69 CEbreak,
70 /// C.JALR ra = pc+2; pc = rs1 (rs1 != x0)
71 CJalr { rs1: Reg },
72 /// C.ADD rd += rs2 (rs2 != x0; rd=x0 is a HINT)
73 CAdd { rd: Reg, rs2: Reg },
74 /// C.SWSP mem32\[sp + uimm] = rs2
75 CSwsp { rs2: Reg, uimm: u8 },
76
77 // Unimplemented/illegal
78 CUnimp,
79}
80
81#[instruction]
82const impl<Reg> Instruction for Rv32ZcaInstruction<Reg>
83where
84 Reg: [const] Register<Type = u32>,
85{
86 type Reg = Reg;
87
88 #[inline(always)]
89 #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
90 fn try_decode(instruction: u32) -> Option<Self> {
91 /// Map a 3-bit "prime" register field to an absolute register number
92 #[inline(always)]
93 const fn prime_reg_bits(bits: u8) -> u8 {
94 bits + 8
95 }
96
97 /// Reconstruct the CB-type branch offset used by C.BEQZ / C.BNEZ.
98 ///
99 /// Bit layout in the 16-bit instruction word:
100 /// ```text
101 /// imm[8] = inst[12]
102 /// imm[4:3] = inst[11:10]
103 /// imm[7:6] = inst[6:5]
104 /// imm[2:1] = inst[4:3]
105 /// imm[5] = inst[2]
106 /// imm[0] is always 0 (2-byte aligned).
107 /// ```
108 #[inline(always)]
109 const fn decode_cb_branch_imm(inst: u16) -> i16 {
110 let imm8 = ((inst >> 12u8) & 1).cast_signed();
111 let imm4_3 = ((inst >> 10u8) & 0b11).cast_signed();
112 let imm7_6 = ((inst >> 5u8) & 0b11).cast_signed();
113 let imm2_1 = ((inst >> 3u8) & 0b11).cast_signed();
114 let imm5 = ((inst >> 2u8) & 1).cast_signed();
115 let raw =
116 (imm8 << 8u8) | (imm7_6 << 6u8) | (imm5 << 5u8) | (imm4_3 << 3u8) | (imm2_1 << 1u8);
117 // Sign-extend from bit 8 (9-bit immediate -> i16)
118 (raw << 7u8) >> 7u8
119 }
120
121 /// Decode CJ-type jump offset (C.J / C.JAL).
122 ///
123 /// Bit layout:
124 /// ```text
125 /// imm[11] = inst[12]
126 /// imm[4] = inst[11]
127 /// imm[9:8] = inst[10:9]
128 /// imm[10] = inst[8]
129 /// imm[6] = inst[7]
130 /// imm[7] = inst[6]
131 /// imm[3:1] = inst[5:3]
132 /// imm[5] = inst[2]
133 /// imm[0] is always 0 (2-byte aligned).
134 /// ```
135 #[inline(always)]
136 const fn decode_cj_imm(inst: u16) -> i16 {
137 let imm11 = ((inst >> 12u8) & 1).cast_signed();
138 let imm4 = ((inst >> 11u8) & 1).cast_signed();
139 let imm9_8 = ((inst >> 9u8) & 0b11).cast_signed();
140 let imm10 = ((inst >> 8u8) & 1).cast_signed();
141 let imm6 = ((inst >> 7u8) & 1).cast_signed();
142 let imm7 = ((inst >> 6u8) & 1).cast_signed();
143 let imm3_1 = ((inst >> 3u8) & 0b111).cast_signed();
144 let imm5 = ((inst >> 2u8) & 1).cast_signed();
145 let raw = (imm11 << 11u8)
146 | (imm10 << 10u8)
147 | (imm9_8 << 8u8)
148 | (imm7 << 7u8)
149 | (imm6 << 6u8)
150 | (imm5 << 5u8)
151 | (imm4 << 4u8)
152 | (imm3_1 << 1u8);
153 // Sign-extend from bit 11 (12-bit immediate -> i16)
154 (raw << 4u8) >> 4u8
155 }
156
157 let inst = instruction as u16;
158 let quadrant = inst & 0b11;
159 let funct3 = ((inst >> 13u8) & 0b111) as u8;
160
161 match quadrant {
162 // Quadrant 00
163 0b00 => match funct3 {
164 // C.ADDI4SPN
165 // nzuimm[5:4] = inst[12:11]
166 // nzuimm[9:6] = inst[10:7]
167 // nzuimm[2] = inst[6]
168 // nzuimm[3] = inst[5]
169 0b000 => {
170 let imm5_4 = (inst >> 11u8) & 0b11;
171 let imm9_6 = (inst >> 7u8) & 0xf;
172 let imm2 = (inst >> 6u8) & 1;
173 let imm3 = (inst >> 5u8) & 1;
174 let nzuimm = (imm9_6 << 6u8) | (imm5_4 << 4u8) | (imm3 << 3u8) | (imm2 << 2u8);
175 if nzuimm == 0 {
176 if inst == 0 {
177 Some(Self::CUnimp)
178 } else {
179 // Reserved encoding
180 None
181 }
182 } else {
183 let rd_bits = prime_reg_bits(((inst >> 2u8) & 0b111) as u8);
184 let rd = Reg::from_bits(rd_bits)?;
185 Some(Self::CAddi4spn { rd, nzuimm })
186 }
187 }
188 // C.LW
189 // uimm[5:3] = inst[12:10], uimm[2] = inst[6], uimm[6] = inst[5]
190 0b010 => {
191 let uimm5_3 = ((inst >> 10u8) & 0b111) as u8;
192 let uimm2 = ((inst >> 6u8) & 1) as u8;
193 let uimm6 = ((inst >> 5u8) & 1) as u8;
194 let uimm = (uimm6 << 6u8) | (uimm5_3 << 3u8) | (uimm2 << 2u8);
195 let rs1_bits = prime_reg_bits(((inst >> 7u8) & 0b111) as u8);
196 let rd_bits = prime_reg_bits(((inst >> 2u8) & 0b111) as u8);
197 let rs1 = Reg::from_bits(rs1_bits)?;
198 let rd = Reg::from_bits(rd_bits)?;
199 Some(Self::CLw { rd, rs1, uimm })
200 }
201 // C.SW (same uimm layout as C.LW)
202 0b110 => {
203 let uimm5_3 = ((inst >> 10u8) & 0b111) as u8;
204 let uimm2 = ((inst >> 6u8) & 1) as u8;
205 let uimm6 = ((inst >> 5u8) & 1) as u8;
206 let uimm = (uimm6 << 6u8) | (uimm5_3 << 3u8) | (uimm2 << 2u8);
207 let rs1_bits = prime_reg_bits(((inst >> 7u8) & 0b111) as u8);
208 let rs2_bits = prime_reg_bits(((inst >> 2u8) & 0b111) as u8);
209 let rs1 = Reg::from_bits(rs1_bits)?;
210 let rs2 = Reg::from_bits(rs2_bits)?;
211 Some(Self::CSw { rs1, rs2, uimm })
212 }
213 // funct3=001: C.FLD (Zcd) - not in Zca, reserved
214 // funct3=011: C.FLD (Zcd) - not in Zca, reserved
215 // funct3=100: used by Zcb
216 // funct3=101: C.FSD (Zcd) - not in Zca, reserved
217 // funct3=111: C.FSD (Zcd) - not in Zca, reserved
218 _ => None,
219 },
220
221 // Quadrant 01
222 0b01 => match funct3 {
223 // C.NOP (rd=x0) / C.ADDI (rd!=x0)
224 // nzimm[5] = inst[12], nzimm[4:0] = inst[6:2]
225 0b000 => {
226 let rd_bits = ((inst >> 7u8) & 0x1f) as u8;
227 let imm5 = ((inst >> 12u8) & 1) as u8;
228 let imm4_0 = ((inst >> 2u8) & 0x1f) as u8;
229 let imm_raw = (imm5 << 5u8) | imm4_0;
230 // Sign-extend 6-bit immediate to i8
231 let nzimm = ((imm_raw.cast_signed()) << 2u8) >> 2u8;
232 if rd_bits == 0 && nzimm == 0 {
233 Some(Self::CNop)
234 } else {
235 let rd = Reg::from_bits(rd_bits)?;
236 Some(Self::CAddi { rd, nzimm })
237 }
238 }
239 // C.JAL (same CJ immediate encoding as C.J)
240 0b001 => Some(Self::CJal {
241 imm: decode_cj_imm(inst),
242 }),
243 // C.LI rd = sext(imm) (rd=x0 is a HINT, still decoded)
244 // imm[5] = inst[12], imm[4:0] = inst[6:2]
245 0b010 => {
246 let rd_bits = ((inst >> 7u8) & 0x1f) as u8;
247 let rd = Reg::from_bits(rd_bits)?;
248 let imm5 = ((inst >> 12u8) & 1) as u8;
249 let imm4_0 = ((inst >> 2u8) & 0x1f) as u8;
250 let imm_raw = (imm5 << 5u8) | imm4_0;
251 let imm = ((imm_raw.cast_signed()) << 2u8) >> 2u8;
252 Some(Self::CLi { rd, imm })
253 }
254 // C.ADDI16SP (rd=x2) / C.LUI (rd!=x0, rd!=x2)
255 0b011 => {
256 let rd_bits = ((inst >> 7u8) & 0x1f) as u8;
257 if rd_bits == 2 {
258 // C.ADDI16SP
259 // nzimm[9] = inst[12]
260 // nzimm[4] = inst[6]
261 // nzimm[6] = inst[5]
262 // nzimm[8:7] = inst[4:3]
263 // nzimm[5] = inst[2]
264 let imm9 = ((inst >> 12u8) & 1).cast_signed();
265 let imm4 = ((inst >> 6u8) & 1).cast_signed();
266 let imm6 = ((inst >> 5u8) & 1).cast_signed();
267 let imm8_7 = ((inst >> 3u8) & 0b11).cast_signed();
268 let imm5 = ((inst >> 2u8) & 1).cast_signed();
269 let raw = (imm9 << 9u8)
270 | (imm8_7 << 7u8)
271 | (imm6 << 6u8)
272 | (imm5 << 5u8)
273 | (imm4 << 4u8);
274 if raw == 0 {
275 None?;
276 }
277 // Sign-extend from bit 9 (10-bit nzimm -> i16)
278 let nzimm = (raw << 6u8) >> 6u8;
279 Some(Self::CAddi16sp { nzimm })
280 } else {
281 // C.LUI (rd=x0 is a hint, still decoded)
282 let rd = Reg::from_bits(rd_bits)?;
283 // nzimm[17] = inst[12]
284 // nzimm[16:12] = inst[6:2]
285 let imm17 = ((inst >> 12u8) & 1) as i32;
286 let imm16_12 = ((inst >> 2u8) & 0x1f) as i32;
287 let raw = (imm17 << 17u8) | (imm16_12 << 12u8);
288 if raw == 0 {
289 None?;
290 }
291 // Sign-extend from bit 17 (18-bit nzimm -> i32)
292 let nzimm = I24::from_i32((raw << 14u8) >> 14u8);
293 Some(Self::CLui { rd, nzimm })
294 }
295 }
296 // C.SRLI / C.SRAI / C.ANDI / arithmetic
297 // RV32: shamt is 5-bit only (inst[12] must be 0 for shifts, else reserved)
298 0b100 => {
299 let funct2 = ((inst >> 10u8) & 0b11) as u8;
300 let rd_bits = prime_reg_bits(((inst >> 7u8) & 0b111) as u8);
301 match funct2 {
302 // C.SRLI shamt[4:0]=inst[6:2]
303 // RV32: shamt[5]=inst[12] must be 0, else reserved (NSE)
304 // shamt=0 is a HINT, still decoded
305 0b00 => {
306 let rd = Reg::from_bits(rd_bits)?;
307 let shamt5 = ((inst >> 12u8) & 1) as u8;
308 let shamt40 = ((inst >> 2u8) & 0x1f) as u8;
309 if shamt5 != 0 {
310 None?;
311 }
312 Some(Self::CSrli { rd, shamt: shamt40 })
313 }
314 // C.SRAI (same shamt layout as C.SRLI)
315 // RV32: shamt[5]=inst[12] must be 0, else reserved (NSE)
316 // shamt=0 is a HINT, still decoded
317 0b01 => {
318 let rd = Reg::from_bits(rd_bits)?;
319 let shamt5 = ((inst >> 12u8) & 1) as u8;
320 let shamt40 = ((inst >> 2u8) & 0x1f) as u8;
321 if shamt5 != 0 {
322 None?;
323 }
324 Some(Self::CSrai { rd, shamt: shamt40 })
325 }
326 // C.ANDI imm[5]=inst[12], imm[4:0]=inst[6:2]
327 0b10 => {
328 let rd = Reg::from_bits(rd_bits)?;
329 let imm5 = ((inst >> 12u8) & 1) as u8;
330 let imm4_0 = ((inst >> 2u8) & 0x1f) as u8;
331 let imm_raw = (imm5 << 5u8) | imm4_0;
332 let imm = ((imm_raw.cast_signed()) << 2u8) >> 2u8;
333 Some(Self::CAndi { rd, imm })
334 }
335 // Arithmetic: only bit12=0 variants valid in RV32
336 // bit12=1 (C.SUBW/C.ADDW) does not exist in RV32, reserved
337 0b11 => {
338 let bit12 = (inst >> 12u8) & 1;
339 if bit12 != 0 {
340 None?;
341 }
342 let funct2b = ((inst >> 5u8) & 0b11) as u8;
343 let rs2_bits = prime_reg_bits(((inst >> 2u8) & 0b111) as u8);
344 let rd = Reg::from_bits(rd_bits)?;
345 let rs2 = Reg::from_bits(rs2_bits)?;
346 match funct2b {
347 0b00 => Some(Self::CSub { rd, rs2 }),
348 0b01 => Some(Self::CXor { rd, rs2 }),
349 0b10 => Some(Self::COr { rd, rs2 }),
350 0b11 => Some(Self::CAnd { rd, rs2 }),
351 _ => None,
352 }
353 }
354 _ => None,
355 }
356 }
357 // C.J
358 0b101 => Some(Self::CJ {
359 imm: decode_cj_imm(inst),
360 }),
361 // C.BEQZ
362 0b110 => {
363 let rs1_bits = prime_reg_bits(((inst >> 7u8) & 0b111) as u8);
364 let rs1 = Reg::from_bits(rs1_bits)?;
365 Some(Self::CBeqz {
366 rs1,
367 imm: decode_cb_branch_imm(inst),
368 })
369 }
370 // C.BNEZ
371 0b111 => {
372 let rs1_bits = prime_reg_bits(((inst >> 7u8) & 0b111) as u8);
373 let rs1 = Reg::from_bits(rs1_bits)?;
374 Some(Self::CBnez {
375 rs1,
376 imm: decode_cb_branch_imm(inst),
377 })
378 }
379 _ => None,
380 },
381
382 // Quadrant 10
383 0b10 => match funct3 {
384 // C.SLLI shamt[4:0]=inst[6:2]
385 // RV32: shamt[5]=inst[12] must be 0, else reserved (NSE)
386 // rd=x0 or shamt=0 is a HINT, still decoded
387 0b000 => {
388 let rd_bits = ((inst >> 7u8) & 0x1f) as u8;
389 let rd = Reg::from_bits(rd_bits)?;
390 let shamt5 = ((inst >> 12u8) & 1) as u8;
391 let shamt40 = ((inst >> 2u8) & 0x1f) as u8;
392 if shamt5 != 0 {
393 None?;
394 }
395 Some(Self::CSlli { rd, shamt: shamt40 })
396 }
397 // C.LWSP uimm[5]=inst[12], uimm[4:2]=inst[6:4], uimm[7:6]=inst[3:2]
398 // rd=x0 is reserved
399 0b010 => {
400 let rd_bits = ((inst >> 7u8) & 0x1f) as u8;
401 if rd_bits == 0 {
402 None?;
403 }
404 let rd = Reg::from_bits(rd_bits)?;
405 let uimm5 = ((inst >> 12u8) & 1) as u8;
406 let uimm42 = ((inst >> 4u8) & 0b111) as u8;
407 let uimm76 = ((inst >> 2u8) & 0b11) as u8;
408 let uimm = (uimm76 << 6u8) | (uimm5 << 5u8) | (uimm42 << 2u8);
409 Some(Self::CLwsp { rd, uimm })
410 }
411 // funct3=001: C.FLWSP (Zcf, not Zca) - reserved
412 // funct3=011: C.FLDSP (Zcd, not Zca) - reserved
413 // C.JR / C.MV / C.EBREAK / C.JALR / C.ADD
414 0b100 => {
415 let rs1_bits = ((inst >> 7u8) & 0x1f) as u8;
416 let rs2_bits = ((inst >> 2u8) & 0x1f) as u8;
417 let bit12 = (inst >> 12u8) & 1;
418 if bit12 == 0 {
419 if rs2_bits == 0 {
420 // C.JR (rs1=x0 is reserved)
421 if rs1_bits == 0 {
422 None?;
423 }
424 let rs1 = Reg::from_bits(rs1_bits)?;
425 Some(Self::CJr { rs1 })
426 } else {
427 // C.MV (rs2!=x0; rd=x0 is a HINT, still decoded)
428 let rd = Reg::from_bits(rs1_bits)?;
429 let rs2 = Reg::from_bits(rs2_bits)?;
430 Some(Self::CMv { rd, rs2 })
431 }
432 } else if rs2_bits == 0 {
433 if rs1_bits == 0 {
434 // C.EBREAK
435 Some(Self::CEbreak)
436 } else {
437 // C.JALR (rs1!=x0)
438 let rs1 = Reg::from_bits(rs1_bits)?;
439 Some(Self::CJalr { rs1 })
440 }
441 } else {
442 // C.ADD (rs2!=x0; rd=x0 is a HINT, still decoded)
443 let rd = Reg::from_bits(rs1_bits)?;
444 let rs2 = Reg::from_bits(rs2_bits)?;
445 Some(Self::CAdd { rd, rs2 })
446 }
447 }
448 // C.SWSP uimm[5:2]=inst[12:9], uimm[7:6]=inst[8:7]
449 0b110 => {
450 let rs2_bits = ((inst >> 2u8) & 0x1f) as u8;
451 let rs2 = Reg::from_bits(rs2_bits)?;
452 let uimm52 = ((inst >> 9u8) & 0xf) as u8;
453 let uimm76 = ((inst >> 7u8) & 0b11) as u8;
454 let uimm = (uimm76 << 6u8) | (uimm52 << 2u8);
455 Some(Self::CSwsp { rs2, uimm })
456 }
457 // funct3=111: C.FSWSP (Zcf, not Zca) - reserved
458 _ => None,
459 },
460
461 // Quadrant 11 = 32-bit instructions
462 _ => None,
463 }
464 }
465
466 #[inline(always)]
467 fn alignment() -> u8 {
468 align_of::<u16>() as u8
469 }
470
471 #[inline(always)]
472 fn size(&self) -> u8 {
473 size_of::<u16>() as u8
474 }
475}
476
477#[instruction]
478impl<Reg> fmt::Display for Rv32ZcaInstruction<Reg>
479where
480 Reg: fmt::Display,
481{
482 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
483 match self {
484 Self::CAddi4spn { rd, nzuimm } => write!(f, "c.addi4spn {rd}, sp, {nzuimm}"),
485 Self::CLw { rd, rs1, uimm } => write!(f, "c.lw {rd}, {uimm}({rs1})"),
486 Self::CSw { rs1, rs2, uimm } => write!(f, "c.sw {rs2}, {uimm}({rs1})"),
487 Self::CNop => write!(f, "c.nop"),
488 Self::CAddi { rd, nzimm } => write!(f, "c.addi {rd}, {nzimm}"),
489 Self::CJal { imm } => write!(f, "c.jal {imm}"),
490 Self::CLi { rd, imm } => write!(f, "c.li {rd}, {imm}"),
491 Self::CAddi16sp { nzimm } => write!(f, "c.addi16sp sp, {nzimm}"),
492 Self::CLui { rd, nzimm } => write!(f, "c.lui {rd}, 0x{:x}", nzimm >> 12u8),
493 Self::CSrli { rd, shamt } => write!(f, "c.srli {rd}, {shamt}"),
494 Self::CSrai { rd, shamt } => write!(f, "c.srai {rd}, {shamt}"),
495 Self::CAndi { rd, imm } => write!(f, "c.andi {rd}, {imm}"),
496 Self::CSub { rd, rs2 } => write!(f, "c.sub {rd}, {rs2}"),
497 Self::CXor { rd, rs2 } => write!(f, "c.xor {rd}, {rs2}"),
498 Self::COr { rd, rs2 } => write!(f, "c.or {rd}, {rs2}"),
499 Self::CAnd { rd, rs2 } => write!(f, "c.and {rd}, {rs2}"),
500 Self::CJ { imm } => write!(f, "c.j {imm}"),
501 Self::CBeqz { rs1, imm } => write!(f, "c.beqz {rs1}, {imm}"),
502 Self::CBnez { rs1, imm } => write!(f, "c.bnez {rs1}, {imm}"),
503 Self::CSlli { rd, shamt } => write!(f, "c.slli {rd}, {shamt}"),
504 Self::CLwsp { rd, uimm } => write!(f, "c.lwsp {rd}, {uimm}(sp)"),
505 Self::CJr { rs1 } => write!(f, "c.jr {rs1}"),
506 Self::CMv { rd, rs2 } => write!(f, "c.mv {rd}, {rs2}"),
507 Self::CEbreak => write!(f, "c.ebreak"),
508 Self::CJalr { rs1 } => write!(f, "c.jalr {rs1}"),
509 Self::CAdd { rd, rs2 } => write!(f, "c.add {rd}, {rs2}"),
510 Self::CSwsp { rs2, uimm } => write!(f, "c.swsp {rs2}, {uimm}(sp)"),
511 Self::CUnimp => write!(f, "c.unimp"),
512 }
513 }
514}