bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 32-bit profiling counts?


From: Peter Lindgren
Subject: Re: 32-bit profiling counts?
Date: Sat, 6 Jun 2020 13:23:27 -0500

I was originally running on a Raspberry Pi 2 Model B Rev 1.1, which has a 
32-bit ARM Cortex-A7 processor. The OS is “Raspberry Pi OS”, which is basically 
Debian Buster with a different desktop look and feel. I was using gawk as 
installed by "sudo apt install gawk", which is as up-to-date as Debian provides 
there:

pi@pi2:~ $ gawk --version
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2018 Free Software Foundation.

I’ve just tried it on my Mac Mini, a 64-bit x86 machine. The OS is Mac OS 
Catalina. There I am using gawk as installed via home-brew, which is much newer:

peter@Peters-Mac-mini wordfiles % gawk --version
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
Copyright (C) 1989, 1991-2019 Free Software Foundation.


On the Mac, I get the same results as you do:

    # gawk profile, created Sat Jun 6 13:15:45 2020

    # BEGIN rule(s)

    BEGIN {
  1     two31plus1 = (1024 * 1024 * 1024 * 2) + 1
  1     status = 1024 * 1024 * 128
2147483649     for (x = 1; x <= two31plus1; x++) {
2147483649         if (! (x % status)) { # 16
  16             print "Status: " x
            }
        }
    }

Given that “long” is a slippery quantity - sometimes 32-bit, sometimes 64-bit - 
depending on the platform, perhaps these counts should be defined as “long 
long”, or int64_t, or even uint64_t, which would be 64-bits everywhere. 

Regards,
Peter




On Jun 6, 2020, at 10:35 AM, Andrew J. Schorr 
<aschorr@telemetry-investments.com> wrote:

Hi,

> On Fri, Jun 05, 2020 at 03:44:10PM +0000, Peter Lindgren wrote:
> I've been profiling a very long-running gawk program, and after some time the 
> counts of the innermost loops roll over to negative numbers. I wonder whether 
> the profile counts are 32-bit signed integers? Could you confirm this? And 
> what do you think about changing them to 64-bit integers?
> 
> This isn't my original program, but one designed just to show this issue:
> 
> 
> 
>         # gawk profile, created Fri Jun  5 09:17:14 2020
> 
> 
>         # BEGIN rule(s)
> 
> 
>         BEGIN {
>       1          two31plus1 = (1024 * 1024 * 1024 * 2) + 1
>       1          status = 1024 * 1024 * 128
> -2147483647    for (x = 1; x <= two31plus1; x++) {
> -2147483647            if (! (x % status)) { # 16
>     16                          print "Status: " x
>                         }
>                 }
>         }

What platform are you running on? From my inspection of the code, it looks like
the counts are stored in an integer of type "long".  In awk.h, I think the
relevant item is `exec_count', which is defined as `d.dl', and d.dl is a long.
On my CentOS Linux x86_64 system, that's a 64-bit signed integer, and here's
what I see when I run this program:

bash-4.2$ cat /tmp/profile.awk 
BEGIN {
      two31plus1 = 2^31+1
      status = 2^27
      for (x = 1; x <= two31plus1; x++) {
              if (! (x % status)) {
                      print "Status: " x
              }
      }
}
bash-4.2$ gawk --profile=myprof.out -f /tmp/profile.awk 
Status: 134217728
Status: 268435456
Status: 402653184
Status: 536870912
Status: 671088640
Status: 805306368
Status: 939524096
Status: 1073741824
Status: 1207959552
Status: 1342177280
Status: 1476395008
Status: 1610612736
Status: 1744830464
Status: 1879048192
Status: 2013265920
Status: 2147483648
bash-4.2$ cat myprof.out 
      # gawk profile, created Sat Jun  6 11:23:18 2020

      # BEGIN rule(s)

      BEGIN {
    1          two31plus1 = (1024 * 1024 * 1024 * 2) + 1
    1          status = 1024 * 1024 * 128
2147483649      for (x = 1; x <= two31plus1; x++) {
2147483649              if (! (x % status)) { # 16
  16                          print "Status: " x
                      }
              }
      }

Regards,
Andy

reply via email to

[Prev in Thread] Current Thread [Next in Thread]