threshold-popcount8 / README.md
CharlesCNorton
8-bit popcount threshold circuit, magnitude 163
df35550
metadata
license: mit
tags:
  - pytorch
  - safetensors
  - threshold-logic
  - neuromorphic

threshold-popcount8

8-bit population count. Counts the number of 1 bits in an 8-bit input.

Function

popcount8(a7..a0) = count of 1 bits (0 to 8)

Output is 4 bits: y3y2y1y0 representing count in binary.

Truth Table (selected rows)

Input Count Output
00000000 0 0000
00000001 1 0001
01010101 4 0100
11110000 4 0100
11111111 8 1000

Architecture

  • y3 = (sum == 8)
  • y2 = (sum >= 4) AND (sum <= 7)
  • y1 = ((sum >= 2) AND (sum <= 3)) OR ((sum >= 6) AND (sum <= 7))
  • y0 = XOR8 (parity of all 8 bits)

The parity computation uses a tree of XOR gates: XOR pairs, then XOR the results.

Parameters

Inputs 8
Outputs 4
Neurons 31
Layers 5
Parameters 177
Magnitude 163

Usage

from safetensors.torch import load_file
# See create_safetensors.py for full implementation

# popcount8(1,0,1,0,1,0,1,0) = [0,1,0,0] = 4

License

MIT