Path: blob/a-new-beginning/libavcodec.xcframework/ios-arm64/libavcodec.framework/Headers/mathops.h
2 views
/*1* simple math operations2* Copyright (c) 2001, 2002 Fabrice Bellard3* Copyright (c) 2006 Michael Niedermayer <[email protected]> et al4*5* This file is part of FFmpeg.6*7* FFmpeg is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* FFmpeg is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* You should have received a copy of the GNU Lesser General Public18* License along with FFmpeg; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20*/21#ifndef AVCODEC_MATHOPS_H22#define AVCODEC_MATHOPS_H2324#include <stdint.h>2526#include "libavutil/attributes_internal.h"27#include "libavutil/common.h"28#include "config.h"2930#define MAX_NEG_CROP 10243132extern const uint32_t ff_inverse[257];33extern const uint8_t ff_log2_run[41];34extern const uint8_t ff_sqrt_tab[256];35extern const uint8_t attribute_visibility_hidden ff_crop_tab[256 + 2 * MAX_NEG_CROP];36extern const uint8_t ff_zigzag_direct[64];37extern const uint8_t ff_zigzag_scan[16+1];3839#if ARCH_ARM40# include "arm/mathops.h"41#elif ARCH_AVR3242# include "avr32/mathops.h"43#elif ARCH_MIPS44# include "mips/mathops.h"45#elif ARCH_PPC46# include "ppc/mathops.h"47#elif ARCH_X8648# include "x86/mathops.h"49#endif5051/* generic implementation */5253#ifndef MUL6454# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))55#endif5657#ifndef MULL58# define MULL(a,b,s) (MUL64(a, b) >> (s))59#endif6061#ifndef MULH62static av_always_inline int MULH(int a, int b){63return MUL64(a, b) >> 32;64}65#endif6667#ifndef UMULH68static av_always_inline unsigned UMULH(unsigned a, unsigned b){69return ((uint64_t)(a) * (uint64_t)(b))>>32;70}71#endif7273#ifndef MAC6474# define MAC64(d, a, b) ((d) += MUL64(a, b))75#endif7677#ifndef MLS6478# define MLS64(d, a, b) ((d) -= MUL64(a, b))79#endif8081/* signed 16x16 -> 32 multiply add accumulate */82#ifndef MAC1683# define MAC16(rt, ra, rb) rt += (ra) * (rb)84#endif8586/* signed 16x16 -> 32 multiply */87#ifndef MUL1688# define MUL16(ra, rb) ((ra) * (rb))89#endif9091#ifndef MLS1692# define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))93#endif9495/* median of 3 */96#ifndef mid_pred97#define mid_pred mid_pred98static inline av_const int mid_pred(int a, int b, int c)99{100if(a>b){101if(c>b){102if(c>a) b=a;103else b=c;104}105}else{106if(b>c){107if(c>a) b=c;108else b=a;109}110}111return b;112}113#endif114115#ifndef median4116#define median4 median4117static inline av_const int median4(int a, int b, int c, int d)118{119if (a < b) {120if (c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;121else return (FFMIN(b, c) + FFMAX(a, d)) / 2;122} else {123if (c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;124else return (FFMIN(a, c) + FFMAX(b, d)) / 2;125}126}127#endif128129#define FF_SIGNBIT(x) ((x) >> CHAR_BIT * sizeof(x) - 1)130131#ifndef sign_extend132static inline av_const int sign_extend(int val, unsigned bits)133{134unsigned shift = 8 * sizeof(int) - bits;135union { unsigned u; int s; } v = { (unsigned) val << shift };136return v.s >> shift;137}138#endif139140#ifndef sign_extend64141static inline av_const int64_t sign_extend64(int64_t val, unsigned bits)142{143unsigned shift = 8 * sizeof(int64_t) - bits;144union { uint64_t u; int64_t s; } v = { (uint64_t) val << shift };145return v.s >> shift;146}147#endif148149#ifndef zero_extend150static inline av_const unsigned zero_extend(unsigned val, unsigned bits)151{152return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);153}154#endif155156#ifndef COPY3_IF_LT157#define COPY3_IF_LT(x, y, a, b, c, d)\158if ((y) < (x)) {\159(x) = (y);\160(a) = (b);\161(c) = (d);\162}163#endif164165#ifndef MASK_ABS166#define MASK_ABS(mask, level) do { \167mask = level >> 31; \168level = (level ^ mask) - mask; \169} while (0)170#endif171172#ifndef NEG_SSR32173# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))174#endif175176#ifndef NEG_USR32177# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))178#endif179180#if HAVE_BIGENDIAN181# ifndef PACK_2U8182# define PACK_2U8(a,b) (((a) << 8) | (b))183# endif184# ifndef PACK_4U8185# define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))186# endif187# ifndef PACK_2U16188# define PACK_2U16(a,b) (((a) << 16) | (b))189# endif190#else191# ifndef PACK_2U8192# define PACK_2U8(a,b) (((b) << 8) | (a))193# endif194# ifndef PACK_4U2195# define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))196# endif197# ifndef PACK_2U16198# define PACK_2U16(a,b) (((b) << 16) | (a))199# endif200#endif201202#ifndef PACK_2S8203# define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255)204#endif205#ifndef PACK_4S8206# define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255)207#endif208#ifndef PACK_2S16209# define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff)210#endif211212#ifndef FASTDIV213# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))214#endif /* FASTDIV */215216#ifndef ff_sqrt217#define ff_sqrt ff_sqrt218static inline av_const unsigned int ff_sqrt(unsigned int a)219{220unsigned int b;221222if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;223else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;224#if !CONFIG_SMALL225else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;226else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8] ;227#endif228else {229int s = av_log2_16bit(a >> 16) >> 1;230unsigned int c = a >> (s + 2);231b = ff_sqrt_tab[c >> (s + 8)];232b = FASTDIV(c,b) + (b << s);233}234235return b - (a < b * b);236}237#endif238239static inline av_const float ff_sqrf(float a)240{241return a*a;242}243244static inline int8_t ff_u8_to_s8(uint8_t a)245{246union {247uint8_t u8;248int8_t s8;249} b;250b.u8 = a;251return b.s8;252}253254#endif /* AVCODEC_MATHOPS_H */255256257