3 ms·
and divides were worse. (1 cycle add, 10 cycle mult, 60 cycle div)
by kurthr 1y ago
and divides were worse. (1 cycle add, 10 cycle mult, 60 cycle div)
- genewitch 1y agoThat's fair but mod is division, or no? So realistically the new magic number version would be faster. Assuming there is 32 bit int support. Sorry, this is above my paygrade.
- bobmcnamara 1y agoMany compiles will compute div-by-a-constant using the invert, multiply, and shift off the remainder trick. Once you have that, you can do mod-by-a-constant as a derivative and usually still beat 1-bit or 2-bit division.
- qingcharles 1y agoYeah, I'm thinking more of ones that remove all the divs from some crazy math functions for graphics rendering and replace them all with bit shifts or boolean ops.
- ryao 1y agoDivision still is worse: https://github.com/ridiculousfish/libdivide https://github.com/ridiculousfish/libdivide