Text file src/runtime/time_windows_arm.s

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

View as plain text