threshold-leading-one-detect

8-bit leading one detector. Finds the position of the highest-order 1 bit (MSB priority).

Circuit

x[7:0] ──► LOD ──┬──► pos[2:0]  (position 0-7)
                 └──► valid     (1 if any bit set)

Truth Table (examples)

Input Binary Position Valid
0 00000000 0 0
1 00000001 0 1
2 00000010 1 1
128 10000000 7 1
255 11111111 7 1
170 10101010 7 1

Algorithm

For each bit position i (7 down to 0):
  leader[i] = x[i] AND NOT(any bit j > i is set)

Position is binary encoding of which leader is active.

Architecture

Component Count Neurons
Higher-than OR 8 8
NOT higher 8 8
Leader AND 8 8
Position encode 3 3
Valid OR 1 1

Total: 28 neurons, 136 parameters, 3 layers

Applications

  • Floating-point normalization: Find exponent adjustment
  • Priority encoding: Highest-priority interrupt
  • Integer logβ‚‚: Position = floor(logβ‚‚(x))
  • Bit manipulation: Count leading zeros = 7 - position

Usage

from safetensors.torch import load_file

w = load_file('model.safetensors')

# For x = 0b00101100 (44):
# Leading one at position 5
# logβ‚‚(44) β‰ˆ 5

Relation to CLZ

Count Leading Zeros = 7 - position (when valid=1)

x = 0b00100000 β†’ position=5 β†’ CLZ=2
x = 0b10000000 β†’ position=7 β†’ CLZ=0

Files

threshold-leading-one-detect/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ create_safetensors.py
β”œβ”€β”€ config.json
└── README.md

License

MIT

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

Collection including phanerozoic/threshold-leading-one-detect