[Vm-dev] [commit][3667] Provide eventually accelerated macros for
byte swapping
commits at squeakvm.org
commits at squeakvm.org
Sat Apr 2 21:58:25 UTC 2016
Revision: 3667
Author: nice
Date: 2016-04-02 14:58:22 -0700 (Sat, 02 Apr 2016)
Log Message:
-----------
Provide eventually accelerated macros for byte swapping
Modified Paths:
--------------
branches/Cog/platforms/Cross/vm/sqMemoryAccess.h
Modified: branches/Cog/platforms/Cross/vm/sqMemoryAccess.h
===================================================================
--- branches/Cog/platforms/Cross/vm/sqMemoryAccess.h 2016-04-01 00:36:10 UTC (rev 3666)
+++ branches/Cog/platforms/Cross/vm/sqMemoryAccess.h 2016-04-02 21:58:22 UTC (rev 3667)
@@ -195,7 +195,45 @@
#define storeSingleFloatAtfrom(i, floatVar) storeSingleFloatAtPointerfrom(pointerForOop(i), floatVar)
#define fetchSingleFloatAtinto(i, floatVar) fetchSingleFloatAtPointerinto(pointerForOop(i), floatVar)
+/* These accessors are for accelerating byte swapping
+ whenever intrinsics or other fast functions are available */
+/* Compatibility with non-clang compilers */
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
+/* GCC and Clang recent versions provide intrinsic byte swaps via builtins */
+#if (defined(__clang__) && __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)) \
+ || (defined(__GNUC__ ) && \
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# define SQ_SWAP_4_BYTES(x) __builtin_bswap32(x)
+# define SQ_SWAP_8_BYTES(x) __builtin_bswap64(x)
+#elif defined(__linux__)
+# include <byteswap.h>
+# define SQ_SWAP_4_BYTES(x) bswap_32(x)
+# define SQ_SWAP_8_BYTES(x) bswap_64(x)
+#elif defined(_MSC_VER)
+# include <stdlib.h>
+# define SQ_SWAP_4_BYTES(x) _byteswap_ulong(x)
+# define SQ_SWAP_8_BYTES(x) _byteswap_uint64(x)
+#else
+# define SQ_SWAP_4_BYTES(x) \
+ (((unsigned int)(x) << 24) | \\
+ (((unsigned int)(x) << 8) & 0xff0000U) | \\
+ (((unsigned int)(x) >> 8) & 0xff00U) | \\
+ ( (unsigned int)(x) >> 24))
+# define SQ_SWAP_8_BYTES(x) \
+ (((unsigned long long)(x) << 56) | \\
+ (((unsigned long long)(x) << 40) & 0xff000000000000ULL) | \\
+ (((unsigned long long)(x) << 24) & 0xff0000000000ULL) | \\
+ (((unsigned long long)(x) << 8) & 0xff00000000ULL) | \\
+ (((unsigned long long)(x) >> 8) & 0xff000000ULL) | \\
+ (((unsigned long long)(x) >> 24) & 0xff0000ULL) | \\
+ (((unsigned long long)(x) >> 40) & 0xff00ULL) | \\
+ ( (unsigned long long)(x) >> 56))
+#endif
+
+
/* This doesn't belong here, but neither do 'self flag: ...'s belong in the
image. We use a macro, not an inline function; we need no trace of flag.
*/
More information about the Vm-dev
mailing list