2 * Simple math operations
3 * Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
5 * This file is part of Libav.
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.
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.
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
22 #ifndef AVCODEC_AVR32_MATHOPS_H
23 #define AVCODEC_AVR32_MATHOPS_H
27 #include "libavutil/common.h"
32 static inline av_const
int MULL(int a
, int b
, unsigned shift
)
34 union { int64_t x
; int hl
[2]; } x
;
35 __asm__ ("muls.d %0, %1, %2 \n\t"
37 "or %0, %0, %m0<<%4 \n\t"
38 : "=r"(x
) : "r"(b
), "r"(a
), "i"(shift
), "i"(32-shift
));
43 static inline av_const
int MULH(int a
, int b
)
45 union { int64_t x
; int hl
[2]; } x
;
46 __asm__ ("muls.d %0, %1, %2" : "=r"(x
.x
) : "r"(a
), "r"(b
));
51 static inline av_const
int64_t MUL64(int a
, int b
)
54 __asm__ ("muls.d %0, %1, %2" : "=r"(x
) : "r"(a
), "r"(b
));
58 static inline av_const
int64_t MAC64(int64_t d
, int a
, int b
)
60 __asm__ ("macs.d %0, %1, %2" : "+r"(d
) : "r"(a
), "r"(b
));
63 #define MAC64(d, a, b) ((d) = MAC64(d, a, b))
64 #define MLS64(d, a, b) MAC64(d, -(a), b)
66 static inline av_const
int MAC16(int d
, int a
, int b
)
68 __asm__ ("machh.w %0, %1:b, %2:b" : "+r"(d
) : "r"(a
), "r"(b
));
71 #define MAC16(d, a, b) ((d) = MAC16(d, a, b))
72 #define MLS16(d, a, b) MAC16(d, -(a), b)
75 static inline av_const
int MUL16(int a
, int b
)
78 __asm__ ("mulhh.w %0, %1:b, %2:b" : "=r"(d
) : "r"(a
), "r"(b
));
82 #define mid_pred mid_pred
83 static inline av_const
int mid_pred(int a
, int b
, int c
)
86 __asm__ ("mov %0, %2 \n\t"
99 #endif /* HAVE_INLINE_ASM */
101 #endif /* AVCODEC_AVR32_MATHOPS_H */