aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-11-30 11:59:44 -0500
committerRuss Cox <rsc@golang.org>2011-11-30 11:59:44 -0500
commitefe3d35fc590bf8b439f56070aa1f070125c6e8e (patch)
tree135f305b0e383917e799cb419419a42bfc0430f8 /src/pkg/runtime
parent849fc19cab2c3059379b21dde019f521ce772f5c (diff)
downloadgo-efe3d35fc590bf8b439f56070aa1f070125c6e8e.tar.xz
time: new Time, Duration, ZoneInfo types
R=r, bradfitz, gri, dsymonds, iant CC=golang-dev https://golang.org/cl/5392041
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/darwin/386/sys.s16
-rw-r--r--src/pkg/runtime/darwin/amd64/sys.s13
-rw-r--r--src/pkg/runtime/freebsd/386/sys.s17
-rw-r--r--src/pkg/runtime/freebsd/amd64/sys.s15
-rw-r--r--src/pkg/runtime/linux/386/sys.s17
-rw-r--r--src/pkg/runtime/linux/amd64/sys.s15
-rw-r--r--src/pkg/runtime/linux/arm/sys.s17
-rw-r--r--src/pkg/runtime/openbsd/386/sys.s17
-rw-r--r--src/pkg/runtime/openbsd/amd64/sys.s15
-rw-r--r--src/pkg/runtime/time.goc5
-rw-r--r--src/pkg/runtime/windows/thread.c12
11 files changed, 155 insertions, 4 deletions
diff --git a/src/pkg/runtime/darwin/386/sys.s b/src/pkg/runtime/darwin/386/sys.s
index c8b89bfa3f..426367b9e2 100644
--- a/src/pkg/runtime/darwin/386/sys.s
+++ b/src/pkg/runtime/darwin/386/sys.s
@@ -60,6 +60,22 @@ TEXT runtime·setitimer(SB),7,$0
INT $0x80
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ LEAL 12(SP), AX // must be non-nil, unused
+ MOVL AX, 4(SP)
+ MOVL $0, 8(SP) // time zone pointer
+ MOVL $116, AX
+ INT $0x80
+ MOVL DX, BX
+
+ // sec is in AX, usec in BX
+ MOVL AX, sec+0(FP)
+ MOVL $0, sec+4(FP)
+ IMULL $1000, BX
+ MOVL BX, nsec+8(FP)
+ RET
+
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB), 7, $32
diff --git a/src/pkg/runtime/darwin/amd64/sys.s b/src/pkg/runtime/darwin/amd64/sys.s
index f049d973db..5a504e3ecf 100644
--- a/src/pkg/runtime/darwin/amd64/sys.s
+++ b/src/pkg/runtime/darwin/amd64/sys.s
@@ -55,6 +55,19 @@ TEXT runtime·setitimer(SB), 7, $0
SYSCALL
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ MOVQ SP, DI // must be non-nil, unused
+ MOVQ $0, SI
+ MOVL $(0x2000000+116), AX
+ SYSCALL
+
+ // sec is in AX, usec in DX
+ MOVQ AX, sec+0(FP)
+ IMULQ $1000, DX
+ MOVL DX, nsec+8(FP)
+ RET
+
// int64 nanotime(void)
TEXT runtime·nanotime(SB), 7, $32
MOVQ SP, DI // must be non-nil, unused
diff --git a/src/pkg/runtime/freebsd/386/sys.s b/src/pkg/runtime/freebsd/386/sys.s
index 3856a53707..41134ad61f 100644
--- a/src/pkg/runtime/freebsd/386/sys.s
+++ b/src/pkg/runtime/freebsd/386/sys.s
@@ -106,6 +106,23 @@ TEXT runtime·setitimer(SB), 7, $-4
INT $0x80
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ MOVL $116, AX
+ LEAL 12(SP), BX
+ MOVL BX, 4(SP)
+ MOVL $0, 8(SP)
+ INT $0x80
+ MOVL 12(SP), AX // sec
+ MOVL 16(SP), BX // usec
+
+ // sec is in AX, usec in BX
+ MOVL AX, sec+0(FP)
+ MOVL $0, sec+4(FP)
+ IMULL $1000, BX
+ MOVL BX, nsec+8(FP)
+ RET
+
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB), 7, $32
diff --git a/src/pkg/runtime/freebsd/amd64/sys.s b/src/pkg/runtime/freebsd/amd64/sys.s
index 252069e0db..bd63650236 100644
--- a/src/pkg/runtime/freebsd/amd64/sys.s
+++ b/src/pkg/runtime/freebsd/amd64/sys.s
@@ -85,6 +85,21 @@ TEXT runtime·setitimer(SB), 7, $-8
SYSCALL
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ MOVL $116, AX
+ LEAQ 8(SP), DI
+ MOVQ $0, SI
+ SYSCALL
+ MOVQ 8(SP), AX // sec
+ MOVL 16(SP), DX // usec
+
+ // sec is in AX, usec in DX
+ MOVQ AX, sec+0(FP)
+ IMULQ $1000, DX
+ MOVL DX, nsec+8(FP)
+ RET
+
TEXT runtime·nanotime(SB), 7, $32
MOVL $116, AX
LEAQ 8(SP), DI
diff --git a/src/pkg/runtime/linux/386/sys.s b/src/pkg/runtime/linux/386/sys.s
index 97d9d5ed9c..7baeb34bce 100644
--- a/src/pkg/runtime/linux/386/sys.s
+++ b/src/pkg/runtime/linux/386/sys.s
@@ -95,6 +95,23 @@ TEXT runtime·mincore(SB),7,$0-24
CALL *runtime·_vdso(SB)
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ MOVL $78, AX // syscall - gettimeofday
+ LEAL 8(SP), BX
+ MOVL $0, CX
+ MOVL $0, DX
+ CALL *runtime·_vdso(SB)
+ MOVL 8(SP), AX // sec
+ MOVL 12(SP), BX // usec
+
+ // sec is in AX, usec in BX
+ MOVL AX, sec+0(FP)
+ MOVL $0, sec+4(FP)
+ IMULL $1000, BX
+ MOVL BX, nsec+8(FP)
+ RET
+
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB), 7, $32
diff --git a/src/pkg/runtime/linux/amd64/sys.s b/src/pkg/runtime/linux/amd64/sys.s
index 227c8e62cc..ff72a75340 100644
--- a/src/pkg/runtime/linux/amd64/sys.s
+++ b/src/pkg/runtime/linux/amd64/sys.s
@@ -93,6 +93,21 @@ TEXT runtime·mincore(SB),7,$0-24
SYSCALL
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ LEAQ 8(SP), DI
+ MOVQ $0, SI
+ MOVQ $0xffffffffff600000, AX
+ CALL AX
+ MOVQ 8(SP), AX // sec
+ MOVL 16(SP), DX // usec
+
+ // sec is in AX, usec in DX
+ MOVQ AX, sec+0(FP)
+ IMULQ $1000, DX
+ MOVL DX, nsec+8(FP)
+ RET
+
TEXT runtime·nanotime(SB), 7, $32
LEAQ 8(SP), DI
MOVQ $0, SI
diff --git a/src/pkg/runtime/linux/arm/sys.s b/src/pkg/runtime/linux/arm/sys.s
index 3d26ff0a41..80f956fb08 100644
--- a/src/pkg/runtime/linux/arm/sys.s
+++ b/src/pkg/runtime/linux/arm/sys.s
@@ -127,6 +127,23 @@ TEXT runtime·mincore(SB),7,$0
SWI $0
RET
+TEXT time·now(SB), 7, $32
+ MOVW $8(R13), R0 // timeval
+ MOVW $0, R1 // zone
+ MOVW $SYS_gettimeofday, R7
+ SWI $0
+
+ MOVW 8(R13), R0 // sec
+ MOVW 12(R13), R2 // usec
+
+ MOVW R0, 0(FP)
+ MOVW $0, R1
+ MOVW R1, 4(FP)
+ MOVW $1000, R3
+ MUL R3, R2
+ MOVW R2, 8(FP)
+ RET
+
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB),7,$32
diff --git a/src/pkg/runtime/openbsd/386/sys.s b/src/pkg/runtime/openbsd/386/sys.s
index 6a6a7bbd3b..2b1be7ee6b 100644
--- a/src/pkg/runtime/openbsd/386/sys.s
+++ b/src/pkg/runtime/openbsd/386/sys.s
@@ -91,6 +91,23 @@ TEXT runtime·setitimer(SB),7,$-4
INT $0x80
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ MOVL $116, AX
+ LEAL 12(SP), BX
+ MOVL BX, 4(SP)
+ MOVL $0, 8(SP)
+ INT $0x80
+ MOVL 12(SP), AX // sec
+ MOVL 16(SP), BX // usec
+
+ // sec is in AX, usec in BX
+ MOVL AX, sec+0(FP)
+ MOVL $0, sec+4(FP)
+ IMULL $1000, BX
+ MOVL BX, nsec+8(FP)
+ RET
+
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB),7,$32
diff --git a/src/pkg/runtime/openbsd/amd64/sys.s b/src/pkg/runtime/openbsd/amd64/sys.s
index 7bb44d6a95..9c2d403b25 100644
--- a/src/pkg/runtime/openbsd/amd64/sys.s
+++ b/src/pkg/runtime/openbsd/amd64/sys.s
@@ -133,6 +133,21 @@ TEXT runtime·setitimer(SB),7,$-8
SYSCALL
RET
+// func now() (sec int64, nsec int32)
+TEXT time·now(SB), 7, $32
+ LEAQ 8(SP), DI // arg 1 - tp
+ MOVQ $0, SI // arg 2 - tzp
+ MOVL $116, AX // sys_gettimeofday
+ SYSCALL
+ MOVQ 8(SP), AX // sec
+ MOVL 16(SP), DX // usec
+
+ // sec is in AX, usec in DX
+ MOVQ AX, sec+0(FP)
+ IMULQ $1000, DX
+ MOVL DX, nsec+8(FP)
+ RET
+
TEXT runtime·nanotime(SB),7,$32
LEAQ 8(SP), DI // arg 1 - tp
MOVQ $0, SI // arg 2 - tzp
diff --git a/src/pkg/runtime/time.goc b/src/pkg/runtime/time.goc
index ad9f3aac56..8306e61358 100644
--- a/src/pkg/runtime/time.goc
+++ b/src/pkg/runtime/time.goc
@@ -19,10 +19,7 @@ static bool deltimer(Timer*);
// Package time APIs.
// Godoc uses the comments in package time, not these.
-// Nanoseconds returns the current time in nanoseconds.
-func Nanoseconds() (ret int64) {
- ret = runtime·nanotime();
-}
+// time.now is implemented in assembly.
// Sleep puts the current goroutine to sleep for at least ns nanoseconds.
func Sleep(ns int64) {
diff --git a/src/pkg/runtime/windows/thread.c b/src/pkg/runtime/windows/thread.c
index 9abc9cd728..4b963f374e 100644
--- a/src/pkg/runtime/windows/thread.c
+++ b/src/pkg/runtime/windows/thread.c
@@ -219,6 +219,18 @@ runtime·nanotime(void)
return (filetime - 116444736000000000LL) * 100LL;
}
+void
+time·now(int64 sec, int32 usec)
+{
+ int64 ns;
+
+ ns = runtime·nanotime();
+ sec = ns / 1000000000LL;
+ usec = ns - sec * 1000000000LL;
+ FLUSH(&sec);
+ FLUSH(&usec);
+}
+
// Calling stdcall on os stack.
#pragma textflag 7
void *