Fastest way to calculate a 128-bit integer modulo a 64-bit integer

Posted by Paul Baker on Stack Overflow See other posts from Stack Overflow or by Paul Baker
Published on 2010-04-02T09:54:09Z Indexed on 2010/04/02 11:13 UTC
Read the original article Hit count: 532

Filed under:
|
|
|
|

I have a 128-bit unsigned integer A and a 64-bit unsigned integer B. What's the fastest way to calculate A % B - that is the (64-bit) remainder from dividing A by B?

I'm looking to do this in either C or assembly language, but I need to target the 32-bit x86 platform. This unfortunately means that I cannot take advantage of compiler support for 128-bit integers, nor of the x64 architecture's ability to perform the required operation in a single instruction.

© Stack Overflow or respective owner

Related posts about modulo

Related posts about remainder