Skip to content

Commit

Permalink
Merge pull request #30 from isuruf/filetime
Browse files Browse the repository at this point in the history
[runtime/util] implement filetime_to_int64
  • Loading branch information
isuruf authored Oct 29, 2017
2 parents 23236a6 + a56292e commit b64e602
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 52 deletions.
38 changes: 7 additions & 31 deletions runtime/flang/dtime3f.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@
#include <sys/types.h>
#include <limits.h>

#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)
#ifdef _WIN32
#include "times_win32.h"
#define CLK_TCK 10000000.0
#else
#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)
#endif
#endif

#ifndef _WIN32
static clock_t accum_user = 0, accum_sys = 0;

float ENT3F(DTIME, dtime)(float *tarray)
Expand All @@ -50,33 +54,5 @@ float ENT3F(DTIME, dtime)(float *tarray)
accum_sys = b.tms_stime;
return (tarray[0] + tarray[1]);
}
#else
#include <Windows.h>
static FILETIME accum_user;
static FILETIME accum_sys;

float convert_filetime( const FILETIME *ac_FileTime )
{
ULARGE_INTEGER lv_Large ;

lv_Large.LowPart = ac_FileTime->dwLowDateTime ;
lv_Large.HighPart = ac_FileTime->dwHighDateTime ;

return (float)lv_Large.QuadPart ;
}

float ENT3F(DTIME, dtime)(float *tarray)
{

FILETIME time_create;
FILETIME time_exit;

GetProcessTimes( GetCurrentProcess(),
&time_create, &time_exit, &accum_sys, &accum_user );

tarray[0] = ((float)(convert_filetime(&accum_user)));
tarray[1] = ((float)(convert_filetime(&accum_sys)));
return (tarray[0] + tarray[1]);
}
#endif

29 changes: 8 additions & 21 deletions runtime/flang/etime3f.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
#include <sys/types.h>
#include <limits.h>

#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)

#ifdef _WIN32
#include "times_win32.h"
#define CLK_TCK 10000000.0
#else
#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)
#endif
#endif

#ifndef _WIN32
float ENT3F(ETIME, etime)(float *tarray)
{
struct tms b;
Expand All @@ -49,21 +54,3 @@ float ENT3F(ETIME, etime)(float *tarray)
return (tarray[0] + tarray[1]);
}

#else
#include <Windows.h>

float ENT3F(ETIME, etime)(float *tarray)
{
FILETIME accum_user;
FILETIME accum_sys;
FILETIME time_create;
FILETIME time_exit;

GetProcessTimes( GetCurrentProcess(),
&time_create, &time_exit, &accum_sys, &accum_user );

tarray[0] = ((float)(convert_filetime(&accum_user)));
tarray[1] = ((float)(convert_filetime(&accum_sys)));
return (tarray[0] + tarray[1]);
}
#endif
27 changes: 27 additions & 0 deletions runtime/flang/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,30 @@ void __fort_ftnstrcpy(char *dst, /* destination string, blank-filled */
*dst++ = ' ';
}


#ifdef _WIN32
#include "times_win32.h"

clock_t convert_filetime( const FILETIME *ac_FileTime )
{
ULARGE_INTEGER lv_Large ;

lv_Large.LowPart = ac_FileTime->dwLowDateTime ;
lv_Large.HighPart = ac_FileTime->dwHighDateTime ;

return (clock_t)lv_Large.QuadPart ;
}

/*
Thin emulation of the unix times function
*/
void times(tms *time_struct) {
FILETIME time_create, time_exit, accum_sys, accum_user;

GetProcessTimes( GetCurrentProcess(),
&time_create, &time_exit, &accum_sys, &accum_user );

time_struct->tms_utime = convert_filetime(&accum_user);
time_struct->tms_stime = convert_filetime(&accum_sys);
}
#endif
20 changes: 20 additions & 0 deletions runtime/include/times_win32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _FLANG_TIMES_WIN32
#define _FLANG_TIMES_WIN32
#include <Windows.h>

typedef __int64 clock_t;

typedef struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time of children */
clock_t tms_cstime; /* system time of children */
} tms;

clock_t convert_filetime( const FILETIME *ac_FileTime );

/*
Thin emulation of the unix times function
*/
void times(tms *time_struct);
#endif

0 comments on commit b64e602

Please sign in to comment.