Views
No views yet
A[3:0] ──┐ (dividend, 0-15)
├──► Divider ──┬──► Q[3:0] (quotient)
B[3:0] ──┘ (divisor, 1-15) └──► R[3:0] (remainder)
A = Q × B + R, where R < BP = 0 (partial remainder)
for i = 3 downto 0:
P = (P << 1) | A[i] // shift in next dividend bit
diff = P - B
if diff >= 0: // P >= B
Q[i] = 1
P = diff // keep subtraction result
else:
Q[i] = 0 // restore P (don't subtract)
R = P (final remainder)| Component | Function | Neurons |
|---|---|---|
| 4-bit Subtractor | P - B | 28 |
| 4× MUX | Select P or diff | 12 |
13 ÷ 3:
Stage 3: P=0, shift in 1 → P=1, 1<3, Q[3]=0
Stage 2: P=1, shift in 1 → P=3, 3≥3, Q[2]=1, P=0
Stage 1: P=0, shift in 0 → P=0, 0<3, Q[1]=0
Stage 0: P=0, shift in 1 → P=1, 1<3, Q[0]=0
Result: Q=0100=4, R=0001=1
Verify: 4×3+1=13 ✓1from safetensors.torch import load_file
2
3w = load_file('model.safetensors')
4
5# Division by zero returns Q=15, R=0
6# All 240 test cases verified (16 × 15 non-zero divisors)threshold-divider/
├── model.safetensors
├── create_safetensors.py
├── config.json
└── README.md