1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/ecintrin.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* Copyright (c) 2003-2008 Timothy B. Terriberry 1.5 + Copyright (c) 2008 Xiph.Org Foundation */ 1.6 +/* 1.7 + Redistribution and use in source and binary forms, with or without 1.8 + modification, are permitted provided that the following conditions 1.9 + are met: 1.10 + 1.11 + - Redistributions of source code must retain the above copyright 1.12 + notice, this list of conditions and the following disclaimer. 1.13 + 1.14 + - Redistributions in binary form must reproduce the above copyright 1.15 + notice, this list of conditions and the following disclaimer in the 1.16 + documentation and/or other materials provided with the distribution. 1.17 + 1.18 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.19 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.20 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.21 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 1.22 + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.23 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.24 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.25 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.26 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.27 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.28 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.29 +*/ 1.30 + 1.31 +/*Some common macros for potential platform-specific optimization.*/ 1.32 +#include "opus_types.h" 1.33 +#include <math.h> 1.34 +#include <limits.h> 1.35 +#include "arch.h" 1.36 +#if !defined(_ecintrin_H) 1.37 +# define _ecintrin_H (1) 1.38 + 1.39 +/*Some specific platforms may have optimized intrinsic or OPUS_INLINE assembly 1.40 + versions of these functions which can substantially improve performance. 1.41 + We define macros for them to allow easy incorporation of these non-ANSI 1.42 + features.*/ 1.43 + 1.44 +/*Modern gcc (4.x) can compile the naive versions of min and max with cmov if 1.45 + given an appropriate architecture, but the branchless bit-twiddling versions 1.46 + are just as fast, and do not require any special target architecture. 1.47 + Earlier gcc versions (3.x) compiled both code to the same assembly 1.48 + instructions, because of the way they represented ((_b)>(_a)) internally.*/ 1.49 +# define EC_MINI(_a,_b) ((_a)+(((_b)-(_a))&-((_b)<(_a)))) 1.50 + 1.51 +/*Count leading zeros. 1.52 + This macro should only be used for implementing ec_ilog(), if it is defined. 1.53 + All other code should use EC_ILOG() instead.*/ 1.54 +#if defined(_MSC_VER) && (_MSC_VER >= 1400) 1.55 +# include <intrin.h> 1.56 +/*In _DEBUG mode this is not an intrinsic by default.*/ 1.57 +# pragma intrinsic(_BitScanReverse) 1.58 + 1.59 +static __inline int ec_bsr(unsigned long _x){ 1.60 + unsigned long ret; 1.61 + _BitScanReverse(&ret,_x); 1.62 + return (int)ret; 1.63 +} 1.64 +# define EC_CLZ0 (1) 1.65 +# define EC_CLZ(_x) (-ec_bsr(_x)) 1.66 +#elif defined(ENABLE_TI_DSPLIB) 1.67 +# include "dsplib.h" 1.68 +# define EC_CLZ0 (31) 1.69 +# define EC_CLZ(_x) (_lnorm(_x)) 1.70 +#elif __GNUC_PREREQ(3,4) 1.71 +# if INT_MAX>=2147483647 1.72 +# define EC_CLZ0 ((int)sizeof(unsigned)*CHAR_BIT) 1.73 +# define EC_CLZ(_x) (__builtin_clz(_x)) 1.74 +# elif LONG_MAX>=2147483647L 1.75 +# define EC_CLZ0 ((int)sizeof(unsigned long)*CHAR_BIT) 1.76 +# define EC_CLZ(_x) (__builtin_clzl(_x)) 1.77 +# endif 1.78 +#endif 1.79 + 1.80 +#if defined(EC_CLZ) 1.81 +/*Note that __builtin_clz is not defined when _x==0, according to the gcc 1.82 + documentation (and that of the BSR instruction that implements it on x86). 1.83 + The majority of the time we can never pass it zero. 1.84 + When we need to, it can be special cased.*/ 1.85 +# define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x)) 1.86 +#else 1.87 +int ec_ilog(opus_uint32 _v); 1.88 +# define EC_ILOG(_x) (ec_ilog(_x)) 1.89 +#endif 1.90 +#endif