github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/runtime/time_windows_386.s (about) 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 7 #include "go_asm.h" 8 #include "textflag.h" 9 #include "time_windows.h" 10 11 TEXT time·now(SB),NOSPLIT,$0-20 12 CMPB runtime·useQPCTime(SB), $0 13 JNE useQPC 14 loop: 15 MOVL (_INTERRUPT_TIME+time_hi1), AX 16 MOVL (_INTERRUPT_TIME+time_lo), CX 17 MOVL (_INTERRUPT_TIME+time_hi2), DI 18 CMPL AX, DI 19 JNE loop 20 21 // w = DI:CX 22 // multiply by 100 23 MOVL $100, AX 24 MULL CX 25 IMULL $100, DI 26 ADDL DI, DX 27 // w*100 = DX:AX 28 MOVL AX, mono+12(FP) 29 MOVL DX, mono+16(FP) 30 31 wall: 32 MOVL (_SYSTEM_TIME+time_hi1), CX 33 MOVL (_SYSTEM_TIME+time_lo), AX 34 MOVL (_SYSTEM_TIME+time_hi2), DX 35 CMPL CX, DX 36 JNE wall 37 38 // w = DX:AX 39 // convert to Unix epoch (but still 100ns units) 40 #define delta 116444736000000000 41 SUBL $(delta & 0xFFFFFFFF), AX 42 SBBL $(delta >> 32), DX 43 44 // nano/100 = DX:AX 45 // split into two decimal halves by div 1e9. 46 // (decimal point is two spots over from correct place, 47 // but we avoid overflow in the high word.) 48 MOVL $1000000000, CX 49 DIVL CX 50 MOVL AX, DI 51 MOVL DX, SI 52 53 // DI = nano/100/1e9 = nano/1e11 = sec/100, DX = SI = nano/100%1e9 54 // split DX into seconds and nanoseconds by div 1e7 magic multiply. 55 MOVL DX, AX 56 MOVL $1801439851, CX 57 MULL CX 58 SHRL $22, DX 59 MOVL DX, BX 60 IMULL $10000000, DX 61 MOVL SI, CX 62 SUBL DX, CX 63 64 // DI = sec/100 (still) 65 // BX = (nano/100%1e9)/1e7 = (nano/1e9)%100 = sec%100 66 // CX = (nano/100%1e9)%1e7 = (nano%1e9)/100 = nsec/100 67 // store nsec for return 68 IMULL $100, CX 69 MOVL CX, nsec+8(FP) 70 71 // DI = sec/100 (still) 72 // BX = sec%100 73 // construct DX:AX = 64-bit sec and store for return 74 MOVL $0, DX 75 MOVL $100, AX 76 MULL DI 77 ADDL BX, AX 78 ADCL $0, DX 79 MOVL AX, sec+0(FP) 80 MOVL DX, sec+4(FP) 81 RET 82 useQPC: 83 JMP runtime·nowQPC(SB) 84 RET