poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] ios: fix write of {,u}int<{16,24,32,40,48,56,64}>


From: Jose E. Marchesi
Subject: Re: [PATCH] ios: fix write of {,u}int<{16,24,32,40,48,56,64}>
Date: Sun, 06 Aug 2023 16:54:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

OK for master and maint/poke-3.
Thanks!

> 2023-08-06  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>
>       * liboke/ios.c (ios_write_int_common): Fix the function when `bits'
>       is 16, 24, 32, 40, 48, 56, 64.
>       * testsuite/poke.map/maps-uint-write-75.pk: New test.
>       * testsuite/poke.map/maps-uint-write-76.pk: Likewise.
>       * testsuite/poke.map/maps-uint-write-77.pk: Likewise.
>       * testsuite/poke.map/maps-uint-write-78.pk: Likewise.
>       * testsuite/poke.map/maps-uint-write-79.pk: Likewise.
>       * testsuite/poke.map/maps-uint-write-80.pk: Likewise.
>       * testsuite/poke.map/maps-uint-write-81.pk: Likewise.
>       * testsuite/Makefile.am (EXTRA_DIST): Update.
> ---
>  ChangeLog                                | 13 +++++
>  libpoke/ios.c                            | 34 +++++++------
>  testsuite/Makefile.am                    |  7 +++
>  testsuite/poke.map/maps-uint-write-75.pk | 30 +++++++++++
>  testsuite/poke.map/maps-uint-write-76.pk | 36 ++++++++++++++
>  testsuite/poke.map/maps-uint-write-77.pk | 42 ++++++++++++++++
>  testsuite/poke.map/maps-uint-write-78.pk | 48 ++++++++++++++++++
>  testsuite/poke.map/maps-uint-write-79.pk | 54 ++++++++++++++++++++
>  testsuite/poke.map/maps-uint-write-80.pk | 60 ++++++++++++++++++++++
>  testsuite/poke.map/maps-uint-write-81.pk | 63 ++++++++++++++++++++++++
>  10 files changed, 373 insertions(+), 14 deletions(-)
>  create mode 100644 testsuite/poke.map/maps-uint-write-75.pk
>  create mode 100644 testsuite/poke.map/maps-uint-write-76.pk
>  create mode 100644 testsuite/poke.map/maps-uint-write-77.pk
>  create mode 100644 testsuite/poke.map/maps-uint-write-78.pk
>  create mode 100644 testsuite/poke.map/maps-uint-write-79.pk
>  create mode 100644 testsuite/poke.map/maps-uint-write-80.pk
>  create mode 100644 testsuite/poke.map/maps-uint-write-81.pk
>
> diff --git a/ChangeLog b/ChangeLog
> index cd17e6d8..25bcdefe 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,16 @@
> +2023-08-06  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * liboke/ios.c (ios_write_int_common): Fix the function when `bits'
> +     is 16, 24, 32, 40, 48, 56, 64.
> +     * testsuite/poke.map/maps-uint-write-75.pk: New test.
> +     * testsuite/poke.map/maps-uint-write-76.pk: Likewise.
> +     * testsuite/poke.map/maps-uint-write-77.pk: Likewise.
> +     * testsuite/poke.map/maps-uint-write-78.pk: Likewise.
> +     * testsuite/poke.map/maps-uint-write-79.pk: Likewise.
> +     * testsuite/poke.map/maps-uint-write-80.pk: Likewise.
> +     * testsuite/poke.map/maps-uint-write-81.pk: Likewise.
> +     * testsuite/Makefile.am (EXTRA_DIST): Update.
> +
>  2023-07-06  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>  
>       * doc/poke.texi (Integral Structs): Update.
> diff --git a/libpoke/ios.c b/libpoke/ios.c
> index 073d3e52..974aface 100644
> --- a/libpoke/ios.c
> +++ b/libpoke/ios.c
> @@ -1335,7 +1335,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      if (bits <= 16)
> +      if (bits < 16)
>          value = ((value & 0xff) << (bits % 8))
>                  | (value & 0xff00) >> 8;
>        else
> @@ -1362,7 +1362,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      if (bits <= 24)
> +      if (bits < 24)
>          value = ((value & 0xff) << (8 + bits % 8))
>                  | (value & 0xff00) >> (8 - bits % 8)
>                  | (value & 0xff0000) >> 16;
> @@ -1392,7 +1392,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      if (bits <= 32)
> +      if (bits < 32)
>          value = ((value & 0xff) << (16 + bits % 8))
>                  | (value & 0xff00) << (bits % 8)
>                  | (value & 0xff0000) >> (16 - bits % 8)
> @@ -1425,7 +1425,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      if (bits <= 40)
> +      if (bits < 40)
>          value = ((value & 0xff) << (24 + bits % 8))
>                  | (value & 0xff00) << (8 + bits % 8)
>                  | (value & 0xff0000) >> (8 - bits % 8)
> @@ -1461,7 +1461,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      if (bits <= 48)
> +      if (bits < 48)
>          value = ((value & 0xff) << (32 + bits % 8))
>                  | (value & 0xff00) << (16 + bits % 8)
>                  | (value & 0xff0000) << (bits % 8)
> @@ -1500,7 +1500,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      if (bits <= 56)
> +      if (bits < 56)
>          value = ((value & 0xff) << (40 + bits % 8))
>                  | (value & 0xff00) << (24 + bits % 8)
>                  | (value & 0xff0000) << (8 + bits % 8)
> @@ -1542,14 +1542,20 @@ ios_write_int_common (ios io, ios_off offset, int 
> flags,
>        /* Convert to the little endian format. For example a 12-bit-long
>           number's bits get reordered as 7-6-5-4-3-2-1-0-11-10-9-8
>           with leading 0s.  */
> -      value = ((value & 0xff) << (48 + bits % 8))
> -              | (value & 0xff00) << (32 + bits % 8)
> -              | (value & 0xff0000) << (16 + bits % 8)
> -              | (value & 0xff000000) << (bits % 8)
> -              | (value & 0xff00000000) >> (16 - bits % 8)
> -              | (value & 0xff0000000000) >> (32 - bits % 8)
> -              | (value & 0xff000000000000) >> (48 - bits % 8)
> -              | (value & 0xff00000000000000) >> 56;
> +      if (bits < 64)
> +        value = ((value & 0xff) << (48 + bits % 8))
> +                | (value & 0xff00) << (32 + bits % 8)
> +                | (value & 0xff0000) << (16 + bits % 8)
> +                | (value & 0xff000000) << (bits % 8)
> +                | (value & 0xff00000000) >> (16 - bits % 8)
> +                | (value & 0xff0000000000) >> (32 - bits % 8)
> +                | (value & 0xff000000000000) >> (48 - bits % 8)
> +                | (value & 0xff00000000000000) >> 56;
> +      else
> +        {
> +          assert (bits == 64);
> +          value = bswap_64 (value);
> +        }
>      }
>      c[0] |= value >> (56 + lastbyte_bits);
>      c[1] = (value >> (48 + lastbyte_bits)) & 0xff;
> diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
> index 22ea486e..feaca20d 100644
> --- a/testsuite/Makefile.am
> +++ b/testsuite/Makefile.am
> @@ -537,6 +537,13 @@ EXTRA_DIST = \
>    poke.map/maps-uint-write-72.pk \
>    poke.map/maps-uint-write-73.pk \
>    poke.map/maps-uint-write-74.pk \
> +  poke.map/maps-uint-write-75.pk \
> +  poke.map/maps-uint-write-76.pk \
> +  poke.map/maps-uint-write-77.pk \
> +  poke.map/maps-uint-write-78.pk \
> +  poke.map/maps-uint-write-79.pk \
> +  poke.map/maps-uint-write-80.pk \
> +  poke.map/maps-uint-write-81.pk \
>    poke.map/maps-unions-1.pk \
>    poke.map/maps-unions-2.pk \
>    poke.map/maps-unions-3.pk \
> diff --git a/testsuite/poke.map/maps-uint-write-75.pk 
> b/testsuite/poke.map/maps-uint-write-75.pk
> new file mode 100644
> index 00000000..a61f2c7b
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-75.pk
> @@ -0,0 +1,30 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<16>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<16> @ fd : off = m1;
> +
> +    var ok = (uint<16> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> diff --git a/testsuite/poke.map/maps-uint-write-76.pk 
> b/testsuite/poke.map/maps-uint-write-76.pk
> new file mode 100644
> index 00000000..e98cfa64
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-76.pk
> @@ -0,0 +1,36 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<24>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<24> @ fd : off = m1;
> +
> +    var ok = (uint<24> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (23#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (25#b)} } */
> +/* { dg-output "1\n" } */
> diff --git a/testsuite/poke.map/maps-uint-write-77.pk 
> b/testsuite/poke.map/maps-uint-write-77.pk
> new file mode 100644
> index 00000000..51e318ea
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-77.pk
> @@ -0,0 +1,42 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<32>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<32> @ fd : off = m1;
> +
> +    var ok = (uint<32> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (23#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (25#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (31#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (33#b)} } */
> +/* { dg-output "1\n" } */
> diff --git a/testsuite/poke.map/maps-uint-write-78.pk 
> b/testsuite/poke.map/maps-uint-write-78.pk
> new file mode 100644
> index 00000000..213c39c7
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-78.pk
> @@ -0,0 +1,48 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<40>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<40> @ fd : off = m1;
> +
> +    var ok = (uint<40> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (23#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (25#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (31#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (33#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (39#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (41#b)} } */
> +/* { dg-output "1\n" } */
> diff --git a/testsuite/poke.map/maps-uint-write-79.pk 
> b/testsuite/poke.map/maps-uint-write-79.pk
> new file mode 100644
> index 00000000..faaa40d0
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-79.pk
> @@ -0,0 +1,54 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<48>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<48> @ fd : off = m1;
> +
> +    var ok = (uint<48> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (23#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (25#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (31#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (33#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (39#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (41#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (47#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (49#b)} } */
> +/* { dg-output "1\n" } */
> diff --git a/testsuite/poke.map/maps-uint-write-80.pk 
> b/testsuite/poke.map/maps-uint-write-80.pk
> new file mode 100644
> index 00000000..51ee6f57
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-80.pk
> @@ -0,0 +1,60 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<56>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<56> @ fd : off = m1;
> +
> +    var ok = (uint<56> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (23#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (25#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (31#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (33#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (39#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (41#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (47#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (49#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (55#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (57#b)} } */
> +/* { dg-output "1\n" } */
> diff --git a/testsuite/poke.map/maps-uint-write-81.pk 
> b/testsuite/poke.map/maps-uint-write-81.pk
> new file mode 100644
> index 00000000..3f25f1ad
> --- /dev/null
> +++ b/testsuite/poke.map/maps-uint-write-81.pk
> @@ -0,0 +1,63 @@
> +/* { dg-do run } */
> +
> +var m1 = -1UL as uint<64>;
> +
> +fun test = (offset<int<64>,b> off) int<32>:
> +  {
> +    var fd = open ("*mem*");
> +
> +    uint<64> @ fd : off = m1;
> +
> +    var ok = (uint<64> @ fd : off) == m1;
> +
> +    close (fd);
> +    return ok;
> +  }
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {.set endian little} } */
> +
> +/* { dg-command {test (1#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (7#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (9#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (15#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (23#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (25#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (31#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (33#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (39#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (41#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (47#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (49#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (55#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (57#b)} } */
> +/* { dg-output "1\n" } */
> +
> +/* { dg-command {test (63#b)} } */
> +/* { dg-output "1\n" } */



reply via email to

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