threshold-carry-propagate

Carry propagate signal for carry-lookahead adders. Outputs 1 when the bit position will propagate an incoming carry to the output.

Circuit

    a       b
    β”‚       β”‚
    β”œβ”€β”€β”€β”¬β”€β”€β”€β”€
    β”‚   β”‚   β”‚
    β–Ό   β”‚   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”β”‚β”Œβ”€β”€β”€β”€β”€β”€β”
β”‚  OR  β”‚β”‚β”‚ NAND β”‚
β”‚w:1,1 β”‚β”‚β”‚w:-1,-1β”‚
β”‚b: -1 β”‚β”‚β”‚b: +1 β”‚
β””β”€β”€β”€β”€β”€β”€β”˜β”‚β””β”€β”€β”€β”€β”€β”€β”˜
    β”‚   β”‚   β”‚
    β””β”€β”€β”€β”Όβ”€β”€β”€β”˜
        β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”
    β”‚ AND  β”‚
    β”‚w: 1,1β”‚
    β”‚b: -2 β”‚
    β””β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
      P(a,b)

Function

propagate(a, b) = a XOR b

A carry is propagated at position i when exactly one input is 1. In this case, an incoming carry will be passed through to the output.

Truth Table

a b P Meaning
0 0 0 0+0+Cin: Cin absorbed, not propagated
0 1 1 0+1+Cin: Cin propagates through
1 0 1 1+0+Cin: Cin propagates through
1 1 0 1+1+Cin: generates carry, doesn't "propagate"

Mechanism

XOR is implemented as AND(OR, NAND):

Layer 1:

  • OR: fires when a + b >= 1
  • NAND: fires when -(a + b) + 1 >= 0, i.e., a + b <= 1

Layer 2:

  • AND: fires when both OR and NAND fire (exactly one input is 1)
a b OR NAND AND(OR,NAND)
0 0 0 1 0
0 1 1 1 1
1 0 1 1 1
1 1 1 0 0

Carry-Lookahead Context

Together with Generate (G), Propagate (P) enables fast carry computation:

Signal Function Meaning
G (Generate) a AND b Will produce carry regardless of Cin
P (Propagate) a XOR b Will pass through incoming carry

The carry equation:

C[i+1] = G[i] OR (P[i] AND C[i])

In words: "Next carry is generated, OR propagated from previous."

Alternative Definition

Some texts define P = a OR b instead of a XOR b. Both work for carry-lookahead, but XOR is more common because:

  1. P = XOR means P AND G = 0 (mutually exclusive)
  2. Sum bit = P XOR Cin, reusing the propagate signal

Parameters

Inputs 2
Outputs 1
Neurons 3
Layers 2
Parameters 9
Magnitude 10

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def carry_propagate(a, b):
    inp = torch.tensor([float(a), float(b)])
    or_out = int((inp @ w['or.weight'].T + w['or.bias'] >= 0).item())
    nand_out = int((inp @ w['nand.weight'].T + w['nand.bias'] >= 0).item())
    l1 = torch.tensor([float(or_out), float(nand_out)])
    return int((l1 @ w['and.weight'].T + w['and.bias'] >= 0).item())

# Examples
print(carry_propagate(0, 0))  # 0
print(carry_propagate(0, 1))  # 1 (propagates)
print(carry_propagate(1, 0))  # 1 (propagates)
print(carry_propagate(1, 1))  # 0

Applications

  • Carry-lookahead adders (CLA)
  • Parallel prefix adders
  • Sum computation (Sum = P XOR Cin)
  • Conditional sum adders

Related Circuits

  • threshold-carry-generate: The G signal (a AND b)
  • threshold-xor: Same circuit, different name
  • threshold-carrylookahead4bit: Uses both G and P

Files

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

License

MIT

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

Collection including phanerozoic/threshold-carry-propagate