Skip to content

Commit 6144b48

Browse files
committed
go-patches: return correct nanosec param on arm64
Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 531d463 commit 6144b48

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: "Jason A. Donenfeld" <[email protected]>
3+
Date: Fri, 5 Nov 2021 00:10:31 +0100
4+
Subject: [PATCH] runtime: use correct constant when computing nsec remainder
5+
6+
A code comment on amd64 for windows and plan9 contained a snippet for
7+
splitting apart the sec and nsec components of a unix timestamp, with
8+
produced assembly below, which was then cleaned up by hand. When arm64
9+
was ported, that code snippet in the comment went through the compiler
10+
to produce some code that was then pasted and cleaned up. Unfortunately,
11+
the comment had a typo in it, containing 8 zeros instead of 9.
12+
13+
This resulted in the constant used in the assembly being wrong, spotted
14+
by @bufflig's eagle eyes. So, this commit fixes the comment on all three
15+
platforms, and the assembly on windows/arm64.
16+
17+
Fixes #48072.
18+
19+
Change-Id: I786fe89147328b0d25544f52c927ddfdb9f6f1cf
20+
Reviewed-on: https://go-review.googlesource.com/c/go/+/361474
21+
Trust: Jason A. Donenfeld <[email protected]>
22+
Run-TryBot: Jason A. Donenfeld <[email protected]>
23+
Reviewed-by: Patrik Nyblom <[email protected]>
24+
TryBot-Result: Go Bot <[email protected]>
25+
---
26+
src/runtime/sys_plan9_amd64.s | 2 +-
27+
src/runtime/time_windows_amd64.s | 2 +-
28+
src/runtime/time_windows_arm64.s | 9 +++------
29+
3 files changed, 5 insertions(+), 8 deletions(-)
30+
31+
diff --git a/src/runtime/sys_plan9_amd64.s b/src/runtime/sys_plan9_amd64.s
32+
index 731306ab44..068200b7f3 100644
33+
--- a/src/runtime/sys_plan9_amd64.s
34+
+++ b/src/runtime/sys_plan9_amd64.s
35+
@@ -94,7 +94,7 @@ TEXT runtime·walltime(SB),NOSPLIT,$8-12
36+
MOVQ 0(SP), AX
37+
38+
// generated code for
39+
- // func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
40+
+ // func f(x uint64) (uint64, uint64) { return x/1000000000, x%1000000000 }
41+
// adapted to reduce duplication
42+
MOVQ AX, CX
43+
MOVQ $1360296554856532783, AX
44+
diff --git a/src/runtime/time_windows_amd64.s b/src/runtime/time_windows_amd64.s
45+
index 045f64eb46..70f6a008cd 100644
46+
--- a/src/runtime/time_windows_amd64.s
47+
+++ b/src/runtime/time_windows_amd64.s
48+
@@ -25,7 +25,7 @@ TEXT time·now(SB),NOSPLIT,$0-24
49+
IMULQ $100, AX
50+
51+
// generated code for
52+
- // func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
53+
+ // func f(x uint64) (uint64, uint64) { return x/1000000000, x%1000000000 }
54+
// adapted to reduce duplication
55+
MOVQ AX, CX
56+
MOVQ $1360296554856532783, AX
57+
diff --git a/src/runtime/time_windows_arm64.s b/src/runtime/time_windows_arm64.s
58+
index e8a0eb2f93..ef5b848473 100644
59+
--- a/src/runtime/time_windows_arm64.s
60+
+++ b/src/runtime/time_windows_arm64.s
61+
@@ -32,17 +32,14 @@ TEXT time·now(SB),NOSPLIT|NOFRAME,$0-24
62+
// Code stolen from compiler output for:
63+
//
64+
// var x uint64
65+
- // func f() (sec uint64, nsec uint32) { return x / 1000000000, uint32(x % 100000000) }
66+
+ // func f() (sec uint64, nsec uint32) { return x / 1000000000, uint32(x % 1000000000) }
67+
//
68+
LSR $1, R0, R1
69+
MOVD $-8543223759426509416, R2
70+
- UMULH R2, R1, R1
71+
+ UMULH R1, R2, R1
72+
LSR $28, R1, R1
73+
MOVD R1, sec+0(FP)
74+
- MOVD $-6067343680855748867, R1
75+
- UMULH R0, R1, R1
76+
- LSR $26, R1, R1
77+
- MOVD $100000000, R2
78+
+ MOVD $1000000000, R2
79+
MSUB R1, R0, R2, R0
80+
MOVW R0, nsec+8(FP)
81+
RET

0 commit comments

Comments
 (0)