cmd/7g: int64(-1<<63)/int64(-1) == 0??
minux opened this issue · 5 comments
package main
func main() {
var x, y int64 = -1<<63, -1
t, r := x/y, x%y
println(x, y, t, r)
if t != -x {
println("BUG", t)
}
if r != 0 {
println("BUG2", r)
}
}
Output:
-8 -1 0 0
BUG 0
Originate from test/divide.go.
Also note that println(-1<<63) is wrong. Our print implementations are directly from
the real runtime, so I think it's probably caused by (another?) bug in 7g.
our divide by -1 alternative code path is wrong, it always generate 0.
the problem is not limited to -1<<63.
test/divmod.go also has a lot of failures, but I haven't taken a closer look yet.
This might be a different issue (#108?)
http://play.golang.org/p/IK6WUxstH7
The output looks absurd, which suggests that software division implementation
in that program is probably buggy. Perhaps our shift is not working correctly?
uint64(0/5) = 0, want 1
uint64(0%5) = 0, want 1
uint64(5%5) = 0, want 0
int64(-1/-1) = 0, want 1
uint64(1/5) = 0, want 1
uint64(1%5) = 1, want 2
int64(1/-1) = 0, want -1
int64(-2/-1) = 0, want 2
uint64(5%5) = 0, want 0
int64(-1/-1) = 0, want 1
uint64(0/5) = 0, want 1
uint64(0%5) = 0, want 1
uint64(0/5) = 0, want 1
uint64(0%5) = 0, want 1
uint64(5%5) = 0, want 0
int64(-1/-1) = 0, want 1
uint64(5/1) = 5, want 0
uint64(5%1) = 0, want 5
uint64(0/4) = 0, want 1
// ....
this might be part of the problem, @minux remember this from 9g ?
walkdiv:
// TODO(minux)
if(arch.thechar == '9')
return;
Looking at the output from the sample function there are no divisions present in the assembly. I'm going to skip walkdiv for 7g until we have time to investigate it.