[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: memchr.c and memrchr.c portability fixes
From: |
Paul Eggert |
Subject: |
Re: memchr.c and memrchr.c portability fixes |
Date: |
Thu, 29 Jul 2004 10:37:15 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Andreas Schwab <address@hidden> writes:
> on m68k-linux alignof(type) will always be at most 2, but you
> get better performance with a 4-byte aligned pointer.
Thanks for mentioning that. I installed this further patch.
(I used alignof because md5.c uses it, but with md5.c the performance
tradeoffs are different and possibly alignof makes more sense there.)
2004-07-29 Paul Eggert <address@hidden>
* memchr.c (UNALIGNED_P): Use sizeof, not alignof, for better
performance on m68k-linux. Reported by Andreas Schwab in
<http://lists.gnu.org/archive/html/bug-coreutils/2004-07/msg00104.html>.
* memrchr.c (UNALIGNED_P): Likewise.
Index: lib/memchr.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/memchr.c,v
retrieving revision 1.17
diff -p -u -r1.17 memchr.c
--- lib/memchr.c 28 Jul 2004 22:20:56 -0000 1.17
+++ lib/memchr.c 29 Jul 2004 17:27:49 -0000
@@ -48,9 +48,11 @@ USA. */
# include <stdint.h>
#endif
-#define alignof(type) offsetof (struct { char c; type x; }, x)
+/* Use sizeof, not alignof, for better performance on some hosts. For
+ example, on m68k-linux alignof (type) will always be at most 2, but
+ you get better performance with a 4-byte aligned pointer. */
#ifdef UINTPTR_MAX
-# define UNALIGNED_P(p) (((uintptr_t) p) % alignof (unsigned long int) != 0)
+# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (unsigned long int) != 0)
#else
# define UNALIGNED_P(p) 1
#endif
Index: lib/memrchr.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/memrchr.c,v
retrieving revision 1.5
diff -p -u -r1.5 memrchr.c
--- lib/memrchr.c 28 Jul 2004 22:21:18 -0000 1.5
+++ lib/memrchr.c 29 Jul 2004 17:28:23 -0000
@@ -46,9 +46,11 @@
# include <stdint.h>
#endif
-#define alignof(type) offsetof (struct { char c; type x; }, x)
+/* Use sizeof, not alignof, for better performance on some hosts. For
+ example, on m68k-linux alignof (type) will always be at most 2, but
+ you get better performance with a 4-byte aligned pointer. */
#ifdef UINTPTR_MAX
-# define UNALIGNED_P(p) (((uintptr_t) p) % alignof (unsigned long int) != 0)
+# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (unsigned long int) != 0)
#else
# define UNALIGNED_P(p) 1
#endif