poke-devel
[Top][All Lists]
Advanced

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

[PATCH] pkl: Fix bit-depth of negative numbers in print{i,l} insns


From: Mohammad-Reza Nabipoor
Subject: [PATCH] pkl: Fix bit-depth of negative numbers in print{i,l} insns
Date: Sat, 20 Feb 2021 01:06:58 +0330

2021-02-20  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>

        * libpoke/pvm.jitter (PVM_PRINTI): Fix bit-depth of printed negative
        values in base 8 and 16.
        (PVM_PRINTL): Likewise.
        * testsuite/poke.pkl/printf-28.pk: New test.
        * testsuite/poke.pkl/printf-29.pk: Likewise.
        * testsuite/poke.pkl/printf-30.pk: Likewise.
        * testsuite/poke.pkl/printf-31.pk: Likewise.
        * testsuite/poke.pkl/printf-32.pk: Likewise.
        * testsuite/poke.pkl/printf-33.pk: Likewise.
        * testsuite/poke.pkl/printf-34.pk: Likewise.
        * testsuite/poke.pkl/printf-35.pk: Likewise.
        * testsuite/Makefile.am (EXTRA_DIST): Update.
---
 ChangeLog                       | 15 +++++++++++++++
 libpoke/pvm.jitter              | 10 ++++++++--
 testsuite/Makefile.am           |  8 ++++++++
 testsuite/poke.pkl/printf-28.pk |  3 +++
 testsuite/poke.pkl/printf-29.pk |  3 +++
 testsuite/poke.pkl/printf-30.pk |  3 +++
 testsuite/poke.pkl/printf-31.pk |  3 +++
 testsuite/poke.pkl/printf-32.pk |  3 +++
 testsuite/poke.pkl/printf-33.pk |  3 +++
 testsuite/poke.pkl/printf-34.pk |  3 +++
 testsuite/poke.pkl/printf-35.pk |  4 ++++
 11 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/poke.pkl/printf-28.pk
 create mode 100644 testsuite/poke.pkl/printf-29.pk
 create mode 100644 testsuite/poke.pkl/printf-30.pk
 create mode 100644 testsuite/poke.pkl/printf-31.pk
 create mode 100644 testsuite/poke.pkl/printf-32.pk
 create mode 100644 testsuite/poke.pkl/printf-33.pk
 create mode 100644 testsuite/poke.pkl/printf-34.pk
 create mode 100644 testsuite/poke.pkl/printf-35.pk

diff --git a/ChangeLog b/ChangeLog
index cf77895d..6f892fd8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2021-02-20  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>
+
+       * libpoke/pvm.jitter (PVM_PRINTI): Fix bit-depth of printed negative
+       values in base 8 and 16.
+       (PVM_PRINTL): Likewise.
+       * testsuite/poke.pkl/printf-28.pk: New test.
+       * testsuite/poke.pkl/printf-29.pk: Likewise.
+       * testsuite/poke.pkl/printf-30.pk: Likewise.
+       * testsuite/poke.pkl/printf-31.pk: Likewise.
+       * testsuite/poke.pkl/printf-32.pk: Likewise.
+       * testsuite/poke.pkl/printf-33.pk: Likewise.
+       * testsuite/poke.pkl/printf-34.pk: Likewise.
+       * testsuite/poke.pkl/printf-35.pk: Likewise.
+       * testsuite/Makefile.am (EXTRA_DIST): Update.
+
 2021-02-19  Jose E. Marchesi  <jemarch@gnu.org>
 
        * pickles/dwarf-frame.pk (Dwarf_CIE): Fix constant.
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index c7e9668d..dba9307f 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -430,6 +430,9 @@ late-header-c
   {                                                                         \
     TYPEC val = PVM_VAL_##TYPE (JITTER_UNDER_TOP_STACK ());                 \
     char fmt[6];  /* %0NNd */                                               \
+    uint32_t mask                                                           \
+        = JITTER_ARGN0 == 32 ? (uint32_t)-1                                 \
+                             : (((uint32_t)1 << JITTER_ARGN0) - 1);         \
                                                                             \
     fmt[0] = '%';                                                           \
     fmt[1] = '0';                                                           \
@@ -471,7 +474,7 @@ late-header-c
       fmt[5] = '\0';                                                        \
     }                                                                       \
                                                                             \
-    pk_printf (fmt, val);                                                   \
+    pk_printf (fmt, (BASE) == 10 ? val : val & mask);                       \
     JITTER_DROP_STACK ();                                                   \
     JITTER_DROP_STACK ();                                                   \
   } while (0)
@@ -481,6 +484,9 @@ late-header-c
   {                                                                         \
     TYPEC val = PVM_VAL_##TYPE (JITTER_UNDER_TOP_STACK ());                 \
     char fmt[7];  /* %0NNff */                                              \
+    uint64_t mask                                                           \
+        = JITTER_ARGN0 == 64 ? (uint64_t)-1                                 \
+                             : (((uint64_t)1 << JITTER_ARGN0) - 1);         \
                                                                             \
     fmt[0] = '%';                                                           \
     fmt[1] = '0';                                                           \
@@ -517,7 +523,7 @@ late-header-c
       fmt[6] = '\0';                                                        \
     }                                                                       \
                                                                             \
-    pk_printf (fmt, val);                                                   \
+    pk_printf (fmt, (BASE) == 10 ? val : val & mask);                       \
     JITTER_DROP_STACK ();                                                   \
     JITTER_DROP_STACK ();                                                   \
   } while (0)
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index b476b363..c642cb30 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -1353,6 +1353,14 @@ EXTRA_DIST = \
   poke.pkl/printf-25.pk \
   poke.pkl/printf-26.pk \
   poke.pkl/printf-27.pk \
+  poke.pkl/printf-28.pk \
+  poke.pkl/printf-29.pk \
+  poke.pkl/printf-30.pk \
+  poke.pkl/printf-31.pk \
+  poke.pkl/printf-32.pk \
+  poke.pkl/printf-33.pk \
+  poke.pkl/printf-34.pk \
+  poke.pkl/printf-35.pk \
   poke.pkl/printf-binary-1.pk \
   poke.pkl/printf-binary-2.pk \
   poke.pkl/printf-binary-3.pk \
diff --git a/testsuite/poke.pkl/printf-28.pk b/testsuite/poke.pkl/printf-28.pk
new file mode 100644
index 00000000..2610c3be
--- /dev/null
+++ b/testsuite/poke.pkl/printf-28.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i2d", -1;          /* { dg-output "-1" } */
diff --git a/testsuite/poke.pkl/printf-29.pk b/testsuite/poke.pkl/printf-29.pk
new file mode 100644
index 00000000..2622e267
--- /dev/null
+++ b/testsuite/poke.pkl/printf-29.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i2o", -1;          /* { dg-output "3" } */
diff --git a/testsuite/poke.pkl/printf-30.pk b/testsuite/poke.pkl/printf-30.pk
new file mode 100644
index 00000000..00a6f070
--- /dev/null
+++ b/testsuite/poke.pkl/printf-30.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i10d", -1;          /* { dg-output "-1" } */
diff --git a/testsuite/poke.pkl/printf-31.pk b/testsuite/poke.pkl/printf-31.pk
new file mode 100644
index 00000000..bfb962ec
--- /dev/null
+++ b/testsuite/poke.pkl/printf-31.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i19d", -1;          /* { dg-output "-1" } */
diff --git a/testsuite/poke.pkl/printf-32.pk b/testsuite/poke.pkl/printf-32.pk
new file mode 100644
index 00000000..fff5db2a
--- /dev/null
+++ b/testsuite/poke.pkl/printf-32.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i45d", -1;          /* { dg-output "-1" } */
diff --git a/testsuite/poke.pkl/printf-33.pk b/testsuite/poke.pkl/printf-33.pk
new file mode 100644
index 00000000..635bc6a3
--- /dev/null
+++ b/testsuite/poke.pkl/printf-33.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i10o", -1;          /* { dg-output "1777" } */
diff --git a/testsuite/poke.pkl/printf-34.pk b/testsuite/poke.pkl/printf-34.pk
new file mode 100644
index 00000000..23095b2b
--- /dev/null
+++ b/testsuite/poke.pkl/printf-34.pk
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+printf "%i19x", -1;          /* { dg-output "7ffff" } */
diff --git a/testsuite/poke.pkl/printf-35.pk b/testsuite/poke.pkl/printf-35.pk
new file mode 100644
index 00000000..822d0262
--- /dev/null
+++ b/testsuite/poke.pkl/printf-35.pk
@@ -0,0 +1,4 @@
+/* { dg-do run } */
+
+/* 45 = 3 * 15 */
+printf "%i45o", -1;          /* { dg-output "777777777777777" } */
-- 
2.30.1



reply via email to

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