summaryrefslogtreecommitdiff
path: root/pack.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-27 22:00:15 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-27 22:00:15 +0000
commit95fd5f33c08b1d8f6645d7739a1268dc8c6fa5de (patch)
tree4f0681148a2f6228077b1e48124153f899bde0bd /pack.c
parent81b7329d0b967653230af16bfac8a2c37c201c52 (diff)
* pack.c (swap32): use __builtin_bswap32 on gcc 4.3.0 or later.
(swap64): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/pack.c b/pack.c
index 9b14b80828..1b46fd4a38 100644
--- a/pack.c
+++ b/pack.c
@@ -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 @@ TOKEN_PASTE(swap,x)(xtype z) \
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 @@ TOKEN_PASTE(swap,x)(xtype z) \
#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) \