4-bit Kogge-Stone parallel prefix adder. Computes all carries in O(log n) depth using generate/propagate signals.
Inputs: A[3:0], B[3:0], Cin (9 inputs)
Outputs: S[3:0], Cout (5 outputs)
Level 0 - Generate/Propagate:
G_i = A_i AND B_i
P_i = A_i XOR B_i
Level 1-3 - Parallel Prefix:
(G_high, P_high) o (G_low, P_low) = (G_high + P_high·G_low, P_high·P_low)
Final:
C_i = G_i:0 + P_i:0·Cin
S_i = P_i XOR C_{i-1}
G3,P3 G2,P2 G1,P1 G0,P0 Cin
│ │ │ │ │
Level 1 ●────────● ●────────● │
│ │ │ │ │
Level 2 ●────────┼────────● │ │
│ │ │ │ │
Level 3 ●────────┼────────┼────────● │
│ │ │ │ │
▼ ▼ ▼ ▼ │
G3:0 G2:0 G1:0 G0 ──┘
│ │ │ │
▼ ▼ ▼ ▼
Cout C2 C1 C0
│ │ │
▼ ▼ ▼
S3 S2 S1 S0
Kogge-Stone trades area for speed with maximum parallelism.
1from safetensors.torch import load_file
2
3w = load_file('model.safetensors')
4
5# All 512 input combinations verified correct
threshold-kogge-stone/
├── model.safetensors
├── create_safetensors.py
├── config.json
└── README.md