File size: 1,792 Bytes
8b9ff19 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | ---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- arithmetic
- dsp
---
# threshold-saturating-adder
4-bit unsigned saturating adder. Clamps to maximum value on overflow instead of wrapping around.
## Circuit
```
A[3:0] βββ
ββββΊ Sat Add βββ¬βββΊ S[3:0] (result)
B[3:0] βββ ββββΊ saturated (overflow flag)
```
## Behavior
| A + B | Result | Saturated |
|-------|--------|-----------|
| β€ 15 | A + B | 0 |
| > 15 | 15 | 1 |
## Examples
```
7 + 5 = 12, saturated=0
10 + 10 = 15, saturated=1 (true sum: 20)
15 + 15 = 15, saturated=1 (true sum: 30)
8 + 7 = 15, saturated=0
8 + 8 = 15, saturated=1 (true sum: 16)
```
## Wrapping vs Saturating
```
Wrapping: 15 + 1 = 0 (modulo 16)
Saturating: 15 + 1 = 15 (clamped)
```
## Architecture
| Component | Count | Neurons |
|-----------|-------|---------|
| Full Adders | 4 | 28 |
| Saturation MUXes | 4 | 12 |
**Total: 40 neurons, 124 parameters, 4 layers**
## How It Works
```
1. Compute A + B with standard 4-bit adder
2. If carry out = 1:
- Output 1111 (15)
- Set saturated = 1
3. Else:
- Output sum bits
- Set saturated = 0
```
## Applications
- **Audio DSP**: Prevents clipping distortion
- **Image processing**: Pixel value saturation
- **Neural networks**: Activation clamping
- **Control systems**: Prevents actuator overshoot
- **Fixed-point arithmetic**: Overflow protection
## Usage
```python
from safetensors.torch import load_file
w = load_file('model.safetensors')
# All 256 test cases verified
# Saturates 120 cases (where A+B > 15)
```
## Files
```
threshold-saturating-adder/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
```
## License
MIT
|