This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: eliminate some endian #ifs


Ulrich Drepper <drepper@redhat.com> writes:

> > No build-shared & build-static failures or binary differences for i686.

Same deal.

I refined this a bit further: __LONG_LONG_SPLIT accepts a single
64-bit quantity, breaks it into two 32-bit args, and passes the pieces
according to __BYTE_ORDER.

Index: string/endian.h
===================================================================
RCS file: /cvs/glibc/libc/string/endian.h,v
retrieving revision 1.5
diff -u -p -r1.5 endian.h
--- endian.h	1998/11/27 11:34:04	1.5
+++ endian.h	2000/07/06 20:44:11
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1996, 1997, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -45,6 +45,13 @@
 # define BIG_ENDIAN	__BIG_ENDIAN
 # define PDP_ENDIAN	__PDP_ENDIAN
 # define BYTE_ORDER	__BYTE_ORDER
+#endif
+
+#define __LONG_LONG_SPLIT(LL) __LONG_LONG_PAIR ((LL) >> 32, (LL) & 0xffffffff)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# define __LONG_LONG_PAIR(HI, LO) (LO), (HI)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+# define __LONG_LONG_PAIR(HI, LO) (HI), (LO)
 #endif
 
 #endif	/* endian.h */
Index: sysdeps/unix/sysv/linux/ftruncate64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/ftruncate64.c,v
retrieving revision 1.7
diff -u -p -r1.7 ftruncate64.c
--- ftruncate64.c	2000/05/26 20:11:43	1.7
+++ ftruncate64.c	2000/07/06 20:44:12
@@ -44,16 +44,11 @@ ftruncate64 (int fd, off64_t length)
   if (! __have_no_truncate64)
 #endif
     {
-      unsigned int low = length & 0xffffffff;
-      unsigned int high = length >> 32;
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       int saved_errno = errno;
 #endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-      int result = INLINE_SYSCALL (ftruncate64, 3, fd, low, high);
-#elif __BYTE_ORDER == __BIG_ENDIAN
-      int result = INLINE_SYSCALL (ftruncate64, 3, fd, high, low);
-#endif
+      int result = INLINE_SYSCALL (ftruncate64, 3, fd,
+				   __LONG_LONG_SPLIT (length));
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       if (result != -1 || errno != ENOSYS)
 #endif
Index: sysdeps/unix/sysv/linux/pread.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/pread.c,v
retrieving revision 1.9
diff -u -p -r1.9 pread.c
--- pread.c	2000/05/27 16:50:33	1.9
+++ pread.c	2000/07/06 20:44:12
@@ -48,11 +48,8 @@ __libc_pread (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-  result = INLINE_SYSCALL (pread, 5, fd, buf, count, offset, 0);
-# elif __BYTE_ORDER == __BIG_ENDIAN
-  result = INLINE_SYSCALL (pread, 5, fd, buf, count, 0, offset);
-# endif
+  result = INLINE_SYSCALL (pread, 5, fd, buf, count,
+			   __LONG_LONG_SPLIT (offset));
 
 # if __ASSUME_PREAD_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
Index: sysdeps/unix/sysv/linux/pread64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/pread64.c,v
retrieving revision 1.9
diff -u -p -r1.9 pread64.c
--- pread64.c	2000/05/26 19:55:43	1.9
+++ pread64.c	2000/07/06 20:44:12
@@ -47,16 +47,8 @@ __libc_pread64 (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if __BYTE_ORDER == __LITTLE_ENDIAN
   result = INLINE_SYSCALL (pread, 5, fd, buf, count,
-			   (off_t) (offset & 0xffffffff),
-			   (off_t) (offset >> 32));
-# elif __BYTE_ORDER == __BIG_ENDIAN
-  result = INLINE_SYSCALL (pread, 5, fd, buf, count,
-			   (off_t) (offset >> 32),
-			   (off_t) (offset & 0xffffffff));
-# endif
-
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PREAD_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/pwrite.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/pwrite.c,v
retrieving revision 1.8
diff -u -p -r1.8 pwrite.c
--- pwrite.c	2000/05/27 16:50:33	1.8
+++ pwrite.c	2000/07/06 20:44:12
@@ -48,11 +48,8 @@ __libc_pwrite (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-  result = INLINE_SYSCALL (pwrite, 5, fd, buf, count, offset, 0);
-# elif __BYTE_ORDER == __BIG_ENDIAN
-  result = INLINE_SYSCALL (pwrite, 5, fd, buf, count, 0, offset);
-# endif
+  result = INLINE_SYSCALL (pwrite, 5, fd, buf, count,
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PWRITE_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/pwrite64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/pwrite64.c,v
retrieving revision 1.8
diff -u -p -r1.8 pwrite64.c
--- pwrite64.c	2000/05/26 15:45:04	1.8
+++ pwrite64.c	2000/07/06 20:44:12
@@ -47,15 +47,8 @@ __libc_pwrite64 (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if __BYTE_ORDER == __LITTLE_ENDIAN
   result = INLINE_SYSCALL (pwrite, 5, fd, buf, count,
-			   (off_t) (offset & 0xffffffff),
-			   (off_t) (offset >> 32));
-# elif __BYTE_ORDER == __BIG_ENDIAN
-  result = INLINE_SYSCALL (pwrite, 5, fd, buf, count,
-			   (off_t) (offset >> 32),
-			   (off_t) (offset & 0xffffffff));
-# endif
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PWRITE_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/truncate64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/truncate64.c,v
retrieving revision 1.8
diff -u -p -r1.8 truncate64.c
--- truncate64.c	2000/05/26 20:11:43	1.8
+++ truncate64.c	2000/07/06 20:44:12
@@ -44,17 +44,11 @@ truncate64 (const char *path, off64_t le
   if (! __have_no_truncate64)
 #endif
     {
-      unsigned int low = length & 0xffffffff;
-      unsigned int high = length >> 32;
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       int saved_errno = errno;
 #endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-      int result = INLINE_SYSCALL (truncate64, 3, path, low, high);
-#elif __BYTE_ORDER == __BIG_ENDIAN
-      int result = INLINE_SYSCALL (truncate64, 3, path, high, low);
-#endif
-
+      int result = INLINE_SYSCALL (truncate64, 3, path,
+				   __LONG_LONG_SPLIT (length));
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       if (result != -1 || errno != ENOSYS)
 #endif
Index: sysdeps/unix/sysv/linux/mips/ftruncate64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/ftruncate64.c,v
retrieving revision 1.2
diff -u -p -r1.2 ftruncate64.c
--- ftruncate64.c	2000/05/31 12:00:45	1.2
+++ ftruncate64.c	2000/07/06 20:44:14
@@ -45,18 +45,11 @@ ftruncate64 (int fd, off64_t length)
   if (! __have_no_truncate64)
 #endif
     {
-      unsigned int low = length & 0xffffffff;
-      unsigned int high = length >> 32;
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       int saved_errno = errno;
 #endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-      /* Use a fill argument to pass low, high in an aligned pair of
-         arguments (here 2/3).  */
-      int result = INLINE_SYSCALL (ftruncate64, 3, fd, 0, low, high);
-#elif __BYTE_ORDER == __BIG_ENDIAN
-      int result = INLINE_SYSCALL (ftruncate64, 3, fd, 0, high, low);
-#endif
+      int result = INLINE_SYSCALL (ftruncate64, 3, fd, 0,
+				   __LONG_LONG_SPLIT (length));
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       if (result != -1 || errno != ENOSYS)
 #endif
Index: sysdeps/unix/sysv/linux/mips/pread.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pread.c,v
retrieving revision 1.4
diff -u -p -r1.4 pread.c
--- pread.c	2000/05/30 12:50:17	1.4
+++ pread.c	2000/07/06 20:44:14
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include <endian.h>
 
 #include <sysdep.h>
 #include <sys/syscall.h>
@@ -46,11 +47,8 @@ __libc_pread (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if defined(__MIPSEB__)
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0, 0, offset);
-# elif defined(__MIPSEL__)
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0, offset, 0);
-# endif
+  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PREAD_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/mips/pread64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pread64.c,v
retrieving revision 1.5
diff -u -p -r1.5 pread64.c
--- pread64.c	2000/05/30 12:50:17	1.5
+++ pread64.c	2000/07/06 20:44:14
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include <endian.h>
 
 #include <sysdep.h>
 #include <sys/syscall.h>
@@ -47,14 +48,8 @@ __libc_pread64 (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if defined(__MIPSEB__)
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0, (off_t) (offset >> 32),
-			   (off_t) (offset & 0xffffffff));
-# elif defined(__MIPSEL__)
   result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			   (off_t) (offset & 0xffffffff),
-			   (off_t) (offset >> 32));
-# endif
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PREAD_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/mips/pwrite.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pwrite.c,v
retrieving revision 1.4
diff -u -p -r1.4 pwrite.c
--- pwrite.c	2000/05/30 12:50:17	1.4
+++ pwrite.c	2000/07/06 20:44:14
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include <endian.h>
 
 #include <sysdep.h>
 #include <sys/syscall.h>
@@ -45,11 +46,8 @@ __libc_pwrite (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if defined(__MIPSEB__)
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0, 0, offset);
-# elif defined(__MIPSEL__)
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0, offset, 0);
-# endif
+  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PWRITE_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/mips/pwrite64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pwrite64.c,v
retrieving revision 1.5
diff -u -p -r1.5 pwrite64.c
--- pwrite64.c	2000/05/30 12:50:17	1.5
+++ pwrite64.c	2000/07/06 20:44:14
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include <endian.h>
 
 #include <sysdep.h>
 #include <sys/syscall.h>
@@ -45,15 +46,8 @@ __libc_pwrite64 (fd, buf, count, offset)
   ssize_t result;
 
   /* First try the syscall.  */
-# if defined(__MIPSEB__)
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0, (off_t) (offset >> 32),
-			   (off_t) (offset & 0xffffffff));
-# elif defined(__MIPSEL__)
   result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			   (off_t) (offset & 0xffffffff),
-			   (off_t) (offset >> 32));
-# endif
-
+			   __LONG_LONG_SPLIT (offset));
 # if __ASSUME_PWRITE_SYSCALL == 0
   if (result == -1 && errno == ENOSYS)
     /* No system call available.  Use the emulation.  */
Index: sysdeps/unix/sysv/linux/mips/truncate64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/truncate64.c,v
retrieving revision 1.2
diff -u -p -r1.2 truncate64.c
--- truncate64.c	2000/05/31 12:00:45	1.2
+++ truncate64.c	2000/07/06 20:44:14
@@ -45,19 +45,11 @@ truncate64 (const char *path, off64_t le
   if (! __have_no_truncate64)
 #endif
     {
-      unsigned int low = length & 0xffffffff;
-      unsigned int high = length >> 32;
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       int saved_errno = errno;
 #endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-      /* Use a fill argument to pass low, high in an aligned pair of
-         arguments (here 2/3).  */
-      int result = INLINE_SYSCALL (truncate64, 3, path, 0, low, high);
-#elif __BYTE_ORDER == __BIG_ENDIAN
-      int result = INLINE_SYSCALL (truncate64, 3, path, 0, high, low);
-#endif
-
+      int result = INLINE_SYSCALL (truncate64, 3, path, 0,
+				   __LONG_LONG_SPLIT (length));
 #ifndef __ASSUME_TRUNCATE64_SYSCALL
       if (result != -1 || errno != ENOSYS)
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]