ruby-changes:14906
From: akr <ko1@a...>
Date: Sun, 28 Feb 2010 07:00:31 +0900 (JST)
Subject: [ruby-changes:14906] Ruby:r26776 (trunk): * pack.c (swap32): use __builtin_bswap32 on gcc 4.3.0 or later.
akr 2010-02-28 07:00:15 +0900 (Sun, 28 Feb 2010) New Revision: 26776 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26776 Log: * pack.c (swap32): use __builtin_bswap32 on gcc 4.3.0 or later. (swap64): ditto. Modified files: trunk/ChangeLog trunk/pack.c Index: ChangeLog =================================================================== --- ChangeLog (revision 26775) +++ ChangeLog (revision 26776) @@ -1,3 +1,8 @@ +Sun Feb 28 06:58:53 2010 Tanaka Akira <akr@f...> + + * pack.c (swap32): use __builtin_bswap32 on gcc 4.3.0 or later. + (swap64): ditto. + Sun Feb 28 00:38:18 2010 Tanaka Akira <akr@f...> * pack.c: use integer types with explicit size. Index: pack.c =================================================================== --- pack.c (revision 26775) +++ pack.c (revision 26776) @@ -15,6 +15,12 @@ #include <ctype.h> #include <errno.h> +#define GCC_VERSION_SINCE(major, minor, patchlevel) \ + (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ + ((__GNUC__ > (major)) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) + #define SIZE16 2 #define SIZE32 4 @@ -79,6 +85,11 @@ return r; \ } +#if GCC_VERSION_SINCE(4,3,0) +# define swap32(x) __builtin_bswap32(x) +# define swap64(x) __builtin_bswap64(x) +#endif + #ifndef swap16 # define swap16(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) #endif @@ -92,7 +103,7 @@ #ifndef swap64 # ifdef HAVE_INT64_T -# define byte_in_64bit(n) ((uint64_t)0xff << n) +# define byte_in_64bit(n) ((uint64_t)0xff << (n)) # define swap64(x) ((((x)&byte_in_64bit(0))<<56) \ |(((x)>>56)&0xFF) \ |(((x)&byte_in_64bit(8))<<40) \ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/