2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVUTIL_ARM_INTMATH_H
22 #define AVUTIL_ARM_INTMATH_H
27 #include "libavutil/attributes.h"
33 #define FASTDIV FASTDIV
34 static av_always_inline av_const int FASTDIV(int a, int b)
37 __asm__ ("cmp %2, #2 \n\t"
38 "ldr %0, [%3, %2, lsl #2] \n\t"
40 "lsrle %0, %1, #1 \n\t"
41 "smmulgt %0, %0, %1 \n\t"
42 : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc");
46 #define av_clip_uint8 av_clip_uint8_arm
47 static av_always_inline av_const uint8_t av_clip_uint8_arm(int a)
50 __asm__ ("usat %0, #8, %1" : "=r"(x) : "r"(a));
54 #define av_clip_int8 av_clip_int8_arm
55 static av_always_inline av_const uint8_t av_clip_int8_arm(int a)
58 __asm__ ("ssat %0, #8, %1" : "=r"(x) : "r"(a));
62 #define av_clip_uint16 av_clip_uint16_arm
63 static av_always_inline av_const uint16_t av_clip_uint16_arm(int a)
66 __asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a));
70 #define av_clip_int16 av_clip_int16_arm
71 static av_always_inline av_const int16_t av_clip_int16_arm(int a)
74 __asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
78 #define av_clip_uintp2 av_clip_uintp2_arm
79 static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
82 __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
87 #else /* HAVE_ARMV6 */
89 #define FASTDIV FASTDIV
90 static av_always_inline av_const int FASTDIV(int a, int b)
93 __asm__ ("umull %1, %0, %2, %3"
94 : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
98 #endif /* HAVE_ARMV6 */
100 #define av_clipl_int32 av_clipl_int32_arm
101 static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
104 __asm__ ("adds %1, %R2, %Q2, lsr #31 \n\t"
106 "mvnne %1, #1<<31 \n\t"
108 "eorne %0, %1, %R2, asr #31 \n\t"
109 : "=r"(x), "=&r"(y) : "r"(a));
113 #endif /* HAVE_INLINE_ASM */
115 #endif /* AVUTIL_ARM_INTMATH_H */