------- Comment #5 from burnus at gcc dot gnu dot org  2006-11-02 16:02 -------
Created an attachment (id=12535)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12535&action=view)
Idea how libgfortran/intrinsic/system_clock.c could look like

Some bits of thought.

Methods obtaining the time:
* clock_gettime() [POSIX]
  10^-9s (nanosecond) resolution, options:
  CLOCK_REALTIME  - on unix time since the epoch [I would suggested this]
  CLOCK_MONOTONIC - survives even changing the time,
     but starting point is arbitrary
  See also PR 15516 for assembler calling sequences for Linux

* gettimeofday (&tv, NULL) [POSIX]
  10^-6s (microsecond) resolution

* time() [POSIX]
  second resolution


Resolution -> time able to be represented
---------------------------------------------
For huge(i4) = 2147483647
1000 ms:    68 years
 100 ms:  2485 days
  10 ms:   246 days
   1 ms:    25 days
 100 us:    60 hours
  10 us:     6 hours
=> 10 ms seems to be a good resolution, 25 days might be a bit short for some
calculation jobs, but 250 days should be enough.

For huge(i8) = 9223372036854775807
1  s:      2e11 years
1 ms:      2e8  years
1 us: 292271    years
1 ns:    292    years
=> 1 ns seems to be ok

I'm thinking of the following library implementation:
Only do integer(8) as this seems to be enough. (See attachment.)

For iresolve.c one needs to do something like the following (pseudo code):

if(count != NULL && counts.type != 8)
  gfc_convert_type()
if(count != NULL && count_max.type != 8)
  gfc_convert_type()
if(count != NULL && count_rate.type != 8)
  gfc_convert_type()

c->resolved_sym = gfc_get_intrinsic_sub_symbol ("system_clock")

if (count != NULL && count.type == 4)
   count = (int4) ((count8/10000000) % GFC_INTEGER_4_HUGE)
else if (count != NULL && count.type != 8)
   count = (type) count8

if (count_rate != NULL && count_rate.type == 4)
   add_expression("if(count_rate8 == 0) count_rate = 0"
                  "else count_rate = 100")
else if (count != NULL && count.type != 8)
   count_rate = (type) count_rate8

if (count_max != NULL && count_max.type == 4)
   add_expression("if(count_max8 == 0) count_max = 0"
                  "else count_max = GFC_INTEGER_4_HUGE")
else if (count != NULL && count.type != 8)
   count_rate = (type) count_rate8


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28484

Reply via email to