media/libopus/celt/ecintrin.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial