poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Simplify the implementation of ios_mask functions.


From: Egeyar Bagcioglu
Subject: Re: [PATCH] Simplify the implementation of ios_mask functions.
Date: Sun, 22 Dec 2019 18:22:58 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1

Hi John!

It looks good to me. Thanks! The patch will still need to be reviewer by a global reviewer though.

Regards
Egeyar


On 12/21/19 6:16 PM, John Darrington wrote:
---
  ChangeLog |  5 +++++
  src/ios.c | 72 +++++++++------------------------------------------------------
  2 files changed, 15 insertions(+), 62 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6640c2b..7fd81a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,11 @@
        * src/pk-cmd.c (pk_cmd_exec_1): fix memory leak of filename
        * src/pk-cmd.c (null_cmd): properly initialize struct
+2019-12-15 John Darrington <address@hidden>
+
+       *src/ios.c (ios_mask_last_byte) simplify
+       *src/ios.c (ios_mask_first_byte) simplify
+
  2019-12-16  Jose E. Marchesi  <address@hidden>
* src/pkl-asm.pks (atrim): The mka instruction expects the type of
diff --git a/src/ios.c b/src/ios.c
index a96e349..757ada3 100644
--- a/src/ios.c
+++ b/src/ios.c
@@ -23,6 +23,7 @@
  #include <unistd.h>
  #include <stdio.h>
  #include <assert.h>
+#include <limits.h>
  #define _(str) gettext (str)
  #include <streq.h>
@@ -310,72 +311,19 @@ ios_map (ios_map_fn cb, void *data)
      (*cb) (io, data);
  }
-inline static void
-ios_mask_first_byte(uint64_t *byte, int significant_bits)
+/* Set all except the lowest SIGNIFICANT_BITS of VALUE to zero.  */
+static inline void
+ios_mask_first_byte (uint64_t *value, int significant_bits)
  {
-  switch (significant_bits)
-    {
-    case 1:
-      *byte &= (char) 0x01;
-      return;
-    case 2:
-      *byte &= (char) 0x03;
-      return;
-    case 3:
-      *byte &= (char) 0x07;
-      return;
-    case 4:
-      *byte &= (char) 0x0f;
-      return;
-    case 5:
-      *byte &= (char) 0x1f;
-      return;
-    case 6:
-      *byte &= (char) 0x3f;
-      return;
-    case 7:
-      *byte &= (char) 0x7f;
-      return;
-    case 8:
-      return;
-    default:
-      assert (0);
-      return;
-    }
+  *value &= 0xFFU >> (CHAR_BIT - significant_bits);
  }
-inline static void
-ios_mask_last_byte(uint64_t *byte, int significant_bits)
+/* Set all except the highest SIGNIFICANT_BITS of the lowest
+   significant byte of VALUE to zero.  */
+static inline void
+ios_mask_last_byte (uint64_t *value, int significant_bits)
  {
-  switch (significant_bits)
-    {
-    case 1:
-      *byte &= (char) 0x80;
-      return;
-    case 2:
-      *byte &= (char) 0xc0;
-      return;
-    case 3:
-      *byte &= (char) 0xe0;
-      return;
-    case 4:
-      *byte &= (char) 0xf0;
-      return;
-    case 5:
-      *byte &= (char) 0xf8;
-      return;
-    case 6:
-      *byte &= (char) 0xfc;
-      return;
-    case 7:
-      *byte &= (char) 0xfe;
-      return;
-    case 8:
-      return;
-    default:
-      assert (0);
-      return;
-    }
+  *value &= 0xFFU << (CHAR_BIT - significant_bits);
  }
static inline int




reply via email to

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