This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Fix up bswap_* types
- From: Marek Polacek <polacek at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Sun, 19 Aug 2012 18:09:58 +0200
- Subject: [PATCH] Fix up bswap_* types
It looks like various bswap_* functions and macros aren't using
optimal types of parameters and return values. E.g. here
static __inline unsigned long long int
__bswap_64 (unsigned long long int __bsx)
{
return __builtin_bswap64 (__bsx);
}
it would be IMNSHO better to use uint64_t directly, as this is the type
that the gcc builtin takes and returns. For instance __builtin_bswap64
is defined as:
DEF_GCC_BUILTIN (BUILT_IN_BSWAP64, "bswap64", BT_FN_UINT64_UINT64,
ATTR_CONST_NOTHROW_LEAF_LIST)
and BT_UINT64 is:
DEF_PRIMITIVE_TYPE (BT_UINT64, uint64_type_node)
So this patch changes various unsigned ints to uint*_t variants. It
silences two warnings in debug/pcprofiledump.c and does not cause
any new warnings on both x86_64/i?86. I've checked places where
these bswap_* functions are used and callers are using appropriate
uint*_t types. So no changes needed there.
Tested x86_64/i?86, ok for trunk?
2012-08-19 Marek Polacek <polacek@redhat.com>
* bits/byteswap-16.h (__bswap_16) [__GNUC__]: Use uint16_t instead
of unsigned short int.
(__bswapt_16) [!__GNUC__]: Likewise.
* bits/byteswap.h: Include <stdint.h>.
(__bswap_constant_16): Use uint16_t instead of unsigned short int.
(__bswap_32) [__GNUC_PREREQ]: Use uint32_t instead of unsigned int.
(__bswap_32) [!__GNUC_PREREQ]: Likewise.
(__bswap_64) [__GNUC_PREREQ]: Use uint64_t instead of unsigned long long
int.
(__bswap_64) [!__GNUC_PREREQ]: Use uint64_t instead of unsigned long long
int and uint32_t instead of unsigned int.
(__bswap_64) [__GLIBC_HAVE_LONG_LONG]: Use uint64_t instead of
unsigned long long int.
* sysdeps/s390/bits/byteswap-16.h (__bswap_16) [WORDSIZE == 64]: Use
uint16_t instead of unsigned short int.
(__bswap_16) [!WORDSIZE == 64]: Likewise.
(__bswap_16) [!__GNUC__]: Likewise.
* sysdeps/s390/bits/byteswap.h: Include <stdint.h>.
(__bswap_32) [__GNUC_PREREQ]: Use uint32_t instead of unsigned int.
(__bswap_32) [!__GNUC_PREREQ]: Likewise.
(__bswap_64) [__GNUC_PREREQ]: Use uint64_t instead of unsigned long long
int.
(__bswap_64) [!__GNUC_PREREQ]: Use uint64_t instead of unsigned long long
int and uint32_t instead of unsigned int.
(__bswap_64) [__GLIBC_HAVE_LONG_LONG]: Use uint64_t instead of
unsigned long long int.
(__bswap_constant_16): Use uint16_t instead of unsigned short int.
* sysdeps/x86/bits/byteswap-16.h (__bswap_16) [WORDSIZE == 64]: Use
uint16_t instead of unsigned short int.
(__bswap_16) [!WORDSIZE == 64]: Likewise.
(__bswap_16) [!__GNUC__]: Likewise.
* sysdeps/x86/bits/byteswap.h: Include <stdint.h>.
(__bswap_32) [__GNUC_PREREQ]: Use uint32_t instead of unsigned int.
(__bswap_32) [!__GNUC_PREREQ]: Likewise.
(__bswap_64) [__GNUC_PREREQ]: Use uint64_t instead of unsigned long long
int.
(__bswap_64) [!__GNUC_PREREQ]: Use uint64_t instead of unsigned long long
int and uint32_t instead of unsigned int.
(__bswap_64) [__GLIBC_HAVE_LONG_LONG]: Use uint64_t instead of
unsigned long long int.
--- libc/bits/byteswap-16.h.mp 2012-08-19 14:50:02.904713109 +0200
+++ libc/bits/byteswap-16.h 2012-08-19 16:15:45.083302162 +0200
@@ -23,11 +23,11 @@
#ifdef __GNUC__
# define __bswap_16(x) \
(__extension__ \
- ({ unsigned short int __bsx = (unsigned short int) (x); \
+ ({ uint16_t __bsx = (uint16_t) (x); \
__bswap_constant_16 (__bsx); }))
#else
-static __inline unsigned short int
-__bswap_16 (unsigned short int __bsx)
+static __inline uint16_t
+__bswap_16 (uint16_t __bsx)
{
return __bswap_constant_16 (__bsx);
}
--- libc/bits/byteswap.h.mp 2012-08-19 14:49:59.151703654 +0200
+++ libc/bits/byteswap.h 2012-08-19 16:19:56.836119393 +0200
@@ -1,5 +1,5 @@
/* Macros to swap the order of bytes in integer values.
- Copyright (C) 1997-2012 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
@@ -24,10 +24,11 @@
#define _BITS_BYTESWAP_H 1
#include <features.h>
+#include <stdint.h>
/* Swap bytes in 16 bit value. */
#define __bswap_constant_16(x) \
- ((unsigned short int)((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
+ ((uint16_t) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
/* Get __bswap_16. */
#include <bits/byteswap-16.h>
@@ -39,19 +40,19 @@
#ifdef __GNUC__
# if __GNUC_PREREQ (4, 2)
-static __inline unsigned int
-__bswap_32 (unsigned int __bsx)
+static __inline uint32_t
+__bswap_32 (uint32_t __bsx)
{
return __builtin_bswap32 (__bsx);
}
# else
# define __bswap_32(x) \
(__extension__ \
- ({ register unsigned int __bsx = (x); __bswap_constant_32 (__bsx); }))
+ ({ register uint32_t __bsx = (x); __bswap_constant_32 (__bsx); }))
# endif
#else
-static __inline unsigned int
-__bswap_32 (unsigned int __bsx)
+static __inline uint32_t
+__bswap_32 (uint32_t __bsx)
{
return __bswap_constant_32 (__bsx);
}
@@ -70,16 +71,16 @@ __bswap_32 (unsigned int __bsx)
| (((x) & 0x00000000000000ffull) << 56)))
# if __GNUC_PREREQ (4, 2)
-static __inline unsigned long long int
-__bswap_64 (unsigned long long int __bsx)
+static __inline uint64_t
+__bswap_64 (uint64_t __bsx)
{
return __builtin_bswap64 (__bsx);
}
# else
# define __bswap_64(x) \
(__extension__ \
- ({ union { __extension__ unsigned long long int __ll; \
- unsigned int __l[2]; } __w, __r; \
+ ({ union { __extension__ uint64_t __ll; \
+ uint32_t __l[2]; } __w, __r; \
if (__builtin_constant_p (x)) \
__r.__ll = __bswap_constant_64 (x); \
else \
@@ -101,8 +102,8 @@ __bswap_64 (unsigned long long int __bsx
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
-static __inline unsigned long long int
-__bswap_64 (unsigned long long int __bsx)
+static __inline uint64_t
+__bswap_64 (uint64_t __bsx)
{
return __bswap_constant_64 (__bsx);
}
--- libc/sysdeps/s390/bits/byteswap-16.h.mp 2012-08-19 16:34:38.626981852 +0200
+++ libc/sysdeps/s390/bits/byteswap-16.h 2012-08-19 16:38:36.140993773 +0200
@@ -28,11 +28,11 @@
# if __WORDSIZE == 64
# define __bswap_16(x) \
(__extension__ \
- ({ unsigned short int __v, __x = (unsigned short int) (x); \
+ ({ uint16_t __v, __x = (uint16_t) (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_16 (__x); \
else { \
- unsigned short int __tmp = (unsigned short int) (__x); \
+ uint16_t __tmp = (uint16_t) (__x); \
__asm__ __volatile__ ( \
"lrvh %0,%1" \
: "=&d" (__v) : "m" (__tmp) ); \
@@ -41,11 +41,11 @@
# else
# define __bswap_16(x) \
(__extension__ \
- ({ unsigned short int __v, __x = (unsigned short int) (x); \
+ ({ uint16_t __v, __x = (uint16_t) (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_16 (__x); \
else { \
- unsigned short int __tmp = (unsigned short int) (__x); \
+ uint16_t __tmp = (uint16_t) (__x); \
__asm__ __volatile__ ( \
"sr %0,%0\n" \
"la 1,%1\n" \
@@ -57,8 +57,8 @@
# endif
#else
/* This is better than nothing. */
-static __inline unsigned short int
-__bswap_16 (unsigned short int __bsx)
+static __inline uint16_t
+__bswap_16 (uint16_t __bsx)
{
return __bswap_constant_16 (__bsx);
}
--- libc/sysdeps/s390/bits/byteswap.h.mp 2012-08-19 16:22:27.367608050 +0200
+++ libc/sysdeps/s390/bits/byteswap.h 2012-08-19 16:27:59.534686325 +0200
@@ -21,13 +21,14 @@
# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
#endif
+#include <stdint.h>
#include <bits/wordsize.h>
#ifndef _BITS_BYTESWAP_H
#define _BITS_BYTESWAP_H 1
#define __bswap_constant_16(x) \
- ((unsigned short int) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
+ ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
/* Get __bswap_16. */
#include <bits/byteswap-16.h>
@@ -41,11 +42,11 @@
# if __WORDSIZE == 64
# define __bswap_32(x) \
(__extension__ \
- ({ unsigned int __v, __x = (x); \
+ ({ uint32_t __v, __x = (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_32 (__x); \
else { \
- unsigned int __tmp = (unsigned int) (__x); \
+ uint32_t __tmp = (uint32_t) (__x); \
__asm__ __volatile__ ( \
"lrv %0,%1" \
: "=&d" (__v) : "m" (__tmp)); \
@@ -54,11 +55,11 @@
# else
# define __bswap_32(x) \
(__extension__ \
- ({ unsigned int __v, __x = (x); \
+ ({ uint32_t __v, __x = (x); \
if (__builtin_constant_p (x)) \
__v = __bswap_constant_32 (__x); \
else { \
- unsigned int __tmp = (unsigned int) (__x); \
+ uint32_t __tmp = (uint32_t) (__x); \
__asm__ __volatile__ ( \
"la 1,%1\n" \
"icm %0,8,3(1)\n" \
@@ -70,8 +71,8 @@
__v; }))
# endif
#else
-static __inline unsigned int
-__bswap_32 (unsigned int __bsx)
+static __inline uint32_t
+__bswap_32 (uint32_t __bsx)
{
return __bswap_constant_32 (__bsx);
}
@@ -92,11 +93,11 @@ __bswap_32 (unsigned int __bsx)
# if __WORDSIZE == 64
# define __bswap_64(x) \
(__extension__ \
- ({ unsigned long __w, __x = (x); \
+ ({ uint64_t __w, __x = (x); \
if (__builtin_constant_p (x)) \
__w = __bswap_constant_64 (__x); \
else { \
- unsigned long __tmp = (unsigned long) (__x); \
+ uint64_t __tmp = (uint64_t) (__x); \
__asm__ __volatile__ ( \
"lrvg %0,%1" \
: "=&d" (__w) : "m" (__tmp)); \
@@ -105,8 +106,8 @@ __bswap_32 (unsigned int __bsx)
# else
# define __bswap_64(x) \
__extension__ \
- ({ union { unsigned long long int __ll; \
- unsigned long int __l[2]; } __w, __r; \
+ ({ union { uint64_t __ll; \
+ uint32_t __l[2]; } __w, __r; \
__w.__ll = (x); \
__r.__l[0] = __bswap_32 (__w.__l[1]); \
__r.__l[1] = __bswap_32 (__w.__l[0]); \
@@ -123,8 +124,8 @@ __bswap_32 (unsigned int __bsx)
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
-static __inline unsigned long long int
-__bswap_64 (unsigned long long int __bsx)
+static __inline uint64_t
+__bswap_64 (uint64_t __bsx)
{
return __bswap_constant_64 (__bsx);
}
--- libc/sysdeps/x86/bits/byteswap-16.h.mp 2012-08-19 16:34:46.892008679 +0200
+++ libc/sysdeps/x86/bits/byteswap-16.h 2012-08-19 16:44:42.827193033 +0200
@@ -24,7 +24,7 @@
# if __GNUC__ >= 2
# define __bswap_16(x) \
(__extension__ \
- ({ register unsigned short int __v, __x = (unsigned short int) (x); \
+ ({ register uint16_t __v, __x = (uint16_t) (x); \
if (__builtin_constant_p (__x)) \
__v = __bswap_constant_16 (__x); \
else \
@@ -37,12 +37,12 @@
/* This is better than nothing. */
# define __bswap_16(x) \
(__extension__ \
- ({ register unsigned short int __x = (unsigned short int) (x); \
+ ({ register uint16_t __x = (uint16_t) (x); \
__bswap_constant_16 (__x); }))
# endif
#else
-static __inline unsigned short int
-__bswap_16 (unsigned short int __bsx)
+static __inline uint16_t
+__bswap_16 (uint16_t __bsx)
{
return __bswap_constant_16 (__bsx);
}
--- libc/sysdeps/x86/bits/byteswap.h.mp 2012-08-19 15:32:48.711742439 +0200
+++ libc/sysdeps/x86/bits/byteswap.h 2012-08-19 16:09:26.114071959 +0200
@@ -1,5 +1,5 @@
/* Macros to swap the order of bytes in integer values.
- Copyright (C) 1997-2012 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
@@ -24,11 +24,12 @@
#define _BITS_BYTESWAP_H 1
#include <features.h>
+#include <stdint.h>
#include <bits/wordsize.h>
/* Swap bytes in 16 bit value. */
#define __bswap_constant_16(x) \
- ((unsigned short int) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
+ ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
/* Get __bswap_16. */
#include <bits/byteswap-16.h>
@@ -40,8 +41,8 @@
#ifdef __GNUC__
# if __GNUC_PREREQ (4, 2)
-static __inline unsigned int
-__bswap_32 (unsigned int __bsx)
+static __inline uint32_t
+__bswap_32 (uint32_t __bsx)
{
return __builtin_bswap32 (__bsx);
}
@@ -56,7 +57,7 @@ __bswap_32 (unsigned int __bsx)
`bswap' opcode. On i386 we have to use three instructions. */
# define __bswap_32(x) \
(__extension__ \
- ({ register unsigned int __v, __x = (x); \
+ ({ register uint32_t __v, __x = (x); \
if (__builtin_constant_p (__x)) \
__v = __bswap_constant_32 (__x); \
else \
@@ -65,7 +66,7 @@ __bswap_32 (unsigned int __bsx)
# else
# define __bswap_32(x) \
(__extension__ \
- ({ register unsigned int __v, __x = (x); \
+ ({ register uint32_t __v, __x = (x); \
if (__builtin_constant_p (__x)) \
__v = __bswap_constant_32 (__x); \
else \
@@ -80,11 +81,11 @@ __bswap_32 (unsigned int __bsx)
# else
# define __bswap_32(x) \
(__extension__ \
- ({ register unsigned int __x = (x); __bswap_constant_32 (__x); }))
+ ({ register uint32_t __x = (x); __bswap_constant_32 (__x); }))
# endif
#else
-static __inline unsigned int
-__bswap_32 (unsigned int __bsx)
+static __inline uint32_t
+__bswap_32 (uint32_t __bsx)
{
return __bswap_constant_32 (__bsx);
}
@@ -104,15 +105,15 @@ __bswap_32 (unsigned int __bsx)
| (((x) & 0x00000000000000ffull) << 56)))
# if __GNUC_PREREQ (4, 2)
-static __inline unsigned long long int
-__bswap_64 (unsigned long long int __bsx)
+static __inline uint64_t
+__bswap_64 (uint64_t __bsx)
{
return __builtin_bswap64 (__bsx);
}
# elif __WORDSIZE == 64
# define __bswap_64(x) \
(__extension__ \
- ({ register unsigned long __v, __x = (x); \
+ ({ register uint64_t __v, __x = (x); \
if (__builtin_constant_p (__x)) \
__v = __bswap_constant_64 (__x); \
else \
@@ -121,8 +122,8 @@ __bswap_64 (unsigned long long int __bsx
# else
# define __bswap_64(x) \
(__extension__ \
- ({ union { __extension__ unsigned long long int __ll; \
- unsigned int __l[2]; } __w, __r; \
+ ({ union { __extension__ uint64_t __ll; \
+ uint32_t __l[2]; } __w, __r; \
if (__builtin_constant_p (x)) \
__r.__ll = __bswap_constant_64 (x); \
else \
@@ -144,8 +145,8 @@ __bswap_64 (unsigned long long int __bsx
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
-static __inline unsigned long long int
-__bswap_64 (unsigned long long int __bsx)
+static __inline uint64_t
+__bswap_64 (uint64_t __bsx)
{
return __bswap_constant_64 (__bsx);
}
Marek