Most optimized way to calculate modulus in C

后端 未结 8 1290
逝去的感伤
逝去的感伤 2020-12-08 15:39

I have minimize cost of calculating modulus in C. say I have a number x and n is the number which will divide x

when n == 65536 (which happens to be 2^16):

m

8条回答
  •  独厮守ぢ
    2020-12-08 15:48

    idiv — Integer Division

    The idiv instruction divides the contents of the 64 bit integer EDX:EAX (constructed by viewing EDX as the most significant four bytes and EAX as the least significant four bytes) by the specified operand value. The quotient result of the division is stored into EAX, while the remainder is placed in EDX.

    source: http://www.cs.virginia.edu/~evans/cs216/guides/x86.html

提交回复
热议问题