A=2^62

B=13

 

A/B = 4611686018427387904/13 

A/B = quotient 354745078340568300 with remainder 4

A/B = (82595524*2^32 + 3964585196) with remainder 4

 

Consider the quotient:

H = Upper 32 bits of 354745078340568300 = 82595524

L = Lower 32 bits of 354745078340568300 = 3964585196

 

Apparently you want L.

 

uint32(uint64(354745078340568300)) = 3964585196

 

The overflow condition is that the quotient is not representable in 32 bits. 
Reference:

http://stackoverflow.com/questions/22596059/problems-dividing-64-bits-in-x86-assembly

 

 

From: <golang-nuts@googlegroups.com> on behalf of <alb.donize...@gmail.com>
Date: Thursday, November 10, 2016 at 6:05 AM
To: golang-nuts <golang-nuts@googlegroups.com>
Cc: <minux...@gmail.com>, <0xj...@gmail.com>, <r...@cockroachlabs.com>, 
<alb.donize...@gmail.com>
Subject: Re: [go-nuts] Slow 64 bit integer division on amd64

 

n your example, A=2^62 and B=13`, `uint32(A / uint64(B))` is (2^62 / 13) % 2^32 
which I thought is exactly the result of DIV r32.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to