csa-rhdl
Carry-save adder compressor trees composed through comp-cat-rs categorical morphisms, with an hdl-cat backend for hardware synthesis and simulation.
Implements the supranational/hardware rtl/csa
architecture as a type-driven, delay-run combinator library:
full_adder: 1-bit full adder cell (hdl-cat circuit arrow)csa_3to2<N>:N-wide three-to-two compressor (tensor power offull_adder)tree_level: groupsMoperands into triples and reducescompressor_tree<M, W>: recursiveM -> 2compressor via free-category pathRegisteredCompressor<M, W, OUT_W, D>: single-stage pipeline placeholderlower: translate abstract circuit AST to concrete hdl-cat IR
Categorical structure
| Hardware | Category theory |
|---|---|
| signal bundle | object (Shape) |
| combinational circuit | morphism (CircuitArrow) |
| parallel circuits | tensor product |
| wire permutation | braiding |
| tree reduction | catamorphism over Stream<CsaError, LevelDescriptor> |
Composition is delay-run: the tree is built as a lazy
Io<CsaError, CircuitArrow>. The caller invokes .run() exactly
once at the boundary (verilog generation, simulation, or shape
inspection).
Simulation
With hdl-cat-gates enabled, circuits can be simulated using
hdl-cat's interpreter. The example below builds a 4-bit CSA 3-to-2
compressor and checks the arithmetic identity a + b + cin == s + (cout << 1).
use csa_3to2;
use BitSeq;
use interpret;
The same approach works for the abstract compressor tree via the
lower module:
use *;
use interpret;
Verilog emission
With the verilog feature enabled, a lowered graph can be rendered to
Verilog. The emitter returns an Io effect; call .run() at the
boundary to execute.
use *;
use emit_graph;
The generated module has one port per input/output wire. For a
9-operand tree this produces nine input ports and two output ports
(sum and carry), with all internal CSA logic as continuous assign
statements.
Features
hdl-cat-gates(opt-in): hdl-cat circuit definitions, lowering, and the registered compressor. Depends on hdl-cat.verilog(opt-in, implieshdl-cat-gates): Verilog codegen.
Without any feature flags, the crate provides the full categorical tree compiler as a pure combinator library.
License
Dual-licensed under MIT or Apache-2.0, at your option.