[flang-commits] [PATCH] D123624: [flang] Use full result range for clock_gettime implementation of SYSTEM_CLOCK

vdonaldson via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Apr 12 11:46:31 PDT 2022


vdonaldson created this revision.
vdonaldson added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
vdonaldson requested review of this revision.

Update the primary clock_gettime implementation of SYSTEM_CLOCK to use
the full range of values, dependent on the type kind of the requested
result.  Counts/sec and count max for supported kinds become:

  kind          counts/sec             count max
  
     1                  10                   127
     2                1000                 32767
     4                1000            2147483647
     8          1000000000   9223372036854775807
    16          1000000000   9223372036854775807

The secondary "fallback" implementation is not changed.

Real valued COUNT_RATE arguments are not changed.

The test program below has calls for kinds 1, 2, 4, 8, 16.  Support for
these types varies by compiler.  The code as given can be restricted to
accommodate these variations, with results shown below.

  subroutine c
    integer(1) c1, r1, m1
    integer(2) c2, r2, m2
    integer(4) c4, r4, m4
    integer(8) c8, r8, m8
    integer(16) c16, r16, m16
  
    print*
    print '(a5,3a22)', 'kind', 'counts/sec', 'count max', 'count'
    print*
  
    call system_clock(c1, r1, m1)
    print '(i5,3i22)', 1, r1, m1, c1
  
    call system_clock(c2, r2, m2)
    print '(i5,3i22)', 2, r2, m2, c2
  
    call system_clock(c4, r4, m4)
    print '(i5,3i22)', 4, r4, m4, c4
  
    call system_clock(c8, r8, m8)
    print '(i5,3i22)', 8, r8, m8, c8
  
    call system_clock(c16, r16, m16)
    print '(i5,3i22)', 16, r16, m16, c16
  end
  
  subroutine k(j)
    j = 0
    do i=1,1000000000
      j = j + i
    enddo
  end
  
  program p
    do i=1,1 ! increase loop count to check for (kind=1) wraparound
      call k(j)
      call c
    enddo
  end

flang output without change (last column counts vary per run)

  kind          counts/sec             count max                 count
  
     1                 -24                   127                    83
     2                1000                   290                   211
     4                1000                   290                   211
     8          1000000000             290448383             211631452
    16          1000000000             290448383             211633853

flang output with change (last column counts vary per run)

  kind          counts/sec             count max                 count
  
     1                  10                   127                    21
     2                1000                 32767                  2100
     4                1000            2147483647                  2100
     8          1000000000   9223372036854775807            2100183374
    16          1000000000   9223372036854775807            2100185353

Other compilers; kind support varies (last column counts vary per run).
Test and ouput modified to avoid crashes and normalize results.
Some negative values indicate unsupported kinds; others are bugs.

   kind          counts/sec             count max                 count
  
      1                   0                     0                  -127
      2                   0                     0                -32767
      4                1000            2147483647              69271692
      8          1000000000   9223372036854775807        69271692353290
     16          1000000000   9223372036854775807        69271692354794
  
  =======
  
      1                  10                   127                     0
      2                1000                 32767                     0
      4             1000000            2147483647                     0
      8            10000000   9223372036854775807                     9
  
  =======
  
      1                   0                     0                  -127
      2                1000                 32767                  3263
      4               10000            2147483647            1788192630
      8             1000000   9223372036854775807      1649443459263095
  
  =======
  
      1                 -24                    -1                    36
      2                1000                    -1                -10716
      4                1000            2147483647             176018980
      8                1000   9223372036854775807         1649443460644
  
  =======
  
      2                 100                 28799                 23080
      4                 100               8639999               4285480
      8                 100               8639999               4285480
     16                 100               8639999               4285480
  
  =======
  
      1                 -24                    -1                     4
      2                1000                 23551                -26108
      4                1000              86399999              67541508
      8             1000000   9223372036854775807      1649443541508087


https://reviews.llvm.org/D123624

Files:
  flang/docs/Extensions.md
  flang/runtime/time-intrinsic.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123624.422302.patch
Type: text/x-patch
Size: 4805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220412/94eab306/attachment.bin>


More information about the flang-commits mailing list