mod division improvments

Started by
3 comments, last by vaneger 20 years ago

#define MOD(x,y) y & (x-1)
i found this some where but it is inaccurate does any one know how ot make a more accurate and faster MOD function?
Advertisement
That function is accurate for powers of two only. Other than powers of two, there''s no general way to do modulus with a constant that''s faster than just using modulus.

"Sneftel is correct, if rather vulgar." --Flarelocke
not even using asm ?
If there were, the compiler would already use it. Worry about how your code reads; let the compiler make it fast.
quote:Original post by vaneger
not even using asm ?

ASM isn''t a magic bullet. It''s just a lower-level language. More or less the same machine language instructions will be generated by the compiler as would be written by you, anyway. The number of situations where the best way to optimize is to rewrite stuff in ASM is very, very small.

"Sneftel is correct, if rather vulgar." --Flarelocke

This topic is closed to new replies.

Advertisement