Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/time_windows_386.s

Documentation: runtime

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !faketime
     6  // +build !faketime
     7  
     8  #include "go_asm.h"
     9  #include "textflag.h"
    10  #include "time_windows.h"
    11  
    12  TEXT time·now(SB),NOSPLIT,$0-20
    13  	CMPB	runtime·useQPCTime(SB), $0
    14  	JNE	useQPC
    15  loop:
    16  	MOVL	(_INTERRUPT_TIME+time_hi1), AX
    17  	MOVL	(_INTERRUPT_TIME+time_lo), CX
    18  	MOVL	(_INTERRUPT_TIME+time_hi2), DI
    19  	CMPL	AX, DI
    20  	JNE	loop
    21  
    22  	// w = DI:CX
    23  	// multiply by 100
    24  	MOVL	$100, AX
    25  	MULL	CX
    26  	IMULL	$100, DI
    27  	ADDL	DI, DX
    28  	// w*100 = DX:AX
    29  	MOVL	AX, mono+12(FP)
    30  	MOVL	DX, mono+16(FP)
    31  
    32  wall:
    33  	MOVL	(_SYSTEM_TIME+time_hi1), CX
    34  	MOVL	(_SYSTEM_TIME+time_lo), AX
    35  	MOVL	(_SYSTEM_TIME+time_hi2), DX
    36  	CMPL	CX, DX
    37  	JNE	wall
    38  
    39  	// w = DX:AX
    40  	// convert to Unix epoch (but still 100ns units)
    41  	#define delta 116444736000000000
    42  	SUBL	$(delta & 0xFFFFFFFF), AX
    43  	SBBL $(delta >> 32), DX
    44  
    45  	// nano/100 = DX:AX
    46  	// split into two decimal halves by div 1e9.
    47  	// (decimal point is two spots over from correct place,
    48  	// but we avoid overflow in the high word.)
    49  	MOVL	$1000000000, CX
    50  	DIVL	CX
    51  	MOVL	AX, DI
    52  	MOVL	DX, SI
    53  
    54  	// DI = nano/100/1e9 = nano/1e11 = sec/100, DX = SI = nano/100%1e9
    55  	// split DX into seconds and nanoseconds by div 1e7 magic multiply.
    56  	MOVL	DX, AX
    57  	MOVL	$1801439851, CX
    58  	MULL	CX
    59  	SHRL	$22, DX
    60  	MOVL	DX, BX
    61  	IMULL	$10000000, DX
    62  	MOVL	SI, CX
    63  	SUBL	DX, CX
    64  
    65  	// DI = sec/100 (still)
    66  	// BX = (nano/100%1e9)/1e7 = (nano/1e9)%100 = sec%100
    67  	// CX = (nano/100%1e9)%1e7 = (nano%1e9)/100 = nsec/100
    68  	// store nsec for return
    69  	IMULL	$100, CX
    70  	MOVL	CX, nsec+8(FP)
    71  
    72  	// DI = sec/100 (still)
    73  	// BX = sec%100
    74  	// construct DX:AX = 64-bit sec and store for return
    75  	MOVL	$0, DX
    76  	MOVL	$100, AX
    77  	MULL	DI
    78  	ADDL	BX, AX
    79  	ADCL	$0, DX
    80  	MOVL	AX, sec+0(FP)
    81  	MOVL	DX, sec+4(FP)
    82  	RET
    83  useQPC:
    84  	JMP	runtime·nowQPC(SB)
    85  	RET
    86  

View as plain text