Path: blob/a-new-beginning/libavcodec.xcframework/ios-arm64-simulator/libavcodec.framework/Headers/x86/mathops.h
2 views
/*1* simple math operations2* Copyright (c) 2006 Michael Niedermayer <[email protected]> et al3*4* This file is part of FFmpeg.5*6* FFmpeg is free software; you can redistribute it and/or7* modify it under the terms of the GNU Lesser General Public8* License as published by the Free Software Foundation; either9* version 2.1 of the License, or (at your option) any later version.10*11* FFmpeg is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14* Lesser General Public License for more details.15*16* You should have received a copy of the GNU Lesser General Public17* License along with FFmpeg; if not, write to the Free Software18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19*/2021#ifndef AVCODEC_X86_MATHOPS_H22#define AVCODEC_X86_MATHOPS_H2324#include "config.h"2526#include "libavutil/common.h"27#include "libavutil/x86/asm.h"2829#if HAVE_INLINE_ASM3031#if ARCH_X86_323233#define MULL MULL34static av_always_inline av_const int MULL(int a, int b, unsigned shift)35{36int rt, dummy;37__asm__ (38"imull %3 \n\t"39"shrdl %4, %%edx, %%eax \n\t"40:"=a"(rt), "=d"(dummy)41:"a"(a), "rm"(b), "ci"((uint8_t)shift)42);43return rt;44}4546#define MULH MULH47static av_always_inline av_const int MULH(int a, int b)48{49int rt, dummy;50__asm__ (51"imull %3"52:"=d"(rt), "=a"(dummy)53:"a"(a), "rm"(b)54);55return rt;56}5758#define MUL64 MUL6459static av_always_inline av_const int64_t MUL64(int a, int b)60{61int64_t rt;62__asm__ (63"imull %2"64:"=A"(rt)65:"a"(a), "rm"(b)66);67return rt;68}6970#endif /* ARCH_X86_32 */7172#if HAVE_I68673/* median of 3 */74#define mid_pred mid_pred75static inline av_const int mid_pred(int a, int b, int c)76{77int i=b;78__asm__ (79"cmp %2, %1 \n\t"80"cmovg %1, %0 \n\t"81"cmovg %2, %1 \n\t"82"cmp %3, %1 \n\t"83"cmovl %3, %1 \n\t"84"cmp %1, %0 \n\t"85"cmovg %1, %0 \n\t"86:"+&r"(i), "+&r"(a)87:"r"(b), "r"(c)88);89return i;90}9192#if HAVE_6REGS93#define COPY3_IF_LT(x, y, a, b, c, d)\94__asm__ volatile(\95"cmpl %0, %3 \n\t"\96"cmovl %3, %0 \n\t"\97"cmovl %4, %1 \n\t"\98"cmovl %5, %2 \n\t"\99: "+&r" (x), "+&r" (a), "+r" (c)\100: "r" (y), "r" (b), "r" (d)\101);102#endif /* HAVE_6REGS */103104#endif /* HAVE_I686 */105106#define MASK_ABS(mask, level) \107__asm__ ("cdq \n\t" \108"xorl %1, %0 \n\t" \109"subl %1, %0 \n\t" \110: "+a"(level), "=&d"(mask))111112// avoid +32 for shift optimization (gcc should do that ...)113#define NEG_SSR32 NEG_SSR32114static inline int32_t NEG_SSR32( int32_t a, int8_t s){115__asm__ ("sarl %1, %0\n\t"116: "+r" (a)117: "ic" ((uint8_t)(-s))118);119return a;120}121122#define NEG_USR32 NEG_USR32123static inline uint32_t NEG_USR32(uint32_t a, int8_t s){124__asm__ ("shrl %1, %0\n\t"125: "+r" (a)126: "ic" ((uint8_t)(-s))127);128return a;129}130131#endif /* HAVE_INLINE_ASM */132#endif /* AVCODEC_X86_MATHOPS_H */133134135