… | |
… | |
98 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
98 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
99 | #endif |
99 | #endif |
100 | |
100 | |
101 | #define ECB_CLANG_VERSION(major,minor) (__clang_major__ > (major) || (__clang_major__ == (major) && __clang_minor__ >= (minor))) |
101 | #define ECB_CLANG_VERSION(major,minor) (__clang_major__ > (major) || (__clang_major__ == (major) && __clang_minor__ >= (minor))) |
102 | |
102 | |
103 | #if __clang__ && defined(__has_builtin) |
103 | #if __clang__ && defined __has_builtin |
104 | #define ECB_CLANG_BUILTIN(x) __has_builtin(x) |
104 | #define ECB_CLANG_BUILTIN(x) __has_builtin (x) |
105 | #else |
105 | #else |
106 | #define ECB_CLANG_BUILTIN(x) 0 |
106 | #define ECB_CLANG_BUILTIN(x) 0 |
107 | #endif |
107 | #endif |
108 | |
108 | |
109 | #if __clang__ && defined(__has_extension) |
109 | #if __clang__ && defined __has_extension |
110 | #define ECB_CLANG_EXTENSION(x) __has_extension(x) |
110 | #define ECB_CLANG_EXTENSION(x) __has_extension (x) |
111 | #else |
111 | #else |
112 | #define ECB_CLANG_EXTENSION(x) 0 |
112 | #define ECB_CLANG_EXTENSION(x) 0 |
113 | #endif |
113 | #endif |
114 | |
114 | |
115 | #define ECB_CPP (__cplusplus+0) |
115 | #define ECB_CPP (__cplusplus+0) |
… | |
… | |
335 | #define ecb_prefetch(addr,rw,locality) |
335 | #define ecb_prefetch(addr,rw,locality) |
336 | #endif |
336 | #endif |
337 | |
337 | |
338 | /* no emulation for ecb_decltype */ |
338 | /* no emulation for ecb_decltype */ |
339 | #if ECB_CPP11 |
339 | #if ECB_CPP11 |
|
|
340 | // older implementations might have problems with decltype(x)::type, work around it |
|
|
341 | template<class T> struct ecb_decltype_t { typedef T type; }; |
340 | #define ecb_decltype(x) decltype (x) |
342 | #define ecb_decltype(x) ecb_decltype_t<decltype (x)>::type |
341 | #elif ECB_GCC_VERSION(3,0) || ECB_CLANG_VERSION(2,8) |
343 | #elif ECB_GCC_VERSION(3,0) || ECB_CLANG_VERSION(2,8) |
342 | #define ecb_decltype(x) __typeof__ (x) |
344 | #define ecb_decltype(x) __typeof__ (x) |
343 | #endif |
345 | #endif |
344 | |
346 | |
345 | #if _MSC_VER >= 1300 |
347 | #if _MSC_VER >= 1300 |
… | |
… | |
351 | #define ecb_noinline ecb_attribute ((__noinline__)) |
353 | #define ecb_noinline ecb_attribute ((__noinline__)) |
352 | #define ecb_unused ecb_attribute ((__unused__)) |
354 | #define ecb_unused ecb_attribute ((__unused__)) |
353 | #define ecb_const ecb_attribute ((__const__)) |
355 | #define ecb_const ecb_attribute ((__const__)) |
354 | #define ecb_pure ecb_attribute ((__pure__)) |
356 | #define ecb_pure ecb_attribute ((__pure__)) |
355 | |
357 | |
356 | /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx __declspec(noreturn) */ |
358 | /* TODO http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx __declspec(noreturn) */ |
357 | #if ECB_C11 |
359 | #if ECB_C11 || __IBMC_NORETURN |
|
|
360 | /* http://pic.dhe.ibm.com/infocenter/compbg/v121v141/topic/com.ibm.xlcpp121.bg.doc/language_ref/noreturn.html */ |
358 | #define ecb_noreturn _Noreturn |
361 | #define ecb_noreturn _Noreturn |
359 | #else |
362 | #else |
360 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
363 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
361 | #endif |
364 | #endif |
362 | |
365 | |
… | |
… | |
667 | #define ECB_NAN NAN |
670 | #define ECB_NAN NAN |
668 | #else |
671 | #else |
669 | #define ECB_NAN ECB_INFINITY |
672 | #define ECB_NAN ECB_INFINITY |
670 | #endif |
673 | #endif |
671 | |
674 | |
|
|
675 | #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L |
|
|
676 | #define ecb_ldexpf(x,e) ldexpf ((x), (e)) |
|
|
677 | #else |
|
|
678 | #define ecb_ldexpf(x,e) (float) ldexp ((double)(x), (e)) |
|
|
679 | #endif |
|
|
680 | |
672 | /* converts an ieee half/binary16 to a float */ |
681 | /* converts an ieee half/binary16 to a float */ |
673 | ecb_function_ float ecb_binary16_to_float (uint16_t x) ecb_const; |
682 | ecb_function_ float ecb_binary16_to_float (uint16_t x) ecb_const; |
674 | ecb_function_ float |
683 | ecb_function_ float |
675 | ecb_binary16_to_float (uint16_t x) |
684 | ecb_binary16_to_float (uint16_t x) |
676 | { |
685 | { |
677 | int e = (x >> 10) & 0x1f; |
686 | int e = (x >> 10) & 0x1f; |
678 | int m = x & 0x3ff; |
687 | int m = x & 0x3ff; |
679 | float r; |
688 | float r; |
680 | |
689 | |
681 | if (!e ) r = ldexpf (m , -24); |
690 | if (!e ) r = ecb_ldexpf (m , -24); |
682 | else if (e != 31) r = ldexpf (m + 0x400, e - 25); |
691 | else if (e != 31) r = ecb_ldexpf (m + 0x400, e - 25); |
683 | else if (m ) r = ECB_NAN; |
692 | else if (m ) r = ECB_NAN; |
684 | else r = ECB_INFINITY; |
693 | else r = ECB_INFINITY; |
685 | |
694 | |
686 | return x & 0x8000 ? -r : r; |
695 | return x & 0x8000 ? -r : r; |
687 | } |
696 | } |
… | |
… | |
746 | x |= 0x800000U; |
755 | x |= 0x800000U; |
747 | else |
756 | else |
748 | e = 1; |
757 | e = 1; |
749 | |
758 | |
750 | /* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */ |
759 | /* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */ |
751 | r = ldexpf (x * (0.5f / 0x800000U), e - 126); |
760 | r = ecb_ldexpf (x * (0.5f / 0x800000U), e - 126); |
752 | |
761 | |
753 | r = neg ? -r : r; |
762 | r = neg ? -r : r; |
754 | #endif |
763 | #endif |
755 | |
764 | |
756 | return r; |
765 | return r; |