]> Savannah Git Hosting - gnulib.git/commitdiff
rawmemchr: port better to CHERI
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Nov 2023 08:09:55 +0000 (00:09 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Nov 2023 08:10:35 +0000 (00:10 -0800)
* lib/rawmemchr.c (rawmemchr): Use unsigned char for longword,
since CHERI doesn’t allow the aligned-word trick to speed up
performance.

ChangeLog
lib/rawmemchr.c

index aae72a19878cfb2768ca925bfc5f75c8f7b26034..83c1b520b9b7ccbfc7727567cede22db60ac7a2d 100644 (file)
--- 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
index 6f2809071b33ba594c2b289c214370a28882777e..137d7282a62acf553652bb922c2ebfa3f2aae3a4 100644 (file)
 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;