Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-13 Thread Nick Craig-Wood
Traditionally you'd write that sort of thing in assembler to get that amount of control. Though the modern thing would be to have intrinsics.. I guess in the go world, having assembler routines that could be inlined would be the optimum solution. On 10/11/16 13:45, alb.donize...@gmail.com wrote:

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-10 Thread Michael Jones
10, 2016 at 6:05 AM To: golang-nuts Cc: , <0xj...@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 b

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-10 Thread radu
Ah, I missed that, thanks! On Thursday, November 10, 2016 at 9:05:53 AM UTC-5, alb.do...@gmail.com wrote: > > If the div overflow, it will trigger and hardware exception. > > Il giorno giovedì 10 novembre 2016 15:01:06 UTC+1, ra...@cockroachlabs.com > ha scritto: >> >> I don't understand. We ar

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-10 Thread alb . donizetti
If the div overflow, it will trigger and hardware exception. Il giorno giovedì 10 novembre 2016 15:01:06 UTC+1, ra...@cockroachlabs.com ha scritto: > > I don't understand. We are truncating the result to 32-bits either way. > What's the point of computing the entire 64-bits of the result just t

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-10 Thread radu
I don't understand. We are truncating the result to 32-bits either way. What's the point of computing the entire 64-bits of the result just to throw away the high 32? In 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 r3

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-10 Thread alb . donizetti
When you do a DIV r32 in 64bit mode the result will be saved in EAX but this means that you can only do that if the high word of the dividend is smaller that the divisor. You can't unconditionally replace uint32(A / uint64(B)) with a DIV r32 instruction because if A is big (take 2**62) and B is

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-07 Thread andrew_chambers
I imagine the new SSA backend can do this with its pattern matching, but you would need to look for it here: https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules or https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/AMD64.rules Maybe some

Re: [go-nuts] Slow 64 bit integer division on amd64

2016-11-07 Thread radu
Sorry to revive an old thread. One thing to note is that dividing a 64-bit by a 32-bit is much faster than dividing a 64-bit by a 64-bit, at least on recent Intel platforms. Unfortunately there is no valid way to express that kind of calculation in Go.. Is the compiler/optimizer smart enough t