summaryrefslogtreecommitdiff
path: root/internal.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-21 17:22:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-21 17:22:14 +0000
commit8e9c9ec8e47866c116d29dd4e2ee0b40bbbe6b00 (patch)
tree477aaed9ef0fb4a9601cf50f8af1ee92c0fbd832 /internal.h
parent6503d883124d8193c3adf485ebe1977fb2503a29 (diff)
* bignum.c (bary_pack): Specialized packers implemented.
(HOST_BIGENDIAN_P): New macro. (ALIGNOF): New macro. (CLEAR_LOWBITS): New macro. (FILL_LOWBITS): New macro. (swap_bdigit): New macro. (bary_2comp): Returns an int. * internal.h (swap16): Moved from pack.c (swap32): Ditto. (swap64): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r--internal.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal.h b/internal.h
index 267d388363..de4403761e 100644
--- a/internal.h
+++ b/internal.h
@@ -73,6 +73,43 @@ extern "C" {
(INTEGER_PACK_MSWORD_FIRST | \
INTEGER_PACK_MSBYTE_FIRST)
+#ifndef swap16
+# define swap16(x) ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF)))
+#endif
+
+#ifndef swap32
+# if GCC_VERSION_SINCE(4,3,0)
+# define swap32(x) __builtin_bswap32(x)
+# endif
+#endif
+
+#ifndef swap32
+# define swap32(x) ((uint32_t)((((x)&0xFF)<<24) \
+ |(((x)>>24)&0xFF) \
+ |(((x)&0x0000FF00)<<8) \
+ |(((x)&0x00FF0000)>>8) ))
+#endif
+
+#ifndef swap64
+# if GCC_VERSION_SINCE(4,3,0)
+# define swap64(x) __builtin_bswap64(x)
+# endif
+#endif
+
+#ifndef swap64
+# ifdef HAVE_INT64_T
+# define byte_in_64bit(n) ((uint64_t)0xff << (n))
+# define swap64(x) ((uint64_t)((((x)&byte_in_64bit(0))<<56) \
+ |(((x)>>56)&0xFF) \
+ |(((x)&byte_in_64bit(8))<<40) \
+ |(((x)&byte_in_64bit(48))>>40) \
+ |(((x)&byte_in_64bit(16))<<24) \
+ |(((x)&byte_in_64bit(40))>>24) \
+ |(((x)&byte_in_64bit(24))<<8) \
+ |(((x)&byte_in_64bit(32))>>8)))
+# endif
+#endif
+
struct rb_deprecated_classext_struct {
char conflict[sizeof(VALUE) * 3];
};