Skip to content

Commit 0e5f287

Browse files
committed
runtime: use correct constant when computing nsec remainder
A code comment on amd64 for windows and plan9 contained a snippet for splitting apart the sec and nsec components of a unix timestamp, with produced assembly below, which was then cleaned up by hand. When arm64 was ported, that code snippet in the comment went through the compiler to produce some code that was then pasted and cleaned up. Unfortunately, the comment had a typo in it, containing 8 zeros instead of 9. This resulted in the constant used in the assembly being wrong, spotted by @bufflig's eagle eyes. So, this commit fixes the comment on all three platforms, and the assembly on windows/arm64. Fixes #48072. Change-Id: I786fe89147328b0d25544f52c927ddfdb9f6f1cf Reviewed-on: https://go-review.googlesource.com/c/go/+/361474 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> Reviewed-by: Patrik Nyblom <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 256a8fc commit 0e5f287

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/runtime/sys_plan9_amd64.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ TEXT runtime·walltime(SB),NOSPLIT,$8-12
9494
MOVQ 0(SP), AX
9595

9696
// generated code for
97-
// func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
97+
// func f(x uint64) (uint64, uint64) { return x/1000000000, x%1000000000 }
9898
// adapted to reduce duplication
9999
MOVQ AX, CX
100100
MOVQ $1360296554856532783, AX

src/runtime/time_windows_amd64.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TEXT time·now(SB),NOSPLIT,$0-24
2525
IMULQ $100, AX
2626

2727
// generated code for
28-
// func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
28+
// func f(x uint64) (uint64, uint64) { return x/1000000000, x%1000000000 }
2929
// adapted to reduce duplication
3030
MOVQ AX, CX
3131
MOVQ $1360296554856532783, AX

src/runtime/time_windows_arm64.s

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ TEXT time·now(SB),NOSPLIT|NOFRAME,$0-24
3232
// Code stolen from compiler output for:
3333
//
3434
// var x uint64
35-
// func f() (sec uint64, nsec uint32) { return x / 1000000000, uint32(x % 100000000) }
35+
// func f() (sec uint64, nsec uint32) { return x / 1000000000, uint32(x % 1000000000) }
3636
//
3737
LSR $1, R0, R1
3838
MOVD $-8543223759426509416, R2
39-
UMULH R2, R1, R1
39+
UMULH R1, R2, R1
4040
LSR $28, R1, R1
4141
MOVD R1, sec+0(FP)
42-
MOVD $-6067343680855748867, R1
43-
UMULH R0, R1, R1
44-
LSR $26, R1, R1
45-
MOVD $100000000, R2
42+
MOVD $1000000000, R2
4643
MSUB R1, R0, R2, R0
4744
MOVW R0, nsec+8(FP)
4845
RET

0 commit comments

Comments
 (0)