[flang-commits] [flang] [flang] Add ETIME runtime and lowering intrinsics implementation (PR #90578)
jiajie zhang via flang-commits
flang-commits at lists.llvm.org
Tue Apr 30 20:53:10 PDT 2024
================
@@ -370,5 +374,69 @@ void RTNAME(DateAndTime)(char *date, std::size_t dateChars, char *time,
terminator, date, dateChars, time, timeChars, zone, zoneChars, values);
}
+void RTNAME(Etime)(const Descriptor *values, const Descriptor *time,
+ const char *sourceFile, int line) {
+ Fortran::runtime::Terminator terminator{sourceFile, line};
+
+ double usrTime = -1.0, sysTime = -1.0, realTime = -1.0;
+
+#ifdef _WIN32
+ FILETIME creationTime;
+ FILETIME exitTime;
+ FILETIME kernelTime;
+ FILETIME userTime;
+
+ if (GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime,
+ &kernelTime, &userTime) != -1) {
+ ULARGE_INTEGER userSystemTime;
+ ULARGE_INTEGER kernelSystemTime;
+
+ memcpy(&userSystemTime, &userTime, sizeof(FILETIME));
+ memcpy(&kernelSystemTime, &kernelTime, sizeof(FILETIME));
+
+ usrTime = double(userSystemTime.QuadPart / 10000);
+ sysTime = double(kernelSystemTime.QuadPart / 10000);
+ realTime = usrTime + sysTime;
+ }
+#else
+ struct tms tms;
+ if (times(&tms) != -1) {
+ usrTime = (double)(tms.tms_utime) / sysconf(_SC_CLK_TCK);
+ sysTime = (double)(tms.tms_stime) / sysconf(_SC_CLK_TCK);
----------------
JumpMasterJJ wrote:
It should perform floating division on Windows. I'll update it later.
https://github.com/llvm/llvm-project/pull/90578
More information about the flang-commits
mailing list