Re:Why is this C++ code faster than my hand-written assembly...
by showdead on Tuesday August 22, 2017 @05:19PM
(#15076491)
Well, there is this approach:
It's less costly than integer division, and I'm not sure it's what you had in mind. The output here still duplicates the strings.
[ Parent
| on HN ]
Re:Why is this C++ code faster than my hand-written assembly...
by raphlinus on Tuesday August 22, 2017 @05:37PM
(#15076602)
Tada! That's very close to what I had in mind. The only difference: you can fizz on 4924, buzz on 4210, none on 34cb, then always \n. Also, you have 3 ops to calculate the rotation, and that can be replaced by (0x8001 * x) >> 1 (for uint16_t x), but with tweaking of the masks because it's rotating right.
Congrats!