annotate src/opus-1.3/celt/ecintrin.h @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /* Copyright (c) 2003-2008 Timothy B. Terriberry
cannam@154 2 Copyright (c) 2008 Xiph.Org Foundation */
cannam@154 3 /*
cannam@154 4 Redistribution and use in source and binary forms, with or without
cannam@154 5 modification, are permitted provided that the following conditions
cannam@154 6 are met:
cannam@154 7
cannam@154 8 - Redistributions of source code must retain the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer.
cannam@154 10
cannam@154 11 - Redistributions in binary form must reproduce the above copyright
cannam@154 12 notice, this list of conditions and the following disclaimer in the
cannam@154 13 documentation and/or other materials provided with the distribution.
cannam@154 14
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
cannam@154 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
cannam@154 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
cannam@154 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
cannam@154 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
cannam@154 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
cannam@154 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
cannam@154 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
cannam@154 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
cannam@154 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
cannam@154 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 */
cannam@154 27
cannam@154 28 /*Some common macros for potential platform-specific optimization.*/
cannam@154 29 #include "opus_types.h"
cannam@154 30 #include <math.h>
cannam@154 31 #include <limits.h>
cannam@154 32 #include "arch.h"
cannam@154 33 #if !defined(_ecintrin_H)
cannam@154 34 # define _ecintrin_H (1)
cannam@154 35
cannam@154 36 /*Some specific platforms may have optimized intrinsic or OPUS_INLINE assembly
cannam@154 37 versions of these functions which can substantially improve performance.
cannam@154 38 We define macros for them to allow easy incorporation of these non-ANSI
cannam@154 39 features.*/
cannam@154 40
cannam@154 41 /*Modern gcc (4.x) can compile the naive versions of min and max with cmov if
cannam@154 42 given an appropriate architecture, but the branchless bit-twiddling versions
cannam@154 43 are just as fast, and do not require any special target architecture.
cannam@154 44 Earlier gcc versions (3.x) compiled both code to the same assembly
cannam@154 45 instructions, because of the way they represented ((_b)>(_a)) internally.*/
cannam@154 46 # define EC_MINI(_a,_b) ((_a)+(((_b)-(_a))&-((_b)<(_a))))
cannam@154 47
cannam@154 48 /*Count leading zeros.
cannam@154 49 This macro should only be used for implementing ec_ilog(), if it is defined.
cannam@154 50 All other code should use EC_ILOG() instead.*/
cannam@154 51 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
cannam@154 52 # include <intrin.h>
cannam@154 53 /*In _DEBUG mode this is not an intrinsic by default.*/
cannam@154 54 # pragma intrinsic(_BitScanReverse)
cannam@154 55
cannam@154 56 static __inline int ec_bsr(unsigned long _x){
cannam@154 57 unsigned long ret;
cannam@154 58 _BitScanReverse(&ret,_x);
cannam@154 59 return (int)ret;
cannam@154 60 }
cannam@154 61 # define EC_CLZ0 (1)
cannam@154 62 # define EC_CLZ(_x) (-ec_bsr(_x))
cannam@154 63 #elif defined(ENABLE_TI_DSPLIB)
cannam@154 64 # include "dsplib.h"
cannam@154 65 # define EC_CLZ0 (31)
cannam@154 66 # define EC_CLZ(_x) (_lnorm(_x))
cannam@154 67 #elif __GNUC_PREREQ(3,4)
cannam@154 68 # if INT_MAX>=2147483647
cannam@154 69 # define EC_CLZ0 ((int)sizeof(unsigned)*CHAR_BIT)
cannam@154 70 # define EC_CLZ(_x) (__builtin_clz(_x))
cannam@154 71 # elif LONG_MAX>=2147483647L
cannam@154 72 # define EC_CLZ0 ((int)sizeof(unsigned long)*CHAR_BIT)
cannam@154 73 # define EC_CLZ(_x) (__builtin_clzl(_x))
cannam@154 74 # endif
cannam@154 75 #endif
cannam@154 76
cannam@154 77 #if defined(EC_CLZ)
cannam@154 78 /*Note that __builtin_clz is not defined when _x==0, according to the gcc
cannam@154 79 documentation (and that of the BSR instruction that implements it on x86).
cannam@154 80 The majority of the time we can never pass it zero.
cannam@154 81 When we need to, it can be special cased.*/
cannam@154 82 # define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x))
cannam@154 83 #else
cannam@154 84 int ec_ilog(opus_uint32 _v);
cannam@154 85 # define EC_ILOG(_x) (ec_ilog(_x))
cannam@154 86 #endif
cannam@154 87 #endif