11package hrtime
22
33import (
4+ "math/bits"
45 "syscall"
56 "time"
67 "unsafe"
1920// getFrequency returns frequency in ticks per second.
2021func getFrequency () int64 {
2122 var freq int64
22- r1 , _ , _ := syscall .Syscall (procFreq .Addr (), 1 , uintptr (unsafe .Pointer (& freq )), 0 , 0 )
23+ r1 , _ , _ := syscall .SyscallN (procFreq .Addr (), uintptr (unsafe .Pointer (& freq )))
2324 if r1 == 0 {
2425 panic ("call failed" )
2526 }
@@ -29,7 +30,7 @@ func getFrequency() int64 {
2930// getCount returns counter ticks.
3031func getCount () int64 {
3132 var qpc int64
32- syscall .Syscall (procCounter .Addr (), 1 , uintptr (unsafe .Pointer (& qpc )), 0 , 0 )
33+ syscall .SyscallN (procCounter .Addr (), uintptr (unsafe .Pointer (& qpc )))
3334 return qpc
3435}
3536
@@ -38,7 +39,10 @@ func getCount() int64 {
3839// Now returns time offset from a specific time.
3940// The values aren't comparable between computer restarts or between computers.
4041func Now () time.Duration {
41- return time .Duration (getCount ()- qpcBase ) * time .Second / (time .Duration (qpcFrequency ) * time .Nanosecond )
42+ delta := uint64 (getCount () - qpcBase )
43+ hi , lo := bits .Mul64 (delta , uint64 (time .Second ))
44+ quo , _ := bits .Div64 (hi , lo , uint64 (qpcFrequency ))
45+ return time .Duration (quo )
4246}
4347
4448// NowPrecision returns maximum possible precision for Now in nanoseconds.
0 commit comments