mathops/x86: work around inline asm miscompilation with GCC 4.8.1
[platform/upstream/libav.git] / libavcodec / x86 / mathops.h
1 /*
2  * simple math operations
3  * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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_I686
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__ (
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
91 #define COPY3_IF_LT(x, y, a, b, c, d)\
92 __asm__ volatile(\
93     "cmpl  %0, %3       \n\t"\
94     "cmovl %3, %0       \n\t"\
95     "cmovl %4, %1       \n\t"\
96     "cmovl %5, %2       \n\t"\
97     : "+&r" (x), "+&r" (a), "+r" (c)\
98     : "r" (y), "r" (b), "r" (d)\
99 );
100 #endif /* HAVE_I686 */
101
102 #define MASK_ABS(mask, level)                   \
103     __asm__ ("cltd                   \n\t"      \
104              "xorl %1, %0            \n\t"      \
105              "subl %1, %0            \n\t"      \
106              : "+a"(level), "=&d"(mask))
107
108 // avoid +32 for shift optimization (gcc should do that ...)
109 #define NEG_SSR32 NEG_SSR32
110 static inline  int32_t NEG_SSR32( int32_t a, int8_t s){
111     __asm__ ("sarl %1, %0\n\t"
112          : "+r" (a)
113          : "ic" ((uint8_t)(-s))
114     );
115     return a;
116 }
117
118 #define NEG_USR32 NEG_USR32
119 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
120     __asm__ ("shrl %1, %0\n\t"
121          : "+r" (a)
122          : "ic" ((uint8_t)(-s))
123     );
124     return a;
125 }
126
127 #endif /* HAVE_INLINE_ASM */
128 #endif /* AVCODEC_X86_MATHOPS_H */