Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/time_windows_arm.s

Documentation: runtime

     1  // Copyright 2018 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|NOFRAME,$0-20
    13  	MOVW    $0, R0
    14  	MOVB    runtime·useQPCTime(SB), R0
    15  	CMP	$0, R0
    16  	BNE	useQPC
    17  	MOVW	$_INTERRUPT_TIME, R3
    18  loop:
    19  	MOVW	time_hi1(R3), R1
    20  	MOVW	time_lo(R3), R0
    21  	MOVW	time_hi2(R3), R2
    22  	CMP	R1, R2
    23  	BNE	loop
    24  
    25  	// wintime = R1:R0, multiply by 100
    26  	MOVW	$100, R2
    27  	MULLU	R0, R2, (R4, R3)    // R4:R3 = R1:R0 * R2
    28  	MULA	R1, R2, R4, R4
    29  
    30  	// wintime*100 = R4:R3
    31  	MOVW	R3, mono+12(FP)
    32  	MOVW	R4, mono+16(FP)
    33  
    34  	MOVW	$_SYSTEM_TIME, R3
    35  wall:
    36  	MOVW	time_hi1(R3), R1
    37  	MOVW	time_lo(R3), R0
    38  	MOVW	time_hi2(R3), R2
    39  	CMP	R1, R2
    40  	BNE	wall
    41  
    42  	// w = R1:R0 in 100ns untis
    43  	// convert to Unix epoch (but still 100ns units)
    44  	#define delta 116444736000000000
    45  	SUB.S   $(delta & 0xFFFFFFFF), R0
    46  	SBC     $(delta >> 32), R1
    47  
    48  	// Convert to nSec
    49  	MOVW    $100, R2
    50  	MULLU   R0, R2, (R4, R3)    // R4:R3 = R1:R0 * R2
    51  	MULA    R1, R2, R4, R4
    52  	// w = R2:R1 in nSec
    53  	MOVW    R3, R1	      // R4:R3 -> R2:R1
    54  	MOVW    R4, R2
    55  
    56  	// multiply nanoseconds by reciprocal of 10**9 (scaled by 2**61)
    57  	// to get seconds (96 bit scaled result)
    58  	MOVW	$0x89705f41, R3		// 2**61 * 10**-9
    59  	MULLU	R1,R3,(R6,R5)		// R7:R6:R5 = R2:R1 * R3
    60  	MOVW	$0,R7
    61  	MULALU	R2,R3,(R7,R6)
    62  
    63  	// unscale by discarding low 32 bits, shifting the rest by 29
    64  	MOVW	R6>>29,R6		// R7:R6 = (R7:R6:R5 >> 61)
    65  	ORR	R7<<3,R6
    66  	MOVW	R7>>29,R7
    67  
    68  	// subtract (10**9 * sec) from nsec to get nanosecond remainder
    69  	MOVW	$1000000000, R5	// 10**9
    70  	MULLU	R6,R5,(R9,R8)   // R9:R8 = R7:R6 * R5
    71  	MULA	R7,R5,R9,R9
    72  	SUB.S	R8,R1		// R2:R1 -= R9:R8
    73  	SBC	R9,R2
    74  
    75  	// because reciprocal was a truncated repeating fraction, quotient
    76  	// may be slightly too small -- adjust to make remainder < 10**9
    77  	CMP	R5,R1	// if remainder > 10**9
    78  	SUB.HS	R5,R1   //    remainder -= 10**9
    79  	ADD.HS	$1,R6	//    sec += 1
    80  
    81  	MOVW	R6,sec_lo+0(FP)
    82  	MOVW	R7,sec_hi+4(FP)
    83  	MOVW	R1,nsec+8(FP)
    84  	RET
    85  useQPC:
    86  	B	runtime·nowQPC(SB)		// tail call
    87  
    88  

View as plain text