FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mathops.h
Go to the documentation of this file.
1 /*
2  * Simple math operations
3  * Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
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_AVR32_MATHOPS_H
23 #define AVCODEC_AVR32_MATHOPS_H
24 
25 #include <stdint.h>
26 #include "config.h"
27 #include "libavutil/common.h"
28 
29 #if HAVE_INLINE_ASM
30 
31 #define MULL MULL
32 static inline av_const int MULL(int a, int b, unsigned shift)
33 {
34  union { int64_t x; int hl[2]; } x;
35  __asm__ ("muls.d %0, %1, %2 \n\t"
36  "lsr %0, %3 \n\t"
37  "or %0, %0, %m0<<%4 \n\t"
38  : "=r"(x) : "r"(b), "r"(a), "i"(shift), "i"(32-shift));
39  return x.hl[1];
40 }
41 
42 #define MULH MULH
43 static inline av_const int MULH(int a, int b)
44 {
45  union { int64_t x; int hl[2]; } x;
46  __asm__ ("muls.d %0, %1, %2" : "=r"(x.x) : "r"(a), "r"(b));
47  return x.hl[0];
48 }
49 
50 #define MUL64 MUL64
51 static inline av_const int64_t MUL64(int a, int b)
52 {
53  int64_t x;
54  __asm__ ("muls.d %0, %1, %2" : "=r"(x) : "r"(a), "r"(b));
55  return x;
56 }
57 
58 static inline av_const int64_t MAC64(int64_t d, int a, int b)
59 {
60  __asm__ ("macs.d %0, %1, %2" : "+r"(d) : "r"(a), "r"(b));
61  return d;
62 }
63 #define MAC64(d, a, b) ((d) = MAC64(d, a, b))
64 #define MLS64(d, a, b) MAC64(d, -(a), b)
65 
66 static inline av_const int MAC16(int d, int a, int b)
67 {
68  __asm__ ("machh.w %0, %1:b, %2:b" : "+r"(d) : "r"(a), "r"(b));
69  return d;
70 }
71 #define MAC16(d, a, b) ((d) = MAC16(d, a, b))
72 #define MLS16(d, a, b) MAC16(d, -(a), b)
73 
74 #define MUL16 MUL16
75 static inline av_const int MUL16(int a, int b)
76 {
77  int d;
78  __asm__ ("mulhh.w %0, %1:b, %2:b" : "=r"(d) : "r"(a), "r"(b));
79  return d;
80 }
81 
82 #define mid_pred mid_pred
83 static inline av_const int mid_pred(int a, int b, int c)
84 {
85  int m;
86  __asm__ ("mov %0, %2 \n\t"
87  "cp.w %1, %2 \n\t"
88  "movgt %0, %1 \n\t"
89  "movgt %1, %2 \n\t"
90  "cp.w %1, %3 \n\t"
91  "movle %1, %3 \n\t"
92  "cp.w %0, %1 \n\t"
93  "movgt %0, %1 \n\t"
94  : "=&r"(m), "+r"(a)
95  : "r"(b), "r"(c));
96  return m;
97 }
98 
99 #endif /* HAVE_INLINE_ASM */
100 
101 #endif /* AVCODEC_AVR32_MATHOPS_H */
#define MUL64(a, b)
Definition: mathops.h:52
#define av_const
Definition: attributes.h:76
static int shift(int a, int b)
Definition: sonic.c:82
const char * b
Definition: vf_curves.c:109
unsigned m
Definition: audioconvert.c:187
#define MUL16(ra, rb)
Definition: mathops.h:86
#define MAC16(rt, ra, rb)
Definition: mathops.h:81
#define mid_pred
Definition: mathops.h:95
common internal and external API header
static double c[64]
#define MULL(a, b, s)
Definition: mathops.h:56
#define MAC64(d, a, b)
Definition: mathops.h:72
#define MULH
Definition: mathops.h:42