asmkit/riscv/
mod.rs

1pub mod assembler;
2pub mod emitter;
3pub mod opcodes;
4pub mod operands;
5pub mod decode;
6pub mod formatter;
7
8pub use crate::core::operand::imm;
9pub use assembler::*;
10pub use emitter::EmitterExplicit;
11pub use opcodes::{Inst, InstructionValue, Opcode};
12pub use operands::*;
13pub use regs::*;
14
15/// Return the length (in bytes) of an instruction given the low 16 bits of it.
16///
17/// The current spec reserves a bit pattern for instructions of length >= 192 bits, but for
18/// simplicity this function just returns 24 in that case. The largest instructions currently
19/// defined are 4 bytes so it will likely be a long time until this diffence matters.
20pub fn instruction_length(i: u16) -> usize {
21    if i & 0b11 != 0b11 {
22        2
23    } else if i & 0b11100 != 0b11100 {
24        4
25    } else if i & 0b111111 == 0b011111 {
26        6
27    } else if i & 0b1111111 == 0b011111 {
28        8
29    } else {
30        10 + 2 * ((i >> 12) & 0b111) as usize
31    }
32}