Skip to content

Commit

Permalink
Prevent warnings due to long long constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Dec 23, 2011
1 parent bbe315e commit 67371b5
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 90 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2011-12-23 Ulrich Drepper <drepper@gmail.com>

* bits/byteswap.h: Protect long long constants with __extension__.
* sysdeps/i386/bits/byteswap.h: Likewise.
* sysdeps/ia64/bits/byteswap.h: Likewise.
* sysdeps/s390/bits/byteswap.h: Likewise.
* sysdeps/x86_64/bits/byteswap.h: Likewise.

2011-12-23 Liubov Dmitrieva <liubov.dmitrieva@gmail.com>

[BZ #13540]
Expand Down
21 changes: 11 additions & 10 deletions bits/byteswap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Macros to swap the order of bytes in integer values.
Copyright (C) 1997,1998,2000-2002,2005,2008 Free Software Foundation, Inc.
Copyright (C) 1997,1998,2000-2002,2005,2008,2011
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
Expand Down Expand Up @@ -60,20 +61,20 @@ __bswap_32 (unsigned int __bsx)
#if defined __GNUC__ && __GNUC__ >= 2
/* Swap bytes in 64 bit value. */
# 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))
(__extension__ ((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56)))

# define __bswap_64(x) \
(__extension__ \
({ union { __extension__ unsigned long long int __ll; \
unsigned int __l[2]; } __w, __r; \
if (__builtin_constant_p (x)) \
if (__builtin_constant_p (x)) \
__r.__ll = __bswap_constant_64 (x); \
else \
{ \
Expand Down
20 changes: 10 additions & 10 deletions sysdeps/i386/bits/byteswap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Macros to swap the order of bytes in integer values.
Copyright (C) 1997, 1998, 2000, 2002, 2003, 2006, 2007, 2008, 2010
Copyright (C) 1997, 1998, 2000, 2002, 2003, 2006, 2007, 2008, 2010, 2011
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Expand Down Expand Up @@ -109,15 +109,15 @@ __bswap_32 (unsigned int __bsx)

#if defined __GNUC__ && __GNUC__ >= 2
/* Swap bytes in 64 bit value. */
#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))
# define __bswap_constant_64(x) \
(__extension__ ((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56)))

# define __bswap_64(x) \
(__extension__ \
Expand Down
35 changes: 23 additions & 12 deletions sysdeps/ia64/bits/byteswap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Macros to swap the order of bytes in integer values.
Copyright (C) 1997,1998,2000,2002,2003,2008 Free Software Foundation, Inc.
Copyright (C) 1997,1998,2000,2002,2003,2008,2011
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
Expand Down Expand Up @@ -77,17 +78,17 @@ __bswap_32 (unsigned int __bsx)


/* Swap bytes in 64 bit value. */
#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))

#if defined __GNUC__ && __GNUC__ >= 2
# define __bswap_constant_64(x) \
(__extension__ ((((x) & 0xff00000000000000ul) >> 56) \
| (((x) & 0x00ff000000000000ul) >> 40) \
| (((x) & 0x0000ff0000000000ul) >> 24) \
| (((x) & 0x000000ff00000000ul) >> 8) \
| (((x) & 0x00000000ff000000ul) << 8) \
| (((x) & 0x0000000000ff0000ul) << 24) \
| (((x) & 0x000000000000ff00ul) << 40) \
| (((x) & 0x00000000000000fful) << 56)))

# define __bswap_64(x) \
(__extension__ \
({ register unsigned long int __v, __x = (x); \
Expand All @@ -97,9 +98,19 @@ __bswap_32 (unsigned int __bsx)
__asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \
: "=r" (__v) \
: "r" ((unsigned long int) (__x))); \
__v; }))
__v; }))

#else
# 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))

static __inline unsigned long int
__bswap_64 (unsigned long int __bsx)
{
Expand Down
112 changes: 63 additions & 49 deletions sysdeps/s390/bits/byteswap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Macros to swap the order of bytes in integer values. s390 version.
Copyright (C) 2000, 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
Copyright (C) 2000-2003, 2008, 2011 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
This file is part of the GNU C Library.
Expand Down Expand Up @@ -35,31 +35,31 @@
# if __WORDSIZE == 64
# define __bswap_16(x) \
(__extension__ \
({ unsigned short int __v, __x = (x); \
({ unsigned short int __v, __x = (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_16 (__x); \
else { \
unsigned short int __tmp = (unsigned short int) (__x); \
__asm__ __volatile__ ( \
"lrvh %0,%1" \
: "=&d" (__v) : "m" (__tmp) ); \
} \
unsigned short int __tmp = (unsigned short int) (__x); \
__asm__ __volatile__ ( \
"lrvh %0,%1" \
: "=&d" (__v) : "m" (__tmp) ); \
} \
__v; }))
# else
# define __bswap_16(x) \
(__extension__ \
({ unsigned short int __v, __x = (x); \
({ unsigned short int __v, __x = (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_16 (__x); \
else { \
unsigned short int __tmp = (unsigned short int) (__x); \
__asm__ __volatile__ ( \
"sr %0,%0\n" \
"la 1,%1\n" \
"icm %0,2,1(1)\n" \
"ic %0,0(1)" \
: "=&d" (__v) : "m" (__tmp) : "1"); \
} \
unsigned short int __tmp = (unsigned short int) (__x); \
__asm__ __volatile__ ( \
"sr %0,%0\n" \
"la 1,%1\n" \
"icm %0,2,1(1)\n" \
"ic %0,0(1)" \
: "=&d" (__v) : "m" (__tmp) : "1"); \
} \
__v; }))
# endif
#else
Expand All @@ -80,32 +80,32 @@ __bswap_16 (unsigned short int __bsx)
# if __WORDSIZE == 64
# define __bswap_32(x) \
(__extension__ \
({ unsigned int __v, __x = (x); \
({ unsigned int __v, __x = (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_32 (__x); \
else { \
unsigned int __tmp = (unsigned int) (__x); \
__asm__ __volatile__ ( \
"lrv %0,%1" \
: "=&d" (__v) : "m" (__tmp)); \
} \
unsigned int __tmp = (unsigned int) (__x); \
__asm__ __volatile__ ( \
"lrv %0,%1" \
: "=&d" (__v) : "m" (__tmp)); \
} \
__v; }))
# else
# define __bswap_32(x) \
(__extension__ \
({ unsigned int __v, __x = (x); \
({ unsigned int __v, __x = (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_32 (__x); \
else { \
unsigned int __tmp = (unsigned int) (__x); \
__asm__ __volatile__ ( \
"la 1,%1\n" \
"icm %0,8,3(1)\n" \
"icm %0,4,2(1)\n" \
"icm %0,2,1(1)\n" \
"ic %0,0(1)" \
: "=&d" (__v) : "m" (__tmp) : "1"); \
} \
unsigned int __tmp = (unsigned int) (__x); \
__asm__ __volatile__ ( \
"la 1,%1\n" \
"icm %0,8,3(1)\n" \
"icm %0,4,2(1)\n" \
"icm %0,2,1(1)\n" \
"ic %0,0(1)" \
: "=&d" (__v) : "m" (__tmp) : "1"); \
} \
__v; }))
# endif
#else
Expand All @@ -117,37 +117,51 @@ __bswap_32 (unsigned int __bsx)
#endif

/* Swap bytes in 64 bit value. */
#define __bswap_constant_64(x) \
((((x)&0xff00000000000000) >> 56) | (((x)&0x00ff000000000000) >> 40) | \
(((x)&0x0000ff0000000000) >> 24) | (((x)&0x000000ff00000000) >> 8) | \
(((x)&0x00000000ff000000) << 8) | (((x)&0x0000000000ff0000) << 24) | \
(((x)&0x000000000000ff00) << 40) | (((x)&0x00000000000000ff) << 56))

#if defined __GNUC__ && __GNUC__ >= 2
# define __bswap_constant_64(x) \
(__extension__ ((((x) & 0xff00000000000000ul) >> 56) \
| (((x) & 0x00ff000000000000ul) >> 40) \
| (((x) & 0x0000ff0000000000ul) >> 24) \
| (((x) & 0x000000ff00000000ul) >> 8) \
| (((x) & 0x00000000ff000000ul) << 8) \
| (((x) & 0x0000000000ff0000ul) << 24) \
| (((x) & 0x000000000000ff00ul) << 40) \
| (((x) & 0x00000000000000fful) << 56)))

# if __WORDSIZE == 64
# define __bswap_64(x) \
(__extension__ \
({ unsigned long __w, __x = (x); \
({ unsigned long __w, __x = (x); \
if (__builtin_constant_p (x)) \
__w = __bswap_constant_64 (__x); \
else { \
unsigned long __tmp = (unsigned long) (__x); \
__asm__ __volatile__ ( \
"lrvg %0,%1" \
: "=&d" (__w) : "m" (__tmp)); \
} \
unsigned long __tmp = (unsigned long) (__x); \
__asm__ __volatile__ ( \
"lrvg %0,%1" \
: "=&d" (__w) : "m" (__tmp)); \
} \
__w; }))
# else
# define __bswap_64(x) \
__extension__ \
({ union { unsigned long long int __ll; \
unsigned long int __l[2]; } __w, __r; \
__w.__ll = (x); \
__r.__l[0] = __bswap_32 (__w.__l[1]); \
__r.__l[1] = __bswap_32 (__w.__l[0]); \
__r.__ll; })
unsigned long int __l[2]; } __w, __r; \
__w.__ll = (x); \
__r.__l[0] = __bswap_32 (__w.__l[1]); \
__r.__l[1] = __bswap_32 (__w.__l[0]); \
__r.__ll; })
# endif
#else
# 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))

static __inline unsigned long long int
__bswap_64 (unsigned long long int __bsx)
{
Expand Down
18 changes: 9 additions & 9 deletions sysdeps/x86_64/bits/byteswap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Macros to swap the order of bytes in integer values.
Copyright (C) 1997, 1998, 2000, 2002, 2003, 2007, 2008, 2010
Copyright (C) 1997, 1998, 2000, 2002, 2003, 2007, 2008, 2010, 2011
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Expand Down Expand Up @@ -99,14 +99,14 @@
#if defined __GNUC__ && __GNUC__ >= 2
/* Swap bytes in 64 bit value. */
# 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))
(__extension__ ((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56)))

# if __WORDSIZE == 64
# define __bswap_64(x) \
Expand Down

0 comments on commit 67371b5

Please sign in to comment.