… | |
… | |
640 | #define ECB_NO_SMP 1 |
640 | #define ECB_NO_SMP 1 |
641 | #endif |
641 | #endif |
642 | |
642 | |
643 | #if ECB_NO_SMP |
643 | #if ECB_NO_SMP |
644 | #define ECB_MEMORY_FENCE do { } while (0) |
644 | #define ECB_MEMORY_FENCE do { } while (0) |
|
|
645 | #endif |
|
|
646 | |
|
|
647 | /* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/compiler_ref/compiler_builtins.html */ |
|
|
648 | #if __xlC__ && ECB_CPP |
|
|
649 | #include <builtins.h> |
645 | #endif |
650 | #endif |
646 | |
651 | |
647 | #ifndef ECB_MEMORY_FENCE |
652 | #ifndef ECB_MEMORY_FENCE |
648 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
653 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
649 | #if __i386 || __i386__ |
654 | #if __i386 || __i386__ |
… | |
… | |
844 | #define ecb_deprecated __declspec (deprecated) |
849 | #define ecb_deprecated __declspec (deprecated) |
845 | #else |
850 | #else |
846 | #define ecb_deprecated ecb_attribute ((__deprecated__)) |
851 | #define ecb_deprecated ecb_attribute ((__deprecated__)) |
847 | #endif |
852 | #endif |
848 | |
853 | |
849 | #if __MSC_VER >= 1500 |
854 | #if _MSC_VER >= 1500 |
850 | #define ecb_deprecated_message(msg) __declspec (deprecated (msg)) |
855 | #define ecb_deprecated_message(msg) __declspec (deprecated (msg)) |
851 | #elif ECB_GCC_VERSION(4,5) |
856 | #elif ECB_GCC_VERSION(4,5) |
852 | #define ecb_deprecated_message(msg) ecb_attribute ((__deprecated__ (msg)) |
857 | #define ecb_deprecated_message(msg) ecb_attribute ((__deprecated__ (msg)) |
853 | #else |
858 | #else |
854 | #define ecb_deprecated_message(msg) ecb_deprecated |
859 | #define ecb_deprecated_message(msg) ecb_deprecated |
… | |
… | |
863 | #define ecb_unused ecb_attribute ((__unused__)) |
868 | #define ecb_unused ecb_attribute ((__unused__)) |
864 | #define ecb_const ecb_attribute ((__const__)) |
869 | #define ecb_const ecb_attribute ((__const__)) |
865 | #define ecb_pure ecb_attribute ((__pure__)) |
870 | #define ecb_pure ecb_attribute ((__pure__)) |
866 | |
871 | |
867 | #if ECB_C11 || __IBMC_NORETURN |
872 | #if ECB_C11 || __IBMC_NORETURN |
868 | /* http://pic.dhe.ibm.com/infocenter/compbg/v121v141/topic/com.ibm.xlcpp121.bg.doc/language_ref/noreturn.html */ |
873 | /* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/language_ref/noreturn.html */ |
869 | #define ecb_noreturn _Noreturn |
874 | #define ecb_noreturn _Noreturn |
870 | #elif ECB_CPP11 |
875 | #elif ECB_CPP11 |
871 | #define ecb_noreturn [[noreturn]] |
876 | #define ecb_noreturn [[noreturn]] |
872 | #elif _MSC_VER >= 1200 |
877 | #elif _MSC_VER >= 1200 |
873 | /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx */ |
878 | /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx */ |
… | |
… | |
1039 | ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } |
1044 | ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } |
1040 | ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } |
1045 | ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } |
1041 | ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } |
1046 | ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } |
1042 | |
1047 | |
1043 | #if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64)) |
1048 | #if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64)) |
|
|
1049 | #if ECB_GCC_VERSION(4,8) || ECB_CLANG_BUILTIN(__builtin_bswap16) |
|
|
1050 | #define ecb_bswap16(x) __builtin_bswap16 (x) |
|
|
1051 | #else |
1044 | #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) |
1052 | #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) |
|
|
1053 | #endif |
1045 | #define ecb_bswap32(x) __builtin_bswap32 (x) |
1054 | #define ecb_bswap32(x) __builtin_bswap32 (x) |
1046 | #define ecb_bswap64(x) __builtin_bswap64 (x) |
1055 | #define ecb_bswap64(x) __builtin_bswap64 (x) |
|
|
1056 | #elif _MSC_VER |
|
|
1057 | #include <stdlib.h> |
|
|
1058 | #define ecb_bswap16(x) ((uint16_t)_byteswap_ushort ((uint16_t)(x))) |
|
|
1059 | #define ecb_bswap32(x) ((uint32_t)_byteswap_ulong ((uint32_t)(x))) |
|
|
1060 | #define ecb_bswap64(x) ((uint64_t)_byteswap_uint64 ((uint64_t)(x))) |
1047 | #else |
1061 | #else |
1048 | ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x); |
1062 | ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x); |
1049 | ecb_function_ ecb_const uint16_t |
1063 | ecb_function_ ecb_const uint16_t |
1050 | ecb_bswap16 (uint16_t x) |
1064 | ecb_bswap16 (uint16_t x) |
1051 | { |
1065 | { |
… | |
… | |
1185 | #define ECB_NAN ECB_INFINITY |
1199 | #define ECB_NAN ECB_INFINITY |
1186 | #endif |
1200 | #endif |
1187 | |
1201 | |
1188 | #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L |
1202 | #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L |
1189 | #define ecb_ldexpf(x,e) ldexpf ((x), (e)) |
1203 | #define ecb_ldexpf(x,e) ldexpf ((x), (e)) |
|
|
1204 | #define ecb_frexpf(x,e) frexpf ((x), (e)) |
1190 | #else |
1205 | #else |
1191 | #define ecb_ldexpf(x,e) (float) ldexp ((float) (x), (e)) |
1206 | #define ecb_ldexpf(x,e) (float) ldexp ((double) (x), (e)) |
|
|
1207 | #define ecb_frexpf(x,e) (float) frexp ((double) (x), (e)) |
1192 | #endif |
1208 | #endif |
1193 | |
1209 | |
1194 | /* converts an ieee half/binary16 to a float */ |
1210 | /* converts an ieee half/binary16 to a float */ |
1195 | ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x); |
1211 | ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x); |
1196 | ecb_function_ ecb_const float |
1212 | ecb_function_ ecb_const float |
… | |
… | |
1225 | if (x == 0e0f ) return 0x00000000U; |
1241 | if (x == 0e0f ) return 0x00000000U; |
1226 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
1242 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
1227 | if (x < -3.40282346638528860e+38f) return 0xff800000U; |
1243 | if (x < -3.40282346638528860e+38f) return 0xff800000U; |
1228 | if (x != x ) return 0x7fbfffffU; |
1244 | if (x != x ) return 0x7fbfffffU; |
1229 | |
1245 | |
1230 | m = frexpf (x, &e) * 0x1000000U; |
1246 | m = ecb_frexpf (x, &e) * 0x1000000U; |
1231 | |
1247 | |
1232 | r = m & 0x80000000U; |
1248 | r = m & 0x80000000U; |
1233 | |
1249 | |
1234 | if (r) |
1250 | if (r) |
1235 | m = -m; |
1251 | m = -m; |