conversion
Modules
IntToBool
module IntToBool {
interface IntToBool : int#(FROM: 0, TO: 2) i'0 -> bool o'0
}Converts a ‘0’ or ‘1’ into the equivalent boolean ‘false’ or ‘true’ respectively
BoolToInt
module BoolToInt {
interface BoolToInt : bool i'0 -> int#(FROM: 0, TO: 2) o'0
}Converts a ‘false’ or ‘true’ into the equivalent integer ‘0’ or ‘1’ respectively
IntToBits #(int NUM_BITS)
module IntToBits #(int NUM_BITS) {
interface IntToBits : int #(FROM: -pow2 #(E: NUM_BITS - 1), TO: pow2 #(E: NUM_BITS - 1)) value'0 -> bool[NUM_BITS] bits'0
}Convert signed int to 2s complement bits. (bits[0] is value’s Least Significant Bit)
Requires -pow2 #(E: NUM_BITS - 1) <= value < pow2 #(E: NUM_BITS - 1)
Runtime equivalent of IntToBitsGen
UIntToBits #(int NUM_BITS)
module UIntToBits #(int NUM_BITS) {
interface UIntToBits : int #(FROM: 0, TO: pow2 #(E: NUM_BITS)) value'0 -> bool[NUM_BITS] bits'0
}Convert int to unsigned bits. (bits[0] is value’s Least Significant Bit)
Requires 0 <= value < pow2 #(E: NUM_BITS)
Runtime equivalent of UIntToBitsGen
BitsToInt #(int NUM_BITS)
module BitsToInt #(int NUM_BITS) {
interface BitsToInt : bool[NUM_BITS] bits'0 -> int #(FROM: -pow2 #(E: NUM_BITS - 1), TO: pow2 #(E: NUM_BITS - 1)) value'0
}Convert 2s complement bits to a signed int. (bits[0] is value’s Least Significant Bit)
Creates an int in the range -pow2 #(E: NUM_BITS - 1) <= value < pow2 #(E: NUM_BITS - 1)
Runtime equivalent of BitsToIntGen
BitsToUInt #(int NUM_BITS)
module BitsToUInt #(int NUM_BITS) {
interface BitsToUInt : bool[NUM_BITS] bits'0 -> int #(FROM: 0, TO: pow2 #(E: NUM_BITS)) value'0
}Convert unsigned bits to an unsigned int. (bits[0] is value’s Least Significant Bit)
Creates an int in the range 0 <= value < pow2 #(E: NUM_BITS)
Runtime equivalent of BitsToUIntGen
ToBits #(T)
module ToBits #(T) {
interface ToBits : T value'0 -> bool[sizeof #(T)] bits'0
}Bitwise conversion of type T to a sizeof#(T)-bit bitset.
FromBits #(T)
module FromBits #(T) {
interface FromBits : bool[sizeof #(T)] bits'0 -> T value'0
}Bitwise conversion of a sizeof#(T)-bit bitset to type T.
Transmute #(T1, T2)
module Transmute #(T1, T2) {
interface Transmute : T1 a'0 -> T2 b'0
}Bitwise conversion of T1 into T2.
Requires:
sizeof#(T: type T1) == sizeof#(T: type T2)
Compile-Time Functions
IntToBitsGen #(int NUM_BITS, int V)
const bool[NUM_BITS] IntToBitsGen #(int NUM_BITS, int V)Convert gen int to 2s complement bits. (RESULT[0] is V’s Least Significant Bit)
Requires -pow2 #(E: NUM_BITS - 1) <= V < pow2 #(E: NUM_BITS - 1)
Generative equivalent of IntToBits
UIntToBitsGen #(int NUM_BITS, int V)
const bool[NUM_BITS] UIntToBitsGen #(int NUM_BITS, int V)Convert gen int to unsigned bits. (RESULT[0] is V’s Least Significant Bit)
Requires 0 <= V < pow2 #(E: NUM_BITS)
Generative equivalent of UIntToBits
BitsToIntGen #(int NUM_BITS, bool[NUM_BITS] BITS)
const int BitsToIntGen #(int NUM_BITS, bool[NUM_BITS] BITS)Convert gen 2s complement bits to a gen signed int. (BITS[0] is V’s Least Significant Bit)
Creates an int in the range -pow2 #(E: NUM_BITS - 1) <= value < pow2 #(E: NUM_BITS - 1)
Generative equivalent of BitsToInt
BitsToUIntGen #(int NUM_BITS, bool[NUM_BITS] BITS)
const int BitsToUIntGen #(int NUM_BITS, bool[NUM_BITS] BITS)Convert gen unsigned bits to a gen unsigned int. (BITS[0] is V’s Least Significant Bit)
Creates an int in the range 0 <= value < pow2 #(E: NUM_BITS)
Generative equivalent of BitsToUInt