Libav
|
00001 /* 00002 * simple math operations 00003 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef AVCODEC_X86_MATHOPS_H 00023 #define AVCODEC_X86_MATHOPS_H 00024 00025 #include "config.h" 00026 #include "libavutil/common.h" 00027 00028 #if ARCH_X86_32 00029 #define MULL(ra, rb, shift) \ 00030 ({ int rt, dummy; __asm__ (\ 00031 "imull %3 \n\t"\ 00032 "shrdl %4, %%edx, %%eax \n\t"\ 00033 : "=a"(rt), "=d"(dummy)\ 00034 : "a" ((int)(ra)), "rm" ((int)(rb)), "i"(shift));\ 00035 rt; }) 00036 00037 #define MULH(ra, rb) \ 00038 ({ int rt, dummy;\ 00039 __asm__ ("imull %3\n\t" : "=d"(rt), "=a"(dummy): "a" ((int)(ra)), "rm" ((int)(rb)));\ 00040 rt; }) 00041 00042 #define MUL64(ra, rb) \ 00043 ({ int64_t rt;\ 00044 __asm__ ("imull %2\n\t" : "=A"(rt) : "a" ((int)(ra)), "g" ((int)(rb)));\ 00045 rt; }) 00046 #endif 00047 00048 #if HAVE_CMOV 00049 /* median of 3 */ 00050 #define mid_pred mid_pred 00051 static inline av_const int mid_pred(int a, int b, int c) 00052 { 00053 int i=b; 00054 __asm__ volatile( 00055 "cmp %2, %1 \n\t" 00056 "cmovg %1, %0 \n\t" 00057 "cmovg %2, %1 \n\t" 00058 "cmp %3, %1 \n\t" 00059 "cmovl %3, %1 \n\t" 00060 "cmp %1, %0 \n\t" 00061 "cmovg %1, %0 \n\t" 00062 :"+&r"(i), "+&r"(a) 00063 :"r"(b), "r"(c) 00064 ); 00065 return i; 00066 } 00067 #endif 00068 00069 #if HAVE_CMOV 00070 #define COPY3_IF_LT(x, y, a, b, c, d)\ 00071 __asm__ volatile(\ 00072 "cmpl %0, %3 \n\t"\ 00073 "cmovl %3, %0 \n\t"\ 00074 "cmovl %4, %1 \n\t"\ 00075 "cmovl %5, %2 \n\t"\ 00076 : "+&r" (x), "+&r" (a), "+r" (c)\ 00077 : "r" (y), "r" (b), "r" (d)\ 00078 ); 00079 #endif 00080 00081 // avoid +32 for shift optimization (gcc should do that ...) 00082 #define NEG_SSR32 NEG_SSR32 00083 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ 00084 __asm__ ("sarl %1, %0\n\t" 00085 : "+r" (a) 00086 : "ic" ((uint8_t)(-s)) 00087 ); 00088 return a; 00089 } 00090 00091 #define NEG_USR32 NEG_USR32 00092 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ 00093 __asm__ ("shrl %1, %0\n\t" 00094 : "+r" (a) 00095 : "ic" ((uint8_t)(-s)) 00096 ); 00097 return a; 00098 } 00099 00100 #endif /* AVCODEC_X86_MATHOPS_H */