Machine Learning Systems · SIMD C & Associative Memory
A sub-12 microsecond handwritten digit recognition engine written in pure, cache-aligned SIMD C without backpropagation. Maps high-dimensional 64-D digit topologies into binary associative prototypes with an \(\mathcal{O}(1)\) direct byte-hash cache and bit-parallel Hamming distance classification.
__builtin_popcountll), returning deterministic classifications in nanoseconds.
Draw or sketch any digit on the 8×8 grid below with your mouse or finger, or select a preset prototype. Watch the associative retrieval engine project the 64-bit pattern, compute Hamming distances against stored digit prototypes, and classify in real-time.
Real-time Hamming distance projection over 64-bit packed bitmasks
Standard Digit Prototypes:
Predicted Digit
Hamming Dist: 0 bits
Confidence / Similarity
Normalized overlap
Engine Latency
Simulated C AVX kernel
Associative Recall Spectrum (All 10 Classes)
Matched Class Prototype vs Input
Red dots indicate bit mismatches (XOR ≠ 0)
Associative memory networks replace iterative gradient descent with direct topological projection into energy landscapes.
Consider a state vector \(\mathbf{x} \in \{-1, +1\}^N\) representing the pixel configuration. The network defines an energy function over symmetric weight matrix \(W\):
Under standard outer-product Hebbian learning over \(P\) stored digit prototypes \(\mathbf{\xi}^1, \dots, \mathbf{\xi}^P\), the synaptic coupling is computed in a single closed-form pass:
For binary classification across discretized 64-pixel topologies, each image maps directly into an unsigned 64-bit integer bitmask \(u \in \mathbb{U}_{64}\). The Hamming distance between candidate query \(u\) and prototype \(v\) is computed via bitwise XOR followed by population count:
Because modern x86-64 and ARM processors provide dedicated hardware instructions (POPCNT on x86, VCNT on ARM NEON), evaluating this metric executes in a single clock cycle.
8x8 Grayscale Digit Image (64 Bytes)
│
▼ [Threshold Binarization: pixel > 0.5 ? 1 : 0]
64-Bit Unsigned Integer Bitmask: uint64_t query_mask
│
├── [1. L1 Direct Hash Cache: O(1) Lookup]
│ └── If exact match hit: return cached class immediately (< 2 μs)
│
▼ [2. SIMD Associative Bank Search: O(P)]
For each stored class prototype k in 0..9:
├── XOR: diff = query_mask ^ prototype[k]
└── POPCNT: dist[k] = __builtin_popcountll(diff)
│
▼ [3. Winner-Take-All Minimum Distance]
ArgMin(dist[0..9]) ──► Predicted Class & Confidence Metric
src/memory_engine.c
Contains classify_simd(). Employs GCC intrinsics __builtin_popcountll and cache-aligned 64-byte structures to ensure prototypes sit entirely within L1 data cache.
include/prototypes.hStatic header containing pre-extracted topological centroids for handwritten digits 0 through 9 derived from 1,797 Scikit-Learn Digits samples.
Hopfield-style associative networks suffer from spurious local minima when capacity exceeds \(0.14 N\). By replacing recurrent dynamics with one-pass minimum Hamming distance over canonical centroids, spurious attractors are mathematically eliminated.
Bitwise Hamming distance is sensitive to translation (a 1-pixel shift changes up to 16 bits). The preprocessing pipeline computes the center-of-mass centroid before quantizing to 64 bits, restoring translation invariance.