bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 2/2] rawmemchr: port better to CHERI


From: Paul Eggert
Subject: [PATCH 2/2] rawmemchr: port better to CHERI
Date: Sat, 11 Nov 2023 00:10:55 -0800

* lib/rawmemchr.c (rawmemchr): Use unsigned char for longword,
since CHERI doesn’t allow the aligned-word trick to speed up
performance.
---
 ChangeLog       |  7 +++++++
 lib/rawmemchr.c | 13 +++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aae72a1987..83c1b520b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-11-11  Paul Eggert  <eggert@cs.ucla.edu>
+
+       rawmemchr: port better to CHERI
+       * lib/rawmemchr.c (rawmemchr): Use unsigned char for longword,
+       since CHERI doesn’t allow the aligned-word trick to speed up
+       performance.
+
 2023-11-10  Paul Eggert  <eggert@cs.ucla.edu>
 
        di-set: port better to CHERI-64
diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c
index 6f2809071b..137d7282a6 100644
--- a/lib/rawmemchr.c
+++ b/lib/rawmemchr.c
@@ -30,11 +30,16 @@
 void *
 rawmemchr (const void *s, int c_in)
 {
+#ifdef __CHERI__
+  /* Most architectures let you read an aligned word, even if the unsigned char
+     array at S ends in the middle of the word.  However, CHERI does not.  */
+  typedef unsigned char longword;
+#else
   /* Change this typedef to experiment with performance.  */
-  typedef unsigned long longword;
-  /* If you change the "unsigned long", you should change ULONG_WIDTH to match.
-     This verifies that the type does not have padding bits.  */
-  static_assert (ULONG_WIDTH == UCHAR_WIDTH * sizeof (longword));
+  typedef uintptr_t longword;
+  /* Verify that the longword type lacks padding bits.  */
+  static_assert (UINTPTR_WIDTH == UCHAR_WIDTH * sizeof (uintptr_t));
+#endif
 
   const unsigned char *char_ptr;
   unsigned char c = c_in;
-- 
2.40.1




reply via email to

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