Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:04

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H
0011 #define _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H
0012 
0013 #include <time.h>
0014 
0015 inline _LIBCPP_HIDE_FROM_ABI int gettimeofdayMonotonic(struct timespec64* Output) {
0016   // The POSIX gettimeofday() function is not available on z/OS. Therefore,
0017   // we will call stcke and other hardware instructions in implement equivalent.
0018   // Note that nanoseconds alone will overflow when reaching new epoch in 2042.
0019 
0020   struct _t {
0021     uint64_t Hi;
0022     uint64_t Lo;
0023   };
0024   struct _t Value = {0, 0};
0025   uint64_t CC     = 0;
0026   asm(" stcke %0\n"
0027       " ipm %1\n"
0028       " srlg %1,%1,28\n"
0029       : "=m"(Value), "+r"(CC)::);
0030 
0031   if (CC != 0) {
0032     errno = EMVSTODNOTSET;
0033     return CC;
0034   }
0035   uint64_t us = (Value.Hi >> 4);
0036   uint64_t ns = ((Value.Hi & 0x0F) << 8) + (Value.Lo >> 56);
0037   ns          = (ns * 1000) >> 12;
0038   us          = us - 2208988800000000;
0039 
0040   register uint64_t DivPair0 asm("r0"); // dividend (upper half), remainder
0041   DivPair0 = 0;
0042   register uint64_t DivPair1 asm("r1"); // dividend (lower half), quotient
0043   DivPair1         = us;
0044   uint64_t Divisor = 1000000;
0045   asm(" dlgr %0,%2" : "+r"(DivPair0), "+r"(DivPair1) : "r"(Divisor) :);
0046 
0047   Output->tv_sec  = DivPair1;
0048   Output->tv_nsec = DivPair0 * 1000 + ns;
0049   return 0;
0050 }
0051 
0052 #endif // _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H