summaryrefslogtreecommitdiffstats
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorjanus <janus@138bc75d-0d04-0410-961f-82ee72b054a4>2012-12-03 22:06:41 +0000
committerjanus <janus@138bc75d-0d04-0410-961f-82ee72b054a4>2012-12-03 22:06:41 +0000
commite333484ff34ed3c15f501f46a6f36caafe4e1a5a (patch)
tree8dc0c5e4e2960946445f05352b2e3c0644e44266 /libgfortran/intrinsics
parent9f78c31e7f21fbafffc6a1778f70fc7b85324510 (diff)
downloadppe42-gcc-e333484ff34ed3c15f501f46a6f36caafe4e1a5a.tar.gz
ppe42-gcc-e333484ff34ed3c15f501f46a6f36caafe4e1a5a.zip
2012-12-03 Janus Weil <janus@gcc.gnu.org>
PR fortran/55548 * intrinsics/system_clock.c (gf_gettime_mono): Add argument 'tck', which returns the clock resolution. (system_clock_4): Get resolution from gf_gettime_mono, but limit to 1000/s. (system_clock_8): Get resolution from gf_gettime_mono. 2012-12-03 Janus Weil <janus@gcc.gnu.org> PR fortran/55548 * intrinsic.texi (SYSTEM_CLOCK): Update documentation of SYSTEM_CLOCK. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194105 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r--libgfortran/intrinsics/system_clock.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/libgfortran/intrinsics/system_clock.c b/libgfortran/intrinsics/system_clock.c
index 6385c4f0c95..9d5ba528ce3 100644
--- a/libgfortran/intrinsics/system_clock.c
+++ b/libgfortran/intrinsics/system_clock.c
@@ -64,6 +64,7 @@ static int weak_gettime (clockid_t, struct timespec *)
Arguments:
secs - OUTPUT, seconds
nanosecs - OUTPUT, nanoseconds
+ tk - OUTPUT, clock resolution [counts/sec]
If the target supports a monotonic clock, the OUTPUT arguments
represent a monotonically incrementing clock starting from some
@@ -76,11 +77,12 @@ static int weak_gettime (clockid_t, struct timespec *)
is set.
*/
static int
-gf_gettime_mono (time_t * secs, long * nanosecs)
+gf_gettime_mono (time_t * secs, long * nanosecs, long * tck)
{
int err;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
+ *tck = 1000000000;
err = clock_gettime (GF_CLOCK_MONOTONIC, &ts);
*secs = ts.tv_sec;
*nanosecs = ts.tv_nsec;
@@ -90,12 +92,14 @@ gf_gettime_mono (time_t * secs, long * nanosecs)
if (weak_gettime)
{
struct timespec ts;
+ *tck = 1000000000;
err = weak_gettime (GF_CLOCK_MONOTONIC, &ts);
*secs = ts.tv_sec;
*nanosecs = ts.tv_nsec;
return err;
}
#endif
+ *tck = 1000000;
err = gf_gettime (secs, nanosecs);
*nanosecs *= 1000;
return err;
@@ -118,21 +122,20 @@ void
system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
GFC_INTEGER_4 *count_max)
{
-#undef TCK
-#define TCK 1000
GFC_INTEGER_4 cnt;
GFC_INTEGER_4 mx;
time_t secs;
- long nanosecs;
+ long nanosecs, tck;
if (sizeof (secs) < sizeof (GFC_INTEGER_4))
internal_error (NULL, "secs too small");
- if (gf_gettime_mono (&secs, &nanosecs) == 0)
+ if (gf_gettime_mono (&secs, &nanosecs, &tck) == 0)
{
- GFC_UINTEGER_4 ucnt = (GFC_UINTEGER_4) secs * TCK;
- ucnt += (nanosecs + 500000000 / TCK) / (1000000000 / TCK);
+ tck = tck>1000 ? 1000 : tck;
+ GFC_UINTEGER_4 ucnt = (GFC_UINTEGER_4) secs * tck;
+ ucnt += (nanosecs + 500000000 / tck) / (1000000000 / tck);
if (ucnt > GFC_INTEGER_4_HUGE)
cnt = ucnt - GFC_INTEGER_4_HUGE - 1;
else
@@ -153,7 +156,7 @@ system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
if (count != NULL)
*count = cnt;
if (count_rate != NULL)
- *count_rate = TCK;
+ *count_rate = tck;
if (count_max != NULL)
*count_max = mx;
}
@@ -165,21 +168,19 @@ void
system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
GFC_INTEGER_8 *count_max)
{
-#undef TCK
-#define TCK 1000000000
GFC_INTEGER_8 cnt;
GFC_INTEGER_8 mx;
time_t secs;
- long nanosecs;
+ long nanosecs, tck;
if (sizeof (secs) < sizeof (GFC_INTEGER_4))
internal_error (NULL, "secs too small");
- if (gf_gettime_mono (&secs, &nanosecs) == 0)
+ if (gf_gettime_mono (&secs, &nanosecs, &tck) == 0)
{
- GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * TCK;
- ucnt += (nanosecs + 500000000 / TCK) / (1000000000 / TCK);
+ GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * tck;
+ ucnt += (nanosecs + 500000000 / tck) / (1000000000 / tck);
if (ucnt > GFC_INTEGER_8_HUGE)
cnt = ucnt - GFC_INTEGER_8_HUGE - 1;
else
@@ -201,7 +202,7 @@ system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
if (count != NULL)
*count = cnt;
if (count_rate != NULL)
- *count_rate = TCK;
+ *count_rate = tck;
if (count_max != NULL)
*count_max = mx;
}
OpenPOWER on IntegriCloud