… | |
… | |
150 | |
150 | |
151 | #if ECB_NO_SMP |
151 | #if ECB_NO_SMP |
152 | #define ECB_MEMORY_FENCE do { } while (0) |
152 | #define ECB_MEMORY_FENCE do { } while (0) |
153 | #endif |
153 | #endif |
154 | |
154 | |
|
|
155 | /* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/compiler_ref/compiler_builtins.html */ |
|
|
156 | #if __xlC__ && ECB_CPP |
|
|
157 | #include <builtins.h> |
|
|
158 | #endif |
|
|
159 | |
155 | #ifndef ECB_MEMORY_FENCE |
160 | #ifndef ECB_MEMORY_FENCE |
156 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
161 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
157 | #if __i386 || __i386__ |
162 | #if __i386 || __i386__ |
158 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
163 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
159 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
164 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
… | |
… | |
170 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
175 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
171 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
176 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
172 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
177 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
173 | #elif __aarch64__ |
178 | #elif __aarch64__ |
174 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb ish" : : : "memory") |
179 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb ish" : : : "memory") |
175 | #elif (__sparc || __sparc__) && !__sparcv8 |
180 | #elif (__sparc || __sparc__) && !(__sparc_v8__ || defined __sparcv8) |
176 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
181 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
177 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
182 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
178 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
183 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
179 | #elif defined __s390__ || defined __s390x__ |
184 | #elif defined __s390__ || defined __s390x__ |
180 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
185 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
… | |
… | |
352 | #define ecb_deprecated __declspec (deprecated) |
357 | #define ecb_deprecated __declspec (deprecated) |
353 | #else |
358 | #else |
354 | #define ecb_deprecated ecb_attribute ((__deprecated__)) |
359 | #define ecb_deprecated ecb_attribute ((__deprecated__)) |
355 | #endif |
360 | #endif |
356 | |
361 | |
357 | #if __MSC_VER >= 1500 |
362 | #if _MSC_VER >= 1500 |
358 | #define ecb_deprecated_message(msg) __declspec (deprecated (msg)) |
363 | #define ecb_deprecated_message(msg) __declspec (deprecated (msg)) |
359 | #elif ECB_GCC_VERSION(4,5) |
364 | #elif ECB_GCC_VERSION(4,5) |
360 | #define ecb_deprecated_message(msg) ecb_attribute ((__deprecated__ (msg)) |
365 | #define ecb_deprecated_message(msg) ecb_attribute ((__deprecated__ (msg)) |
361 | #else |
366 | #else |
362 | #define ecb_deprecated_message(msg) ecb_deprecated |
367 | #define ecb_deprecated_message(msg) ecb_deprecated |
… | |
… | |
371 | #define ecb_unused ecb_attribute ((__unused__)) |
376 | #define ecb_unused ecb_attribute ((__unused__)) |
372 | #define ecb_const ecb_attribute ((__const__)) |
377 | #define ecb_const ecb_attribute ((__const__)) |
373 | #define ecb_pure ecb_attribute ((__pure__)) |
378 | #define ecb_pure ecb_attribute ((__pure__)) |
374 | |
379 | |
375 | #if ECB_C11 || __IBMC_NORETURN |
380 | #if ECB_C11 || __IBMC_NORETURN |
376 | /* http://pic.dhe.ibm.com/infocenter/compbg/v121v141/topic/com.ibm.xlcpp121.bg.doc/language_ref/noreturn.html */ |
381 | /* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/language_ref/noreturn.html */ |
377 | #define ecb_noreturn _Noreturn |
382 | #define ecb_noreturn _Noreturn |
378 | #elif ECB_CPP11 |
383 | #elif ECB_CPP11 |
379 | #define ecb_noreturn [[noreturn]] |
384 | #define ecb_noreturn [[noreturn]] |
380 | #elif _MSC_VER >= 1200 |
385 | #elif _MSC_VER >= 1200 |
381 | /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx */ |
386 | /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx */ |
… | |
… | |
547 | ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } |
552 | ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } |
548 | ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } |
553 | ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } |
549 | ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } |
554 | ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } |
550 | |
555 | |
551 | #if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64)) |
556 | #if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64)) |
|
|
557 | #if ECB_GCC_VERSION(4,8) || ECB_CLANG_BUILTIN(__builtin_bswap16) |
|
|
558 | #define ecb_bswap16(x) __builtin_bswap16 (x) |
|
|
559 | #else |
552 | #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) |
560 | #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) |
|
|
561 | #endif |
553 | #define ecb_bswap32(x) __builtin_bswap32 (x) |
562 | #define ecb_bswap32(x) __builtin_bswap32 (x) |
554 | #define ecb_bswap64(x) __builtin_bswap64 (x) |
563 | #define ecb_bswap64(x) __builtin_bswap64 (x) |
|
|
564 | #elif _MSC_VER |
|
|
565 | #include <stdlib.h> |
|
|
566 | #define ecb_bswap16(x) ((uint16_t)_byteswap_ushort ((uint16_t)(x))) |
|
|
567 | #define ecb_bswap32(x) ((uint32_t)_byteswap_ulong ((uint32_t)(x))) |
|
|
568 | #define ecb_bswap64(x) ((uint64_t)_byteswap_uint64 ((uint64_t)(x))) |
555 | #else |
569 | #else |
556 | ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x); |
570 | ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x); |
557 | ecb_function_ ecb_const uint16_t |
571 | ecb_function_ ecb_const uint16_t |
558 | ecb_bswap16 (uint16_t x) |
572 | ecb_bswap16 (uint16_t x) |
559 | { |
573 | { |
… | |
… | |
693 | #define ECB_NAN ECB_INFINITY |
707 | #define ECB_NAN ECB_INFINITY |
694 | #endif |
708 | #endif |
695 | |
709 | |
696 | #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L |
710 | #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L |
697 | #define ecb_ldexpf(x,e) ldexpf ((x), (e)) |
711 | #define ecb_ldexpf(x,e) ldexpf ((x), (e)) |
|
|
712 | #define ecb_frexpf(x,e) frexpf ((x), (e)) |
698 | #else |
713 | #else |
699 | #define ecb_ldexpf(x,e) (float) ldexp ((double) (x), (e)) |
714 | #define ecb_ldexpf(x,e) (float) ldexp ((double) (x), (e)) |
|
|
715 | #define ecb_frexpf(x,e) (float) frexp ((double) (x), (e)) |
700 | #endif |
716 | #endif |
701 | |
717 | |
702 | /* converts an ieee half/binary16 to a float */ |
718 | /* converts an ieee half/binary16 to a float */ |
703 | ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x); |
719 | ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x); |
704 | ecb_function_ ecb_const float |
720 | ecb_function_ ecb_const float |
… | |
… | |
733 | if (x == 0e0f ) return 0x00000000U; |
749 | if (x == 0e0f ) return 0x00000000U; |
734 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
750 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
735 | if (x < -3.40282346638528860e+38f) return 0xff800000U; |
751 | if (x < -3.40282346638528860e+38f) return 0xff800000U; |
736 | if (x != x ) return 0x7fbfffffU; |
752 | if (x != x ) return 0x7fbfffffU; |
737 | |
753 | |
738 | m = frexpf (x, &e) * 0x1000000U; |
754 | m = ecb_frexpf (x, &e) * 0x1000000U; |
739 | |
755 | |
740 | r = m & 0x80000000U; |
756 | r = m & 0x80000000U; |
741 | |
757 | |
742 | if (r) |
758 | if (r) |
743 | m = -m; |
759 | m = -m; |