This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BZ#13926: Add __bswap_64 for non-GCC compilers


Thanks for all the comments on how to improve my last patch.

IMHO this is the best approach to change the code - make it available with __GLIBC_HAVE_LONG_LONG only. GCC will never see this code since there it is specially handled before.

Ok to commit once testing on both x86 and x86-64 passes?

Andreas

2012-04-02 Andreas Jaeger <aj@suse.de>

	[BZ #13926]
	* sysdeps/i386/bits/byteswap.h [!__GNUC__](__bswap_constant_64):
	New macro for this case.
	[!__GNUC__] (__bswap_64): New inline function for this case.
	* sysdeps/x86_64/bits/byteswap.h: Likewise.
	* bits/byteswap.h: Likewise.
	* sysdeps/s390/bits/byteswap.h: [!__GNUC__] (__bswap_64): Use
	ull, guard with __GLIBC_HAVE_LONG_LONG.

	* string/endian.h (htobe64,htole64,be64toh,le64toh): Guard with
	__GLIBC_HAVE_LONG_LONG.

	* string/byteswap.h (bswap_64): Guard with
	__GLIBC_HAVE_LONG_LONG.
	Include <features.h> for __GLIBC_HAVE_LONG_LONG.


-- Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg) GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126
>From 3c564de0c8795add93829177de25664daace96f9 Mon Sep 17 00:00:00 2001
From: Andreas Jaeger <jaegerandi@gmail.com>
Date: Wed, 28 Mar 2012 16:39:25 +0200
Subject: [PATCH] Add __bswap_64 definition for non GCC compilers.

