aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/time_windows_arm64.s
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-04-27 16:04:56 -0700
committerIan Lance Taylor <iant@golang.org>2021-04-28 20:16:36 +0000
commitb36596b14f8d3bee586479323c56b5db416a49e5 (patch)
tree3a1c6f695e50e811844070decfc8b1e1d26e086b /src/runtime/time_windows_arm64.s
parent07e006dd9322cc484303e1bef3d58c7e51d4f92c (diff)
downloadgo-b36596b14f8d3bee586479323c56b5db416a49e5.tar.gz
go-b36596b14f8d3bee586479323c56b5db416a49e5.zip
runtime: move Windows time.now implementations into separate files
This is a step toward separating whether time.now is implemented in assembly from whether we are using faketime. Change-Id: I8bf059b44a103b034835e3d3b799319cc05e9552 Reviewed-on: https://go-review.googlesource.com/c/go/+/314273 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/time_windows_arm64.s')
-rw-r--r--src/runtime/time_windows_arm64.s64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/runtime/time_windows_arm64.s b/src/runtime/time_windows_arm64.s
new file mode 100644
index 0000000000..61ce7577ce
--- /dev/null
+++ b/src/runtime/time_windows_arm64.s
@@ -0,0 +1,64 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "go_asm.h"
+#include "textflag.h"
+#include "time_windows.h"
+
+TEXT time·now(SB),NOSPLIT|NOFRAME,$0-24
+ MOVB runtime·useQPCTime(SB), R0
+ CMP $0, R0
+ BNE useQPC
+ MOVD $_INTERRUPT_TIME, R3
+loop:
+ MOVWU time_hi1(R3), R1
+ MOVWU time_lo(R3), R0
+ MOVWU time_hi2(R3), R2
+ CMP R1, R2
+ BNE loop
+
+ // wintime = R1:R0, multiply by 100
+ ORR R1<<32, R0
+ MOVD $100, R1
+ MUL R1, R0
+ MOVD R0, mono+16(FP)
+
+ MOVD $_SYSTEM_TIME, R3
+wall:
+ MOVWU time_hi1(R3), R1
+ MOVWU time_lo(R3), R0
+ MOVWU time_hi2(R3), R2
+ CMP R1, R2
+ BNE wall
+
+ // w = R1:R0 in 100ns units
+ // convert to Unix epoch (but still 100ns units)
+ #define delta 116444736000000000
+ ORR R1<<32, R0
+ SUB $delta, R0
+
+ // Convert to nSec
+ MOVD $100, R1
+ MUL R1, R0
+
+ // Code stolen from compiler output for:
+ //
+ // var x uint64
+ // func f() (sec uint64, nsec uint32) { return x / 1000000000, uint32(x % 100000000) }
+ //
+ LSR $1, R0, R1
+ MOVD $-8543223759426509416, R2
+ UMULH R2, R1, R1
+ LSR $28, R1, R1
+ MOVD R1, sec+0(FP)
+ MOVD $-6067343680855748867, R1
+ UMULH R0, R1, R1
+ LSR $26, R1, R1
+ MOVD $100000000, R2
+ MSUB R1, R0, R2, R0
+ MOVW R0, nsec+8(FP)
+ RET
+useQPC:
+ B runtime·nowQPC(SB) // tail call
+