threshold-ripplecarry8bit

Adds two 8-bit numbers with carry-in. Eight cascaded full adders in ripple-carry architecture.

Circuit

 a0 b0      a1 b1      a2 b2      a3 b3      a4 b4      a5 b5      a6 b6      a7 b7
  β”‚ β”‚        β”‚ β”‚        β”‚ β”‚        β”‚ β”‚        β”‚ β”‚        β”‚ β”‚        β”‚ β”‚        β”‚ β”‚
  β””β”¬β”˜        β””β”¬β”˜        β””β”¬β”˜        β””β”¬β”˜        β””β”¬β”˜        β””β”¬β”˜        β””β”¬β”˜        β””β”¬β”˜
   β–Ό          β–Ό          β–Ό          β–Ό          β–Ό          β–Ό          β–Ό          β–Ό
β”Œβ”€β”€β”€β”€β” c0 β”Œβ”€β”€β”€β”€β” c1 β”Œβ”€β”€β”€β”€β” c2 β”Œβ”€β”€β”€β”€β” c3 β”Œβ”€β”€β”€β”€β” c4 β”Œβ”€β”€β”€β”€β” c5 β”Œβ”€β”€β”€β”€β” c6 β”Œβ”€β”€β”€β”€β”
β”‚FA0 │────│FA1 │────│FA2 │────│FA3 │────│FA4 │────│FA5 │────│FA6 │────│FA7 │──cout
β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”˜
   β”‚         β”‚         β”‚         β”‚         β”‚         β”‚         β”‚         β”‚
   β–Ό         β–Ό         β–Ό         β–Ό         β–Ό         β–Ό         β–Ό         β–Ό
  s0        s1        s2        s3        s4        s5        s6        s7

cinβ”€β”˜


   Input:  (a7..a0) + (b7..b0) + cin
   Output: (cout s7..s0)

Example

    11111111  (255)
  + 00000001  (  1)
  ──────────
   100000000  (256)

255 + 1 = 256. The sum bits are all 0, cout = 1.

Architecture

Component Per FA Total (8 FAs)
Neurons 9 72
Parameters 27 216
Layers 4 32

Inputs/Outputs

Name Bits Description
a a7..a0 First 8-bit number (LSB = a0)
b b7..b0 Second 8-bit number (LSB = b0)
cin 1 Carry in
s s7..s0 8-bit sum (LSB = s0)
cout 1 Carry out

Critical Path

Worst-case: carry propagates through all 8 full adders.

cin β†’ FA0 β†’ FA1 β†’ FA2 β†’ FA3 β†’ FA4 β†’ FA5 β†’ FA6 β†’ FA7 β†’ cout

This is 8 Γ— 4 = 32 layers deep. For a byte-wide ALU, this latency is acceptable. For wider words, carry-lookahead or prefix adders would be preferred.

Range

  • Input: 0-255 + 0-255 + 0-1 = 0-511
  • Output: 9 bits (8-bit sum + 1-bit carry)

Usage

from safetensors.torch import load_file

w = load_file('model.safetensors')

def ripple_carry_8bit(a, b, cin):
    """a, b: 8-bit lists [a0..a7] (LSB first)"""
    # See model.py for full implementation
    pass

# Example: 200 + 100 = 300 (overflow to 9 bits)
a = [(200 >> i) & 1 for i in range(8)]  # 200 in LSB-first
b = [(100 >> i) & 1 for i in range(8)]  # 100 in LSB-first
sums, cout = ripple_carry_8bit(a, b, 0)
result = sum(bit << i for i, bit in enumerate(sums)) + (cout << 8)
# result = 300

Scaling

Bits Full Adders Neurons Parameters Max Depth
2 2 18 54 8
4 4 36 108 16
8 8 72 216 32
16 16 144 432 64
n n 9n 27n 4n

Files

threshold-ripplecarry8bit/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ model.py
β”œβ”€β”€ config.json
└── README.md

License

MIT

Downloads last month
11
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-ripplecarry8bit