[BZ#13926]
Currently __bswap_64 is not defined at all for non-GCC compilers.
Define it but guard it with __GLIBC_HAVE_LONG_LONG.

endian.h uses __bswap_64, make the functions only available
if __GLIBC_HAVE_LONG_LONG is defined.
---
 bits/byteswap.h                |   19 +++++++++++++++++--
 string/byteswap.h              |    6 ++++--
 string/endian.h                |   23 ++++++++++++++---------
 sysdeps/i386/bits/byteswap.h   |   19 +++++++++++++++++--
 sysdeps/s390/bits/byteswap.h   |   20 ++++++++++----------
 sysdeps/x86_64/bits/byteswap.h |   19 +++++++++++++++++--
 6 files changed, 79 insertions(+), 27 deletions(-)

diff --git a/bits/byteswap.h b/bits/byteswap.h
index 9d658e4..31e9a16 100644
--- a/bits/byteswap.h
+++ b/bits/byteswap.h
@@ -1,6 +1,5 @@
 /* Macros to swap the order of bytes in integer values.
-   Copyright (C) 1997,1998,2000-2002,2005,2008,2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1997-2012  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
@@ -82,6 +81,22 @@ __bswap_32 (unsigned int __bsx)
 	     __r.__l[1] = __bswap_32 (__w.__l[0]);			      \
 	   }								      \
 	 __r.__ll; }))
+#elif __GLIBC_HAVE_LONG_LONG
+# define __bswap_constant_64(x) \
+     ((((x) & 0xff00000000000000ull) >> 56)				      \
+      | (((x) & 0x00ff000000000000ull) >> 40)				      \
+      | (((x) & 0x0000ff0000000000ull) >> 24)				      \
+      | (((x) & 0x000000ff00000000ull) >> 8)				      \
+      | (((x) & 0x00000000ff000000ull) << 8)				      \
+      | (((x) & 0x0000000000ff0000ull) << 24)				      \
+      | (((x) & 0x000000000000ff00ull) << 40)				      \
+      | (((x) & 0x00000000000000ffull) << 56))
+
+static __inline unsigned long long int
+__bswap_64 (unsigned long long int __bsx)
+{
+  return __bswap_constant_64 (__bsx);
+}
 #endif
 
 #endif /* _BITS_BYTESWAP_H */
diff --git a/string/byteswap.h b/string/byteswap.h
index 18ca95d..7d76957 100644
--- a/string/byteswap.h
+++ b/string/byteswap.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2012 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
@@ -18,6 +18,8 @@
 #ifndef _BYTESWAP_H
 #define _BYTESWAP_H	1
 
+#include <features.h>
+
 /* Get the machine specific, optimized definitions.  */
 #include <bits/byteswap.h>
 
@@ -31,7 +33,7 @@
 /* Return a value with all bytes in the 32 bit argument swapped.  */
 #define bswap_32(x) __bswap_32 (x)
 
-#if defined __GNUC__ && __GNUC__ >= 2
+#if __GLIBC_HAVE_LONG_LONG
 /* Return a value with all bytes in the 64 bit argument swapped.  */
 # define bswap_64(x) __bswap_64 (x)
 #endif
diff --git a/string/endian.h b/string/endian.h
index 13e8c75..0c293f6 100644
--- a/string/endian.h
+++ b/string/endian.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1996, 1997, 2000, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2012 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
@@ -70,10 +70,13 @@
 #  define be32toh(x) __bswap_32 (x)
 #  define le32toh(x) (x)
 
-#  define htobe64(x) __bswap_64 (x)
-#  define htole64(x) (x)
-#  define be64toh(x) __bswap_64 (x)
-#  define le64toh(x) (x)
+#  if __GLIBC_HAVE_LONG_LONG
+#   define htobe64(x) __bswap_64 (x)
+#   define htole64(x) (x)
+#   define be64toh(x) __bswap_64 (x)
+#   define le64toh(x) (x)
+#  endif
+
 # else
 #  define htobe16(x) (x)
 #  define htole16(x) __bswap_16 (x)
@@ -85,10 +88,12 @@
 #  define be32toh(x) (x)
 #  define le32toh(x) __bswap_32 (x)
 
-#  define htobe64(x) (x)
-#  define htole64(x) __bswap_64 (x)
-#  define be64toh(x) (x)
-#  define le64toh(x) __bswap_64 (x)
+#  if __GLIBC_HAVE_LONG_LONG
+#   define htobe64(x) (x)
+#   define htole64(x) __bswap_64 (x)
+#   define be64toh(x) (x)
+#   define le64toh(x) __bswap_64 (x)
+#  endif
 # endif
 #endif
 
diff --git a/sysdeps/i386/bits/byteswap.h b/sysdeps/i386/bits/byteswap.h
index 4a159d1..fb0a827 100644
--- a/sysdeps/i386/bits/byteswap.h
+++ b/sysdeps/i386/bits/byteswap.h
@@ -1,6 +1,5 @@
 /* Macros to swap the order of bytes in integer values.
-   Copyright (C) 1997, 1998, 2000, 2002, 2003, 2006, 2007, 2008, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1997-2012  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
@@ -131,6 +130,22 @@ __bswap_32 (unsigned int __bsx)
 	     __r.__l[1] = __bswap_32 (__w.__l[0]);			      \
 	   }								      \
 	 __r.__ll; }))
+#elif __GLIBC_HAVE_LONG_LONG
+# define __bswap_constant_64(x) \
+     ((((x) & 0xff00000000000000ull) >> 56)				      \
+      | (((x) & 0x00ff000000000000ull) >> 40)				      \
+      | (((x) & 0x0000ff0000000000ull) >> 24)				      \
+      | (((x) & 0x000000ff00000000ull) >> 8)				      \
+      | (((x) & 0x00000000ff000000ull) << 8)				      \
+      | (((x) & 0x0000000000ff0000ull) << 24)				      \
+      | (((x) & 0x000000000000ff00ull) << 40)				      \
+      | (((x) & 0x00000000000000ffull) << 56))
+
+static __inline unsigned long long int
+__bswap_64 (unsigned long long int __bsx)
+{
+  return __bswap_constant_64 (__bsx);
+}
 #endif
 
 #endif /* _BITS_BYTESWAP_H */
diff --git a/sysdeps/s390/bits/byteswap.h b/sysdeps/s390/bits/byteswap.h
index ac325b0..fd7c279 100644
--- a/sysdeps/s390/bits/byteswap.h
+++ b/sysdeps/s390/bits/byteswap.h
@@ -1,5 +1,5 @@
 /* Macros to swap the order of bytes in integer values.  s390 version.
-   Copyright (C) 2000-2003, 2008, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2000-2003, 2008, 2011, 2012 Free Software Foundation, Inc.
    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
    This file is part of the GNU C Library.
 
@@ -150,16 +150,16 @@ __bswap_32 (unsigned int __bsx)
 	  __r.__l[1] = __bswap_32 (__w.__l[0]);		\
 	  __r.__ll; })
 # endif
-#else
+#elif __GLIBC_HAVE_LONG_LONG
 # define __bswap_constant_64(x) \
-     ((((x) & 0xff00000000000000ul) >> 56)				      \
-      | (((x) & 0x00ff000000000000ul) >>  40)				      \
-      | (((x) & 0x0000ff0000000000ul) >> 24)				      \
-      | (((x) & 0x000000ff00000000ul) >> 8)				      \
-      | (((x) & 0x00000000ff000000ul) << 8)				      \
-      | (((x) & 0x0000000000ff0000ul) << 24)				      \
-      | (((x) & 0x000000000000ff00ul) << 40)				      \
-      | (((x) & 0x00000000000000fful) << 56))
+     ((((x) & 0xff00000000000000ull) >> 56)				      \
+      | (((x) & 0x00ff000000000000ull) >> 40)				      \
+      | (((x) & 0x0000ff0000000000ull) >> 24)				      \
+      | (((x) & 0x000000ff00000000ull) >> 8)				      \
+      | (((x) & 0x00000000ff000000ull) << 8)				      \
+      | (((x) & 0x0000000000ff0000ull) << 24)				      \
+      | (((x) & 0x000000000000ff00ull) << 40)				      \
+      | (((x) & 0x00000000000000ffull) << 56))
 
 static __inline unsigned long long int
 __bswap_64 (unsigned long long int __bsx)
diff --git a/sysdeps/x86_64/bits/byteswap.h b/sysdeps/x86_64/bits/byteswap.h
index 5094a05..472281f 100644
--- a/sysdeps/x86_64/bits/byteswap.h
+++ b/sysdeps/x86_64/bits/byteswap.h
@@ -1,6 +1,5 @@
 /* Macros to swap the order of bytes in integer values.
-   Copyright (C) 1997, 1998, 2000, 2002, 2003, 2007, 2008, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1997-2012   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
@@ -131,6 +130,22 @@
 	   }                                                                  \
 	 __r.__ll; }))
 # endif
+#elif __GLIBC_HAVE_LONG_LONG
+# define __bswap_constant_64(x) \
+     ((((x) & 0xff00000000000000ull) >> 56)				      \
+      | (((x) & 0x00ff000000000000ull) >> 40)				      \
+      | (((x) & 0x0000ff0000000000ull) >> 24)				      \
+      | (((x) & 0x000000ff00000000ull) >> 8)				      \
+      | (((x) & 0x00000000ff000000ull) << 8)				      \
+      | (((x) & 0x0000000000ff0000ull) << 24)				      \
+      | (((x) & 0x000000000000ff00ull) << 40)				      \
+      | (((x) & 0x00000000000000ffull) << 56))
+
+static __inline unsigned long long int
+__bswap_64 (unsigned long long int __bsx)
+{
+  return __bswap_constant_64 (__bsx);
+}
 #endif
 
 #endif /* _BITS_BYTESWAP_H */
-- 
1.7.7


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