Dynamic Branch Prediction with Perceptrons (2000) [pdf]
cs.cmu.edu
cs.cmu.edu
I recall implementing one in software in a computer architectures class; it was pretty gnarly but the prediction accuracy (and therefore performance) compared to a simple two-bit saturating counter is immense.
[1]: https://doi.org/10.1145/3226098 [2]: https://en.wikichip.org/wiki/amd/microarchitectures/zen_2#Br...
So the circuitry is complicated despite superficial simplicity of the model.
All branch predictors need some way of storing their state and selection logic, and the way a perceptron branch predictor stores its data is just a big table indexed by some hash of the program counter of the branch, which is pretty standard for branch predictors. Also, all branch predictors have a sort of "backpropogation" in that pipelined processors produce the actual result of the branch (possibly many) cycles later, so this also is not as much of a factor. Since the training is a function of the weights you do not need to store extra data beyond the threshold, but that is already being computed as the prediction anyways.
bot> A 5% miss rate in branch prediction leads to a 14.7% improvement in misprediction rates on a trace of SPEC2000 benchmarks compared to the gshare predictor. The use of machine learning-based predictors has the potential to improve these results further.
Some updates to it were big point of "what we did in Zen" presentations when first Ryzen and EPYC CPUs landed.
To be clear, all hardware branch predictors are "relatively simple state machines"; they need storage in the branch prediction tables which must super-fast to access, which means they can only store a few (sometimes dozens, but certainly not hundreds) bits per branch to reach the access latency goal. With input to the predictor encoded as binary, the weights quantized and small and encoded into binary, and the history small, even perceptrons are "relatively simple state machines". After all, their implementation is just going to become some combinatorial logic in the end.
Did this go anywhere? Is it worth revisiting in 2023?
(The guy who posted the link is Dan Luu who used to work for a company that made x86 CPUs. His blog is worth looking at. He also used to work for Twitter -- but his predictions about the Doom and Disaster after Musk's takeover hasn't panned out at all. Good at some things (CPU architecture and blog posts). Not so good at Elon Musk predictions ;) )
--- Edit: put in the missing "a". My fingers and my brain don't always agree on what to write.
system> What are the microarchitectural tricks that allow prediction to take place in one clock cycle?
bot> The microarchitectural tricks include using the branch address to hash and select a perceptron from the table, calculating the dot product of the perceptron and the global history register, using the training algorithm to update the weights in the perceptron, and writing the updated perceptron back to the table.