FFmpeg
Loading...
Searching...
No Matches
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
27#include "libavutil/common.h"
28
29#if HAVE_INLINE_ASM
30
31#if ARCH_X86_32
32
33#define MULL MULL
34static av_always_inline av_const int MULL(int a, int b, unsigned shift)
35{
36 int rt, dummy;
37 if (__builtin_constant_p(shift))
38 __asm__ (
39 "imull %3 \n\t"
40 "shrdl %4, %%edx, %%eax \n\t"
41 :"=a"(rt), "=d"(dummy)
42 :"a"(a), "rm"(b), "i"(shift & 0x1F)
43 );
44 else
45 __asm__ (
46 "imull %3 \n\t"
47 "shrdl %4, %%edx, %%eax \n\t"
48 :"=a"(rt), "=d"(dummy)
49 :"a"(a), "rm"(b), "c"((uint8_t)shift)
50 );
51 return rt;
52}
53
54#define MULH MULH
55static av_always_inline av_const int MULH(int a, int b)
56{
57 int rt, dummy;
58 __asm__ (
59 "imull %3"
60 :"=d"(rt), "=a"(dummy)
61 :"a"(a), "rm"(b)
62 );
63 return rt;
64}
65
66#define MUL64 MUL64
68{
69 int64_t rt;
70 __asm__ (
71 "imull %2"
72 :"=A"(rt)
73 :"a"(a), "rm"(b)
74 );
75 return rt;
76}
77
78#endif /* ARCH_X86_32 */
79
80#if HAVE_I686
81/* median of 3 */
82#define mid_pred mid_pred
83static inline av_const int mid_pred(int a, int b, int c)
84{
85 int i=b;
86 __asm__ (
87 "cmp %2, %1 \n\t"
88 "cmovg %1, %0 \n\t"
89 "cmovg %2, %1 \n\t"
90 "cmp %3, %1 \n\t"
91 "cmovl %3, %1 \n\t"
92 "cmp %1, %0 \n\t"
93 "cmovg %1, %0 \n\t"
94 :"+&r"(i), "+&r"(a)
95 :"r"(b), "r"(c)
96 );
97 return i;
98}
99
100#if HAVE_X86_6REGS
101#define COPY3_IF_LT(x, y, a, b, c, d)\
102__asm__ volatile(\
103 "cmpl %0, %3 \n\t"\
104 "cmovl %3, %0 \n\t"\
105 "cmovl %4, %1 \n\t"\
106 "cmovl %5, %2 \n\t"\
107 : "+&r" (x), "+&r" (a), "+r" (c)\
108 : "r" (y), "r" (b), "r" (d)\
109);
110#endif /* HAVE_X86_6REGS */
111
112#endif /* HAVE_I686 */
113
114#define MASK_ABS(mask, level) \
115 __asm__ ("cdq \n\t" \
116 "xorl %1, %0 \n\t" \
117 "subl %1, %0 \n\t" \
118 : "+a"(level), "=&d"(mask))
119
120// avoid +32 for shift optimization (gcc should do that ...)
121#define NEG_SSR32 NEG_SSR32
122static inline int32_t NEG_SSR32( int32_t a, int8_t s){
123 if (__builtin_constant_p(s))
124 __asm__ ("sarl %1, %0\n\t"
125 : "+r" (a)
126 : "i" (-s & 0x1F)
127 );
128 else
129 __asm__ ("sarl %1, %0\n\t"
130 : "+r" (a)
131 : "c" ((uint8_t)(-s))
132 );
133 return a;
134}
135
136#define NEG_USR32 NEG_USR32
137static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
138 if (__builtin_constant_p(s))
139 __asm__ ("shrl %1, %0\n\t"
140 : "+r" (a)
141 : "i" (-s & 0x1F)
142 );
143 else
144 __asm__ ("shrl %1, %0\n\t"
145 : "+r" (a)
146 : "c" ((uint8_t)(-s))
147 );
148 return a;
149}
150
151#endif /* HAVE_INLINE_ASM */
152#endif /* AVCODEC_X86_MATHOPS_H */
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
int32_t
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
common internal and external API header
long long int64_t
Definition coverity.c:34
static int dummy
Definition ffplay.c:3754
int a
#define b
Definition input.c:43
static int shift(int a, int b)
Definition bonk.c:261
#define av_always_inline
Definition attributes.h:72
#define av_const
Definition attributes.h:111
#define MULL(a, b, s)
Definition mathops.h:60
#define MUL64(a, b)
Definition mathops.h:56
#define mid_pred
Definition mathops.h:115
#define NEG_SSR32(a, s)
Definition mathops.h:176
#define NEG_USR32(a, s)
Definition mathops.h:180
#define MULH
Definition mathops.h:42
static double c[64]