Skip to main content

hdl_cat_std/
lib.rs

1//! Standard components built from `hdl-cat-circuit` primitives
2//! and `hdl-cat-sync` state machinery.
3//!
4//! # Component catalogue
5//!
6//! | Component | Shape | Summary |
7//! |---|---|---|
8//! | [`half_adder`] | `CircuitArrow<bool⊗bool, bool⊗bool>` | `(a, b) → (sum, carry)` |
9//! | [`full_adder`] | `CircuitArrow<(bool⊗bool)⊗bool, bool⊗bool>` | `(a, b, cin) → (sum, cout)` |
10//! | [`counter()`] | `Sync<Obj<Bits<N>>, CircuitUnit, Obj<Bits<N>>>` | `state + 1` each cycle |
11//! | [`down_counter()`] | `Sync<Obj<Bits<N>>, CircuitUnit, Obj<Bits<N>>>` | `state - 1` each cycle |
12//! | [`accumulator()`] | `Sync<Obj<Bits<N>>, Obj<Bits<N>>, Obj<Bits<N>>>` | `state + input` each cycle |
13//! | [`toggle_ff`] | `Sync<Obj<bool>, CircuitUnit, Obj<bool>>` | flips the state each cycle |
14//! | [`shift_register_left()`] | `Sync<Obj<Bits<N>>, Obj<bool>, Obj<Bits<N>>>` | shift left, new bit at bit 0 |
15//!
16//! # Examples
17//!
18//! ## Accumulating a stream of values
19//!
20//! ```
21//! # fn main() -> Result<(), hdl_cat_error::Error> {
22//! use hdl_cat_std::accumulator;
23//!
24//! let acc = accumulator::<8>()?;
25//! assert_eq!(acc.state_wire_count(), 1);
26//! assert_eq!(acc.input_wires().len(), 2);  // state + input
27//! # Ok(()) }
28//! ```
29//!
30//! ## Building a half-adder from primitive gates
31//!
32//! ```
33//! # fn main() -> Result<(), hdl_cat_error::Error> {
34//! use hdl_cat_std::half_adder;
35//!
36//! let ha = half_adder()?;
37//! assert_eq!(ha.inputs().len(), 2);   // a, b
38//! assert_eq!(ha.outputs().len(), 2);  // sum, carry
39//! assert_eq!(ha.graph().instructions().len(), 2);  // XOR + AND
40//! # Ok(()) }
41//! ```
42
43pub mod accumulator;
44pub mod adder;
45pub mod counter;
46pub mod down_counter;
47pub mod shift_reg;
48pub mod toggle;
49
50pub use accumulator::{accumulator, AccumulatorSync};
51pub use adder::{half_adder, full_adder, HalfAdderArrow, FullAdderArrow};
52pub use counter::{counter, CounterSync};
53pub use down_counter::{down_counter, DownCounterSync};
54pub use shift_reg::{shift_register_left, ShiftRegisterLeftSync};
55pub use toggle::{toggle_ff, ToggleSync};