threshold-clz4

4-bit count leading zeros.

Function

clz4(a3, a2, a1, a0) = number of leading zeros from MSB

Truth Table (selected rows)

Input First 1 CLZ Output
1xxx bit 3 0 000
01xx bit 2 1 001
001x bit 1 2 010
0001 bit 0 3 011
0000 none 4 100

Architecture

Layer 1: Priority detection from MSB
  has3 = a3 (MSB is set, clz=0)
  has2_first = a2 AND NOT(a3) (clz=1)
  has1_first = a1 AND NOT(a2) AND NOT(a3) (clz=2)
  has0_first = a0 AND NOT(a1) AND NOT(a2) AND NOT(a3) (clz=3)
  all_zero = NOT(any bit) (clz=4)

Layer 2: Binary encoding
  y0 = has2_first OR has0_first (clz is 1 or 3)
  y1 = has1_first OR has0_first (clz is 2 or 3)
  y2 = all_zero (clz is 4)

Parameters

Inputs 4
Outputs 3
Neurons 8
Layers 2
Parameters 39
Magnitude 26

Usage

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

# clz4(1, 0, 0, 0) = [0, 0, 0] = 0 (MSB is set)
# clz4(0, 0, 1, 0) = [0, 1, 0] = 2 (two leading zeros)
# clz4(0, 0, 0, 0) = [1, 0, 0] = 4 (all zeros)

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-clz4