1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libtheora/lib/mathops.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +#if !defined(_mathops_H) 1.5 +# define _mathops_H (1) 1.6 +# include <ogg/ogg.h> 1.7 + 1.8 +# if __GNUC_PREREQ(3,4) 1.9 +# include <limits.h> 1.10 +/*Note the casts to (int) below: this prevents OC_CLZ{32|64}_OFFS from 1.11 + "upgrading" the type of an entire expression to an (unsigned) size_t.*/ 1.12 +# if INT_MAX>=2147483647 1.13 +# define OC_CLZ32_OFFS ((int)sizeof(unsigned)*CHAR_BIT) 1.14 +# define OC_CLZ32(_x) (__builtin_clz(_x)) 1.15 +# elif LONG_MAX>=2147483647L 1.16 +# define OC_CLZ32_OFFS ((int)sizeof(unsigned long)*CHAR_BIT) 1.17 +# define OC_CLZ32(_x) (__builtin_clzl(_x)) 1.18 +# endif 1.19 +# if INT_MAX>=9223372036854775807LL 1.20 +# define OC_CLZ64_OFFS ((int)sizeof(unsigned)*CHAR_BIT) 1.21 +# define OC_CLZ64(_x) (__builtin_clz(_x)) 1.22 +# elif LONG_MAX>=9223372036854775807LL 1.23 +# define OC_CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT) 1.24 +# define OC_CLZ64(_x) (__builtin_clzl(_x)) 1.25 +# elif LLONG_MAX>=9223372036854775807LL|| \ 1.26 + __LONG_LONG_MAX__>=9223372036854775807LL 1.27 +# define OC_CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT) 1.28 +# define OC_CLZ64(_x) (__builtin_clzll(_x)) 1.29 +# endif 1.30 +# endif 1.31 + 1.32 + 1.33 + 1.34 +/** 1.35 + * oc_ilog32 - Integer binary logarithm of a 32-bit value. 1.36 + * @_v: A 32-bit value. 1.37 + * Returns floor(log2(_v))+1, or 0 if _v==0. 1.38 + * This is the number of bits that would be required to represent _v in two's 1.39 + * complement notation with all of the leading zeros stripped. 1.40 + * The OC_ILOG_32() or OC_ILOGNZ_32() macros may be able to use a builtin 1.41 + * function instead, which should be faster. 1.42 + */ 1.43 +int oc_ilog32(ogg_uint32_t _v); 1.44 +/** 1.45 + * oc_ilog64 - Integer binary logarithm of a 64-bit value. 1.46 + * @_v: A 64-bit value. 1.47 + * Returns floor(log2(_v))+1, or 0 if _v==0. 1.48 + * This is the number of bits that would be required to represent _v in two's 1.49 + * complement notation with all of the leading zeros stripped. 1.50 + * The OC_ILOG_64() or OC_ILOGNZ_64() macros may be able to use a builtin 1.51 + * function instead, which should be faster. 1.52 + */ 1.53 +int oc_ilog64(ogg_int64_t _v); 1.54 + 1.55 + 1.56 +# if defined(OC_CLZ32) 1.57 +/** 1.58 + * OC_ILOGNZ_32 - Integer binary logarithm of a non-zero 32-bit value. 1.59 + * @_v: A non-zero 32-bit value. 1.60 + * Returns floor(log2(_v))+1. 1.61 + * This is the number of bits that would be required to represent _v in two's 1.62 + * complement notation with all of the leading zeros stripped. 1.63 + * If _v is zero, the return value is undefined; use OC_ILOG_32() instead. 1.64 + */ 1.65 +# define OC_ILOGNZ_32(_v) (OC_CLZ32_OFFS-OC_CLZ32(_v)) 1.66 +/** 1.67 + * OC_ILOG_32 - Integer binary logarithm of a 32-bit value. 1.68 + * @_v: A 32-bit value. 1.69 + * Returns floor(log2(_v))+1, or 0 if _v==0. 1.70 + * This is the number of bits that would be required to represent _v in two's 1.71 + * complement notation with all of the leading zeros stripped. 1.72 + */ 1.73 +# define OC_ILOG_32(_v) (OC_ILOGNZ_32(_v)&-!!(_v)) 1.74 +# else 1.75 +# define OC_ILOGNZ_32(_v) (oc_ilog32(_v)) 1.76 +# define OC_ILOG_32(_v) (oc_ilog32(_v)) 1.77 +# endif 1.78 + 1.79 +# if defined(CLZ64) 1.80 +/** 1.81 + * OC_ILOGNZ_64 - Integer binary logarithm of a non-zero 64-bit value. 1.82 + * @_v: A non-zero 64-bit value. 1.83 + * Returns floor(log2(_v))+1. 1.84 + * This is the number of bits that would be required to represent _v in two's 1.85 + * complement notation with all of the leading zeros stripped. 1.86 + * If _v is zero, the return value is undefined; use OC_ILOG_64() instead. 1.87 + */ 1.88 +# define OC_ILOGNZ_64(_v) (CLZ64_OFFS-CLZ64(_v)) 1.89 +/** 1.90 + * OC_ILOG_64 - Integer binary logarithm of a 64-bit value. 1.91 + * @_v: A 64-bit value. 1.92 + * Returns floor(log2(_v))+1, or 0 if _v==0. 1.93 + * This is the number of bits that would be required to represent _v in two's 1.94 + * complement notation with all of the leading zeros stripped. 1.95 + */ 1.96 +# define OC_ILOG_64(_v) (OC_ILOGNZ_64(_v)&-!!(_v)) 1.97 +# else 1.98 +# define OC_ILOGNZ_64(_v) (oc_ilog64(_v)) 1.99 +# define OC_ILOG_64(_v) (oc_ilog64(_v)) 1.100 +# endif 1.101 + 1.102 +# define OC_STATIC_ILOG0(_v) (!!(_v)) 1.103 +# define OC_STATIC_ILOG1(_v) (((_v)&0x2)?2:OC_STATIC_ILOG0(_v)) 1.104 +# define OC_STATIC_ILOG2(_v) \ 1.105 + (((_v)&0xC)?2+OC_STATIC_ILOG1((_v)>>2):OC_STATIC_ILOG1(_v)) 1.106 +# define OC_STATIC_ILOG3(_v) \ 1.107 + (((_v)&0xF0)?4+OC_STATIC_ILOG2((_v)>>4):OC_STATIC_ILOG2(_v)) 1.108 +# define OC_STATIC_ILOG4(_v) \ 1.109 + (((_v)&0xFF00)?8+OC_STATIC_ILOG3((_v)>>8):OC_STATIC_ILOG3(_v)) 1.110 +# define OC_STATIC_ILOG5(_v) \ 1.111 + (((_v)&0xFFFF0000)?16+OC_STATIC_ILOG4((_v)>>16):OC_STATIC_ILOG4(_v)) 1.112 +# define OC_STATIC_ILOG6(_v) \ 1.113 + (((_v)&0xFFFFFFFF00000000ULL)?32+OC_STATIC_ILOG5((_v)>>32):OC_STATIC_ILOG5(_v)) 1.114 +/** 1.115 + * OC_STATIC_ILOG_32 - The integer logarithm of an (unsigned, 32-bit) constant. 1.116 + * @_v: A non-negative 32-bit constant. 1.117 + * Returns floor(log2(_v))+1, or 0 if _v==0. 1.118 + * This is the number of bits that would be required to represent _v in two's 1.119 + * complement notation with all of the leading zeros stripped. 1.120 + * This macro is suitable for evaluation at compile time, but it should not be 1.121 + * used on values that can change at runtime, as it operates via exhaustive 1.122 + * search. 1.123 + */ 1.124 +# define OC_STATIC_ILOG_32(_v) (OC_STATIC_ILOG5((ogg_uint32_t)(_v))) 1.125 +/** 1.126 + * OC_STATIC_ILOG_64 - The integer logarithm of an (unsigned, 64-bit) constant. 1.127 + * @_v: A non-negative 64-bit constant. 1.128 + * Returns floor(log2(_v))+1, or 0 if _v==0. 1.129 + * This is the number of bits that would be required to represent _v in two's 1.130 + * complement notation with all of the leading zeros stripped. 1.131 + * This macro is suitable for evaluation at compile time, but it should not be 1.132 + * used on values that can change at runtime, as it operates via exhaustive 1.133 + * search. 1.134 + */ 1.135 +# define OC_STATIC_ILOG_64(_v) (OC_STATIC_ILOG6((ogg_int64_t)(_v))) 1.136 + 1.137 +#define OC_Q57(_v) ((ogg_int64_t)(_v)<<57) 1.138 +#define OC_Q10(_v) ((_v)<<10) 1.139 + 1.140 +ogg_int64_t oc_bexp64(ogg_int64_t _z); 1.141 +ogg_int64_t oc_blog64(ogg_int64_t _w); 1.142 + 1.143 +ogg_uint32_t oc_bexp32_q10(int _z); 1.144 +int oc_blog32_q10(ogg_uint32_t _w); 1.145 + 1.146 +#endif