summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-10-04 12:49:02 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-10-04 12:49:02 +0900
commitfe25608edd6fc531b5c865dd511cd438bea2e897 (patch)
tree647483785a7532896b48f1884e122194ab69f91a /src
parentd52f825de60cf8d168aa6899253b6edb862d135b (diff)
eina: handle more compiler strangeness for bswap.
So current order is : - __builtin_bswap*() for compiler that provide it - _byteswap_*() for MSVC - bswap_*() for older Linux and some BSD - own C code when everything else fall appart. The reason for this order is that the builtin will always generate the best assembly possible. On my system bswap_*() are not changing in all version to the best solution as they are almost equivalent to the C macro.
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_config.h.in5
-rw-r--r--src/lib/eina/eina_inline_cpu.x26
2 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/eina/eina_config.h.in b/src/lib/eina/eina_config.h.in
index eb0869cf40..27acdf72b6 100644
--- a/src/lib/eina/eina_config.h.in
+++ b/src/lib/eina/eina_config.h.in
@@ -87,4 +87,9 @@
87#endif 87#endif
88@EINA_CONFIGURE_HAVE_BSWAP64@ 88@EINA_CONFIGURE_HAVE_BSWAP64@
89 89
90#ifdef EINA_HAVE_BYTESWAP_H
91# undef EINA_HAVE_BYTESWAP_H
92#endif
93@EINA_CONFIGURE_HAVE_BYTESWAP_H@
94
90#endif /* EINA_CONFIG_H_ */ 95#endif /* EINA_CONFIG_H_ */
diff --git a/src/lib/eina/eina_inline_cpu.x b/src/lib/eina/eina_inline_cpu.x
index bdfb4a4b13..18310f7347 100644
--- a/src/lib/eina/eina_inline_cpu.x
+++ b/src/lib/eina/eina_inline_cpu.x
@@ -23,11 +23,27 @@
23#ifndef EINA_INLINE_CPU_X_ 23#ifndef EINA_INLINE_CPU_X_
24#define EINA_INLINE_CPU_X_ 24#define EINA_INLINE_CPU_X_
25 25
26#ifdef EINA_HAVE_BYTESWAP_H
27# include <byteswap.h>
28#endif
29
30#ifdef __has_builtin
31# define EINA_HAS_BUILTIN(x) __has_builtin(x)
32#elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
33# define EINA_HAS_BUILTIN(x) 1
34#else
35# define EINA_HAS_BUILTIN(x) 0 // Compatibility for the rest of the world
36#endif
37
26static inline unsigned short 38static inline unsigned short
27eina_swap16(unsigned short x) 39eina_swap16(unsigned short x)
28{ 40{
29#ifdef EINA_HAVE_BSWAP16 41#if defined EINA_HAVE_BSWAP16 && EINA_HAS_BUILTIN(__builtin_bswap16)
30 return __builtin_bswap16(x); 42 return __builtin_bswap16(x);
43#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
44 return _byteswap_ushort(x);
45#elif defined EINA_HAVE_BYTESWAP_H
46 return bswap_16(x);
31#else 47#else
32 return (((x & 0xff00) >> 8) | 48 return (((x & 0xff00) >> 8) |
33 ((x & 0x00ff) << 8)); 49 ((x & 0x00ff) << 8));
@@ -39,6 +55,10 @@ eina_swap32(unsigned int x)
39{ 55{
40#ifdef EINA_HAVE_BSWAP32 56#ifdef EINA_HAVE_BSWAP32
41 return __builtin_bswap32(x); 57 return __builtin_bswap32(x);
58#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
59 return _byteswap_ulong(x);
60#elif defined EINA_HAVE_BYTESWAP_H
61 return bswap_32(x);
42#else 62#else
43 return (x >> 24) | 63 return (x >> 24) |
44 ((x >> 8) & 0x0000FF00) | 64 ((x >> 8) & 0x0000FF00) |
@@ -52,6 +72,10 @@ eina_swap64(unsigned long long x)
52{ 72{
53#ifdef EINA_HAVE_BSWAP64 73#ifdef EINA_HAVE_BSWAP64
54 return __builtin_bswap64(x); 74 return __builtin_bswap64(x);
75#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
76 return _byteswap_uint64(x);
77#elif defined EINA_HAVE_BYTESWAP_H
78 return bswap_64(x);
55#else 79#else
56 return (((x & 0xff00000000000000ull) >> 56) | 80 return (((x & 0xff00000000000000ull) >> 56) |
57 ((x & 0x00ff000000000000ull) >> 40) | 81 ((x & 0x00ff000000000000ull) >> 40) |