2010-01-19 23:25:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2010-01-19 23:25:36 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2010-01-19 23:25:36 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2010-01-19 23:25:36 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2010-01-19 23:25:36 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVUTIL_ARM_INTMATH_H
|
|
|
|
#define AVUTIL_ARM_INTMATH_H
|
|
|
|
|
2010-07-07 17:27:51 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2010-01-19 23:25:36 +00:00
|
|
|
#include "config.h"
|
2010-03-09 17:39:19 +00:00
|
|
|
#include "libavutil/attributes.h"
|
2010-01-19 23:25:36 +00:00
|
|
|
|
|
|
|
#if HAVE_INLINE_ASM
|
|
|
|
|
|
|
|
#if HAVE_ARMV6
|
2010-07-07 17:27:48 +00:00
|
|
|
|
|
|
|
#define FASTDIV FASTDIV
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const int FASTDIV(int a, int b)
|
2010-01-19 23:25:36 +00:00
|
|
|
{
|
2011-05-27 20:43:15 +00:00
|
|
|
int r;
|
|
|
|
__asm__ ("cmp %2, #2 \n\t"
|
|
|
|
"ldr %0, [%3, %2, lsl #2] \n\t"
|
|
|
|
"lsrle %0, %1, #1 \n\t"
|
|
|
|
"smmulgt %0, %0, %1 \n\t"
|
|
|
|
: "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc");
|
2010-01-19 23:25:36 +00:00
|
|
|
return r;
|
|
|
|
}
|
2010-07-07 17:27:48 +00:00
|
|
|
|
2010-07-07 17:27:51 +00:00
|
|
|
#define av_clip_uint8 av_clip_uint8_arm
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const uint8_t av_clip_uint8_arm(int a)
|
2010-07-07 17:27:51 +00:00
|
|
|
{
|
|
|
|
unsigned x;
|
2011-05-24 14:45:50 +00:00
|
|
|
__asm__ ("usat %0, #8, %1" : "=r"(x) : "r"(a));
|
2010-07-07 17:27:51 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_clip_int8 av_clip_int8_arm
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const uint8_t av_clip_int8_arm(int a)
|
2010-07-07 17:27:51 +00:00
|
|
|
{
|
|
|
|
unsigned x;
|
2011-05-24 14:45:50 +00:00
|
|
|
__asm__ ("ssat %0, #8, %1" : "=r"(x) : "r"(a));
|
2010-07-07 17:27:51 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_clip_uint16 av_clip_uint16_arm
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const uint16_t av_clip_uint16_arm(int a)
|
2010-07-07 17:27:51 +00:00
|
|
|
{
|
|
|
|
unsigned x;
|
2011-05-24 14:45:50 +00:00
|
|
|
__asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a));
|
2010-07-07 17:27:51 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_clip_int16 av_clip_int16_arm
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const int16_t av_clip_int16_arm(int a)
|
2010-07-07 17:27:51 +00:00
|
|
|
{
|
|
|
|
int x;
|
2011-05-24 14:45:50 +00:00
|
|
|
__asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
|
2010-07-07 17:27:51 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2011-05-24 14:46:28 +00:00
|
|
|
#define av_clip_uintp2 av_clip_uintp2_arm
|
|
|
|
static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
|
|
|
|
{
|
|
|
|
unsigned x;
|
|
|
|
__asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-07 17:27:48 +00:00
|
|
|
#else /* HAVE_ARMV6 */
|
|
|
|
|
|
|
|
#define FASTDIV FASTDIV
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const int FASTDIV(int a, int b)
|
2010-01-19 23:25:36 +00:00
|
|
|
{
|
|
|
|
int r, t;
|
2011-05-24 14:45:50 +00:00
|
|
|
__asm__ ("umull %1, %0, %2, %3"
|
|
|
|
: "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
|
2010-01-19 23:25:36 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-07-07 17:27:48 +00:00
|
|
|
#endif /* HAVE_ARMV6 */
|
2010-01-19 23:25:36 +00:00
|
|
|
|
2010-07-07 17:27:51 +00:00
|
|
|
#define av_clipl_int32 av_clipl_int32_arm
|
2011-02-16 18:20:54 +00:00
|
|
|
static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
|
2010-07-07 17:27:51 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
2011-05-24 14:45:50 +00:00
|
|
|
__asm__ ("adds %1, %R2, %Q2, lsr #31 \n\t"
|
|
|
|
"mvnne %1, #1<<31 \n\t"
|
|
|
|
"moveq %0, %Q2 \n\t"
|
|
|
|
"eorne %0, %1, %R2, asr #31 \n\t"
|
|
|
|
: "=r"(x), "=&r"(y) : "r"(a));
|
2010-07-07 17:27:51 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2010-01-19 23:25:36 +00:00
|
|
|
#endif /* HAVE_INLINE_ASM */
|
|
|
|
|
|
|
|
#endif /* AVUTIL_ARM_INTMATH_H */
|