8-bit less-than comparator. Returns 1 if a < b, 0 otherwise.
a0 b0 a1 b1 a2 b2 a3 b3 a4 b4 a5 b5 a6 b6 a7 b7
│ │ 0 │ │ │ │ │ │ │ │ │ │ │ │ │ │
└┬┘│ └┬┘ └┬┘ └┬┘ └┬┘ └┬┘ └┬┘ └┬┘
▼ │ ▼ ▼ ▼ ▼ ▼ ▼ ▼
┌───┐│ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
│FS0│┴──│FS1│────│FS2│────│FS3│────│FS4│────│FS5│────│FS6│────│FS7│──►(a<b)
└───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘
│ │ │ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
d0 d1 d2 d3 d4 d5 d6 d7
(difference bits unused - only final borrow matters)
Uses 8 cascaded full subtractors. The final borrow output indicates a < b.
The difference bits (d0-d7) are computed but unused. Only the final borrow matters.
a b
│ │
└───┬───┘
▼
┌─────────┐
│ HS1 │
└─────────┘
│ │
d1 b1
│ \
│ bin \
└──┬──┘ \
▼ \
┌─────────┐ \
│ HS2 │ │
└─────────┘ │
│ │ │
d b2 │
│ │
└──┬───┘
▼
┌──────┐
│ OR │
└──────┘
│
▼
bout
1from safetensors.torch import load_file
2
3w = load_file('model.safetensors')
4
5def less_than(a, b):
6 """a, b: 8-bit lists [a0..a7] (LSB first)
7 Returns: 1 if a < b, 0 otherwise"""
8 # See model.py for full implementation
9 pass
10
11# Example: 99 < 100?
12a = [(99 >> i) & 1 for i in range(8)]
13b = [(100 >> i) & 1 for i in range(8)]
14result = less_than(a, b) # Returns 1
threshold-lessthan/
├── model.safetensors
├── model.py
├── config.json
└── README.md