Didn't come up with this, just saving for posterity
Found here: https://stackoverflow.com/questions/15233121/calculating-hamming-weight-in-o1.
"The exact algorithm you have is a variant of what is known as the "HAKMEM" algorithm (see Beeler, Gosper and Schroppel, 1972)".