… | |
… | |
44 | /* 16 bits major, 16 bits minor */ |
44 | /* 16 bits major, 16 bits minor */ |
45 | #define ECB_VERSION 0x00010008 |
45 | #define ECB_VERSION 0x00010008 |
46 | |
46 | |
47 | #include <string.h> /* for memcpy */ |
47 | #include <string.h> /* for memcpy */ |
48 | |
48 | |
49 | #ifdef _WIN32 |
49 | #if defined (_WIN32) && !defined (__MINGW32__) |
50 | typedef signed char int8_t; |
50 | typedef signed char int8_t; |
51 | typedef unsigned char uint8_t; |
51 | typedef unsigned char uint8_t; |
52 | typedef signed char int_fast8_t; |
52 | typedef signed char int_fast8_t; |
53 | typedef unsigned char uint_fast8_t; |
53 | typedef unsigned char uint_fast8_t; |
54 | typedef signed short int16_t; |
54 | typedef signed short int16_t; |
… | |
… | |
799 | template<typename T> inline void ecb_poke_le_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_le (v)); } |
799 | template<typename T> inline void ecb_poke_le_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_le (v)); } |
800 | |
800 | |
801 | #endif |
801 | #endif |
802 | |
802 | |
803 | /*****************************************************************************/ |
803 | /*****************************************************************************/ |
|
|
804 | /* division */ |
804 | |
805 | |
805 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
806 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
|
|
807 | /* C99 tightened the definition of %, so we can use a more efficient version */ |
806 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
808 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
807 | #else |
809 | #else |
808 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
810 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
809 | #endif |
811 | #endif |
810 | |
812 | |
… | |
… | |
821 | } |
823 | } |
822 | #else |
824 | #else |
823 | #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div)) |
825 | #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div)) |
824 | #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div)) |
826 | #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div)) |
825 | #endif |
827 | #endif |
|
|
828 | |
|
|
829 | /*****************************************************************************/ |
|
|
830 | /* array length */ |
826 | |
831 | |
827 | #if ecb_cplusplus_does_not_suck |
832 | #if ecb_cplusplus_does_not_suck |
828 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
833 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
829 | template<typename T, int N> |
834 | template<typename T, int N> |
830 | static inline int ecb_array_length (const T (&arr)[N]) |
835 | static inline int ecb_array_length (const T (&arr)[N]) |
… | |
… | |
834 | #else |
839 | #else |
835 | #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
840 | #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
836 | #endif |
841 | #endif |
837 | |
842 | |
838 | /*****************************************************************************/ |
843 | /*****************************************************************************/ |
|
|
844 | /* IEEE 754-2008 half float conversions */ |
839 | |
845 | |
840 | ecb_function_ ecb_const uint32_t ecb_binary16_to_binary32 (uint32_t x); |
846 | ecb_function_ ecb_const uint32_t ecb_binary16_to_binary32 (uint32_t x); |
841 | ecb_function_ ecb_const uint32_t |
847 | ecb_function_ ecb_const uint32_t |
842 | ecb_binary16_to_binary32 (uint32_t x) |
848 | ecb_binary16_to_binary32 (uint32_t x) |
843 | { |
849 | { |
… | |
… | |
872 | ecb_function_ ecb_const uint16_t ecb_binary32_to_binary16 (uint32_t x); |
878 | ecb_function_ ecb_const uint16_t ecb_binary32_to_binary16 (uint32_t x); |
873 | ecb_function_ ecb_const uint16_t |
879 | ecb_function_ ecb_const uint16_t |
874 | ecb_binary32_to_binary16 (uint32_t x) |
880 | ecb_binary32_to_binary16 (uint32_t x) |
875 | { |
881 | { |
876 | unsigned int s = (x >> 16) & 0x00008000; /* sign bit, the easy part */ |
882 | unsigned int s = (x >> 16) & 0x00008000; /* sign bit, the easy part */ |
877 | unsigned int e = ((x >> 23) & 0x000000ff) - (127 - 15); /* the desired exponent */ |
883 | int e = ((x >> 23) & 0x000000ff) - (127 - 15); /* the desired exponent */ |
878 | unsigned int m = x & 0x007fffff; |
884 | unsigned int m = x & 0x007fffff; |
879 | |
885 | |
880 | x &= 0x7fffffff; |
886 | x &= 0x7fffffff; |
881 | |
887 | |
882 | /* if it's within range of binary16 normals, use fast path */ |
888 | /* if it's within range of binary16 normals, use fast path */ |