flopz.util package
Submodules
flopz.util.integer_representation module
- build_immediates(val, specs)
Builds immediates for encoding offsets etc in riscv instructions.
Riscv offsets come with specifications like “offset[11|4|9:8|10|6|7|3:1|5]”, This method takes the “[11|4|9:8|10|6|7|3:1|5]” part as a spec string and will return the encoded result as an integer representation. Providing multiple specs is possible (as the offset is often split into multiple immediates).
- Parameters
val (int) – The value (offset) that is to be encoded in the immediate(s).
specs (Union[str, List[str]]) – The spec strings copied from the official riscv documentation for the implemented instruction.
- Returns
- A list of the integers representing the offsets immediate encoding(s).
These can be given to the instructions operands.
- Return type
List[int]
- representable(val, bits, signed=True, shift=0)
Checks if the value is representable with the given number of bits
Will return True if it is possible to encode the value in ‘val’ with the number of bits given in ‘bits’. Additionally, it can be specified if a sign has to be encoded or if the value can be rightshifted before encoding. If encoding the value is not possible, the function will return False.
- Parameters
val (int) – The value to be encoded.
bits (int) – The amount of bits available for encoding.
signed (bool) – Does the encoding include a sign or can we encode the unsigned value.
shift (int) – By which amount is the value supposed to be rightshifted before encoding.
- Returns
Can the value be encoded with the given bits and parameters.
- Return type
bool
flopz.util.parsing module
- get_bytes_from_hex_str(s)
- Parameters
s (
str
) –- Return type
bytes
- get_int_from_str(number)
- Parameters
number (
str
) – a string containing an integer, in hex (0x prefix) or decimal format- Return type
int
- Returns
parsed integer