BitPack type class: Proves a type α can be converted to/from a BitVec of width n.
This is essential for hardware synthesis, as all values must ultimately be representable as bit patterns.
Laws (not enforced, but expected):
- toBitVec (fromBitVec bv) = bv (round-trip property)
- fromBitVec (toBitVec x) = x (round-trip property)
Instances
@[inline]
Convert a value to its bit vector representation
Instances For
@[inline]
Convert a bit vector to its value representation
Instances For
BitPack instance for UInt8 (8 bits)
Equations
- Sparkle.Data.BitPack.instBitPackUInt8OfNatNat = { toBitVec := fun (n : UInt8) => BitVec.ofNat 8 n.toNat, fromBitVec := fun (bv : BitVec 8) => UInt8.ofNat bv.toNat }
BitPack instance for UInt16 (16 bits)
Equations
- Sparkle.Data.BitPack.instBitPackUInt16OfNatNat = { toBitVec := fun (n : UInt16) => BitVec.ofNat 16 n.toNat, fromBitVec := fun (bv : BitVec 16) => UInt16.ofNat bv.toNat }
BitPack instance for UInt32 (32 bits)
Equations
- Sparkle.Data.BitPack.instBitPackUInt32OfNatNat = { toBitVec := fun (n : UInt32) => BitVec.ofNat 32 n.toNat, fromBitVec := fun (bv : BitVec 32) => UInt32.ofNat bv.toNat }
BitPack instance for UInt64 (64 bits)
Equations
- Sparkle.Data.BitPack.instBitPackUInt64OfNatNat = { toBitVec := fun (n : UInt64) => BitVec.ofNat 64 n.toNat, fromBitVec := fun (bv : BitVec 64) => UInt64.ofNat bv.toNat }
Helper to get the bit width of a type with BitPack instance
Equations
Instances For
Test if a value round-trips correctly through BitPack
Equations
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
BitPack instance for RGB (24 bits total)
Equations
- One or more equations did not get rendered due to their size.
Example RGB value