From 11376df686533f658cac985344f45d6132a87076 Mon Sep 17 00:00:00 2001 From: Manish Singh Date: Wed, 11 Nov 1998 01:26:10 +0000 Subject: [PATCH] use __extension__ for long long on gcc >= 2.8 and egcs, and provide a * configure.in: use __extension__ for long long on gcc >= 2.8 and egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic compiles clean. * glib.h: make the endian x86 asm __const__ so the compiler can do better optimizations. Also remove the cc clobber, these shouldn't be changing condition codes. Ditch some redundant casts. Add an optimization for 64-bit endian conversions in x86. Use constant wrapper for the generic method. * testglib.c: use constant wrappers for 64-bit constants -Yosh --- ChangeLog | 14 ++++++++ ChangeLog.pre-2-0 | 14 ++++++++ ChangeLog.pre-2-10 | 14 ++++++++ ChangeLog.pre-2-12 | 14 ++++++++ ChangeLog.pre-2-2 | 14 ++++++++ ChangeLog.pre-2-4 | 14 ++++++++ ChangeLog.pre-2-6 | 14 ++++++++ ChangeLog.pre-2-8 | 14 ++++++++ configure.in | 37 +++++++++++++++++---- glib.h | 97 ++++++++++++++++++++++++++++++++++-------------------- glib/glib.h | 97 ++++++++++++++++++++++++++++++++++-------------------- testglib.c | 3 +- tests/testglib.c | 3 +- 13 files changed, 271 insertions(+), 78 deletions(-) diff --git a/ChangeLog b/ChangeLog index f89a573..bfa281c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index f89a573..bfa281c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +Tue Nov 10 17:12:45 PST 1998 Manish Singh + + * configure.in: use __extension__ for long long on gcc >= 2.8 and + egcs, and provide a G_GINT64_CONSTANT wrapper so -ansi -pedantic + compiles clean. + + * glib.h: make the endian x86 asm __const__ so the compiler can do + better optimizations. Also remove the cc clobber, these shouldn't + be changing condition codes. Ditch some redundant casts. Add an + optimization for 64-bit endian conversions in x86. Use constant + wrapper for the generic method. + + * testglib.c: use constant wrappers for 64-bit constants + 1998-11-04 Phil Schwan * configure.in: Added 'strncasecmp' to the list of functions to be diff --git a/configure.in b/configure.in index 40eb7e5..f8c28ad 100644 --- a/configure.in +++ b/configure.in @@ -584,9 +584,12 @@ outfile_EOF fi if test -n "$gint64"; then cat >>$outfile <= 2 #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END -#elif defined (__alpha__) && defined (__GNUC__) +#elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2 #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END #else /* !__i386__ && !__alpha__ */ #define G_BREAKPOINT() @@ -533,37 +533,34 @@ typedef gint32 GTime; /* Intel specific stuff for speed */ -#if defined (__i386__) && (defined __GNUC__) +#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 # define GUINT16_SWAP_LE_BE_X86(val) \ - (__extension__ \ - ({ register guint16 __v; \ - if (__builtin_constant_p (val)) \ - __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \ - else \ - __asm__ __volatile__ ("rorw $8, %w0" \ - : "=r" (__v) \ - : "0" ((guint16) (val)) \ - : "cc"); \ + (__extension__ \ + ({ register guint16 __v; \ + if (__builtin_constant_p (val)) \ + __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \ + else \ + __asm__ __const__ ("rorw $8, %w0" \ + : "=r" (__v) \ + : "0" ((guint16) (val))); \ __v; })) -# define GUINT16_SWAP_LE_BE(val) \ - ((guint16) GUINT16_SWAP_LE_BE_X86 ((guint16) (val))) +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val)) # if !defined(__i486__) && !defined(__i586__) \ - && !defined(__pentium__) && !defined(__pentiumpro__) && !defined(__i686__) + && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__) # define GUINT32_SWAP_LE_BE_X86(val) \ (__extension__ \ ({ register guint32 __v; \ if (__builtin_constant_p (val)) \ __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ else \ - __asm__ __volatile__ ("rorw $8, %w0\n\t" \ - "rorl $16, %0\n\t" \ - "rorw $8, %w0" \ - : "=r" (__v) \ - : "0" ((guint32) (val)) \ - : "cc"); \ + __asm__ __const__ ("rorw $8, %w0\n\t" \ + "rorl $16, %0\n\t" \ + "rorw $8, %w0" \ + : "=r" (__v) \ + : "0" ((guint32) (val))); \ __v; })) # else /* 486 and higher has bswap */ @@ -573,14 +570,13 @@ typedef gint32 GTime; if (__builtin_constant_p (val)) \ __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ else \ - __asm__ __volatile__ ("bswap %0" \ - : "=r" (__v) \ - : "0" ((guint32) (val))); \ + __asm__ __const__ ("bswap %0" \ + : "=r" (__v) \ + : "0" ((guint32) (val))); \ __v; })) # endif /* processor specific 32-bit stuff */ -# define GUINT32_SWAP_LE_BE(val) \ - ((guint32) GUINT32_SWAP_LE_BE_X86 ((guint32) (val))) +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val)) #else /* !__i386__ */ # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) @@ -588,15 +584,46 @@ typedef gint32 GTime; #endif /* __i386__ */ #ifdef G_HAVE_GINT64 -#define GUINT64_SWAP_LE_BE(val) ((guint64) ( \ - (((guint64) (val) & (guint64) 0x00000000000000ffU) << 56) | \ - (((guint64) (val) & (guint64) 0x000000000000ff00U) << 40) | \ - (((guint64) (val) & (guint64) 0x0000000000ff0000U) << 24) | \ - (((guint64) (val) & (guint64) 0x00000000ff000000U) << 8) | \ - (((guint64) (val) & (guint64) 0x000000ff00000000U) >> 8) | \ - (((guint64) (val) & (guint64) 0x0000ff0000000000U) >> 24) | \ - (((guint64) (val) & (guint64) 0x00ff000000000000U) >> 40) | \ - (((guint64) (val) & (guint64) 0xff00000000000000U) >> 56))) +# define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) << 8) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >> 8) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56))) + +# if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 +# define GUINT64_SWAP_LE_BE_X86(val) \ + (__extension__ \ + ({ union { guint64 __ll; \ + guint32 __l[2]; } __r; \ + if (__builtin_constant_p (val)) \ + __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val); \ + else \ + { \ + union { guint64 __ll; \ + guint32 __l[2]; } __w; \ + __w.__ll = ((guint64) val); \ + __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ + __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ + } \ + __r.__ll; })) + +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val)) + +# else /* !__i386__ */ +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val)) +# endif #endif #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val)) diff --git a/glib/glib.h b/glib/glib.h index 9e93836..9f6c517 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -301,9 +301,9 @@ extern "C" { /* Hacker macro to place breakpoints for x86 machines. * Actual use is strongly deprecated of course ;) */ -#if defined (__i386__) && defined (__GNUC__) +#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END -#elif defined (__alpha__) && defined (__GNUC__) +#elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2 #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END #else /* !__i386__ && !__alpha__ */ #define G_BREAKPOINT() @@ -533,37 +533,34 @@ typedef gint32 GTime; /* Intel specific stuff for speed */ -#if defined (__i386__) && (defined __GNUC__) +#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 # define GUINT16_SWAP_LE_BE_X86(val) \ - (__extension__ \ - ({ register guint16 __v; \ - if (__builtin_constant_p (val)) \ - __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \ - else \ - __asm__ __volatile__ ("rorw $8, %w0" \ - : "=r" (__v) \ - : "0" ((guint16) (val)) \ - : "cc"); \ + (__extension__ \ + ({ register guint16 __v; \ + if (__builtin_constant_p (val)) \ + __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \ + else \ + __asm__ __const__ ("rorw $8, %w0" \ + : "=r" (__v) \ + : "0" ((guint16) (val))); \ __v; })) -# define GUINT16_SWAP_LE_BE(val) \ - ((guint16) GUINT16_SWAP_LE_BE_X86 ((guint16) (val))) +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val)) # if !defined(__i486__) && !defined(__i586__) \ - && !defined(__pentium__) && !defined(__pentiumpro__) && !defined(__i686__) + && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__) # define GUINT32_SWAP_LE_BE_X86(val) \ (__extension__ \ ({ register guint32 __v; \ if (__builtin_constant_p (val)) \ __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ else \ - __asm__ __volatile__ ("rorw $8, %w0\n\t" \ - "rorl $16, %0\n\t" \ - "rorw $8, %w0" \ - : "=r" (__v) \ - : "0" ((guint32) (val)) \ - : "cc"); \ + __asm__ __const__ ("rorw $8, %w0\n\t" \ + "rorl $16, %0\n\t" \ + "rorw $8, %w0" \ + : "=r" (__v) \ + : "0" ((guint32) (val))); \ __v; })) # else /* 486 and higher has bswap */ @@ -573,14 +570,13 @@ typedef gint32 GTime; if (__builtin_constant_p (val)) \ __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ else \ - __asm__ __volatile__ ("bswap %0" \ - : "=r" (__v) \ - : "0" ((guint32) (val))); \ + __asm__ __const__ ("bswap %0" \ + : "=r" (__v) \ + : "0" ((guint32) (val))); \ __v; })) # endif /* processor specific 32-bit stuff */ -# define GUINT32_SWAP_LE_BE(val) \ - ((guint32) GUINT32_SWAP_LE_BE_X86 ((guint32) (val))) +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val)) #else /* !__i386__ */ # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) @@ -588,15 +584,46 @@ typedef gint32 GTime; #endif /* __i386__ */ #ifdef G_HAVE_GINT64 -#define GUINT64_SWAP_LE_BE(val) ((guint64) ( \ - (((guint64) (val) & (guint64) 0x00000000000000ffU) << 56) | \ - (((guint64) (val) & (guint64) 0x000000000000ff00U) << 40) | \ - (((guint64) (val) & (guint64) 0x0000000000ff0000U) << 24) | \ - (((guint64) (val) & (guint64) 0x00000000ff000000U) << 8) | \ - (((guint64) (val) & (guint64) 0x000000ff00000000U) >> 8) | \ - (((guint64) (val) & (guint64) 0x0000ff0000000000U) >> 24) | \ - (((guint64) (val) & (guint64) 0x00ff000000000000U) >> 40) | \ - (((guint64) (val) & (guint64) 0xff00000000000000U) >> 56))) +# define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) << 8) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >> 8) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) | \ + (((guint64) (val) & \ + (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56))) + +# if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 +# define GUINT64_SWAP_LE_BE_X86(val) \ + (__extension__ \ + ({ union { guint64 __ll; \ + guint32 __l[2]; } __r; \ + if (__builtin_constant_p (val)) \ + __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val); \ + else \ + { \ + union { guint64 __ll; \ + guint32 __l[2]; } __w; \ + __w.__ll = ((guint64) val); \ + __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ + __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ + } \ + __r.__ll; })) + +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val)) + +# else /* !__i386__ */ +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val)) +# endif #endif #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val)) diff --git a/testglib.c b/testglib.c index 3a20d62..6a76389 100644 --- a/testglib.c +++ b/testglib.c @@ -324,7 +324,8 @@ main (int argc, guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U; guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U; #ifdef G_HAVE_GINT64 - guint64 gu64t1 = 0x1d636b02300a7aa7U, gu64t2 = 0xa77a0a30026b631dU; + guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U), + gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU); #endif g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n", diff --git a/tests/testglib.c b/tests/testglib.c index 3a20d62..6a76389 100644 --- a/tests/testglib.c +++ b/tests/testglib.c @@ -324,7 +324,8 @@ main (int argc, guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U; guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U; #ifdef G_HAVE_GINT64 - guint64 gu64t1 = 0x1d636b02300a7aa7U, gu64t2 = 0xa77a0a30026b631dU; + guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U), + gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU); #endif g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n", -- 2.7.4