x86/mathops.h
Go to the documentation of this file.
1 /*
2  * simple math operations
3  * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * 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 of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_X86_MATHOPS_H
23 #define AVCODEC_X86_MATHOPS_H
24 
25 #include "config.h"
26 #include "libavutil/common.h"
27 
28 #if HAVE_INLINE_ASM
29 
30 #if ARCH_X86_32
31 
32 #define MULL MULL
33 static av_always_inline av_const int MULL(int a, int b, unsigned shift)
34 {
35  int rt, dummy;
36  __asm__ (
37  "imull %3 \n\t"
38  "shrdl %4, %%edx, %%eax \n\t"
39  :"=a"(rt), "=d"(dummy)
40  :"a"(a), "rm"(b), "ci"((uint8_t)shift)
41  );
42  return rt;
43 }
44 
45 #define MULH MULH
46 static av_always_inline av_const int MULH(int a, int b)
47 {
48  int rt, dummy;
49  __asm__ (
50  "imull %3"
51  :"=d"(rt), "=a"(dummy)
52  :"a"(a), "rm"(b)
53  );
54  return rt;
55 }
56 
57 #define MUL64 MUL64
58 static av_always_inline av_const int64_t MUL64(int a, int b)
59 {
60  int64_t rt;
61  __asm__ (
62  "imull %2"
63  :"=A"(rt)
64  :"a"(a), "rm"(b)
65  );
66  return rt;
67 }
68 
69 #endif /* ARCH_X86_32 */
70 
71 #if HAVE_CMOV
72 /* median of 3 */
73 #define mid_pred mid_pred
74 static inline av_const int mid_pred(int a, int b, int c)
75 {
76  int i=b;
77  __asm__ volatile(
78  "cmp %2, %1 \n\t"
79  "cmovg %1, %0 \n\t"
80  "cmovg %2, %1 \n\t"
81  "cmp %3, %1 \n\t"
82  "cmovl %3, %1 \n\t"
83  "cmp %1, %0 \n\t"
84  "cmovg %1, %0 \n\t"
85  :"+&r"(i), "+&r"(a)
86  :"r"(b), "r"(c)
87  );
88  return i;
89 }
90 #endif
91 
92 #if HAVE_CMOV
93 #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
103 
104 #define MASK_ABS(mask, level) \
105  __asm__ ("cltd \n\t" \
106  "xorl %1, %0 \n\t" \
107  "subl %1, %0 \n\t" \
108  : "+a"(level), "=&d"(mask))
109 
110 // avoid +32 for shift optimization (gcc should do that ...)
111 #define NEG_SSR32 NEG_SSR32
112 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
113  __asm__ ("sarl %1, %0\n\t"
114  : "+r" (a)
115  : "ic" ((uint8_t)(-s))
116  );
117  return a;
118 }
119 
120 #define NEG_USR32 NEG_USR32
121 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
122  __asm__ ("shrl %1, %0\n\t"
123  : "+r" (a)
124  : "ic" ((uint8_t)(-s))
125  );
126  return a;
127 }
128 
129 #endif /* HAVE_INLINE_ASM */
130 #endif /* AVCODEC_X86_MATHOPS_H */
#define MUL64(a, b)
Definition: mathops.h:51
#define av_const
Definition: attributes.h:72
const char * s
Definition: avisynth_c.h:668
static int shift(int a, int b)
Definition: sonic.c:86
uint8_t
#define b
Definition: input.c:42
#define NEG_SSR32(a, s)
Definition: mathops.h:155
#define NEG_USR32(a, s)
Definition: mathops.h:159
int32_t
synthesis window for stochastic i
#define mid_pred
Definition: mathops.h:94
common internal and external API header
static double c[64]
#define MULL(a, b, s)
Definition: mathops.h:55
#define av_always_inline
Definition: attributes.h:41
#define MULH(X, Y)
Definition: bfin/mathops.h:27
int dummy
Definition: motion-test.c:64