Operations on bits
The Bits type supports a subset of operations that can be synthesized in hardware. You can perform
Addition between
Bitsof the same size using the+operatorSubtraction between
Bitsof the same size using the-operatorBitwise logical
ANDbetweenBitsof the same size using the&operatorBitwise logical
ORbetweenBitsof the same size using the|operatorBitwise logical
XOR(Exclusive Or) betweenBitsof the same size using the^operatorBitwise comparisons for equality between
Bitsof the same size using==and!=operatorsUnsigned comparisons (e.g.,
>,>=,<,<=) betweenBitsof the same size - these are always treated as unsigned values for comparison purposes.Shift left using the
<<operatorShift right (no sign extension!) using the '>>' operator
Bitwise logical
NOTusing the!prefix operatorThese should feel natural when using RustHDL, as expressions follow Rust's rules (and not Verilog's). For example:
# use rust_hdl::prelude::*;
let x: Bits<32> = 0xDEAD_0000_u32.to_bits();
let y: Bits<32> = 0x0000_BEEF_u32.to_bits();
let z = x + y;
assert_eq!(z, 0xDEAD_BEEF_u32.to_bits());You can, of course, construct expressions of arbitrary complexity using parenthesis, etc. The only real surprise may be at synthesis time, when you try to fit the expression onto hardware.