2010-01-20 01:25:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* 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 20:27:51 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2010-01-20 01:25:36 +02:00
|
|
|
#include "config.h"
|
2010-03-09 19:39:19 +02:00
|
|
|
#include "libavutil/attributes.h"
|
2010-01-20 01:25:36 +02:00
|
|
|
|
|
|
|
#if HAVE_INLINE_ASM
|
|
|
|
|
2012-12-01 19:41:39 +03:00
|
|
|
#if HAVE_ARMV6_INLINE
|
2010-07-07 20:27:48 +03:00
|
|
|
|
2010-07-07 20:27:51 +03:00
|
|
|
#define av_clip_uint8 av_clip_uint8_arm
|
2015-07-20 17:16:20 +02:00
|
|
|
static av_always_inline av_const int av_clip_uint8_arm(int a)
|
2010-07-07 20:27:51 +03:00
|
|
|
{
|
2015-07-20 17:16:20 +02:00
|
|
|
int x;
|
2011-05-24 17:45:50 +03:00
|
|
|
__asm__ ("usat %0, #8, %1" : "=r"(x) : "r"(a));
|
2010-07-07 20:27:51 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_clip_int8 av_clip_int8_arm
|
2012-08-11 06:08:15 +03:00
|
|
|
static av_always_inline av_const int av_clip_int8_arm(int a)
|
2010-07-07 20:27:51 +03:00
|
|
|
{
|
2012-08-11 06:08:15 +03:00
|
|
|
int x;
|
2011-05-24 17:45:50 +03:00
|
|
|
__asm__ ("ssat %0, #8, %1" : "=r"(x) : "r"(a));
|
2010-07-07 20:27:51 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_clip_uint16 av_clip_uint16_arm
|
2015-07-20 17:16:20 +02:00
|
|
|
static av_always_inline av_const int av_clip_uint16_arm(int a)
|
2010-07-07 20:27:51 +03:00
|
|
|
{
|
2015-07-20 17:16:20 +02:00
|
|
|
int x;
|
2011-05-24 17:45:50 +03:00
|
|
|
__asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a));
|
2010-07-07 20:27:51 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_clip_int16 av_clip_int16_arm
|
2012-08-11 06:08:15 +03:00
|
|
|
static av_always_inline av_const int av_clip_int16_arm(int a)
|
2010-07-07 20:27:51 +03:00
|
|
|
{
|
|
|
|
int x;
|
2011-05-24 17:45:50 +03:00
|
|
|
__asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
|
2010-07-07 20:27:51 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2015-02-20 02:35:34 +02:00
|
|
|
#define av_clip_intp2 av_clip_intp2_arm
|
|
|
|
static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
|
|
|
|
{
|
2022-08-26 10:26:32 +02:00
|
|
|
if (av_builtin_constant_p(p)) {
|
|
|
|
unsigned x;
|
|
|
|
__asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
|
|
|
|
return x;
|
|
|
|
} else {
|
|
|
|
if (((unsigned)a + (1 << p)) & ~((2 << p) - 1))
|
|
|
|
return (a >> 31) ^ ((1 << p) - 1);
|
|
|
|
else
|
|
|
|
return a;
|
|
|
|
}
|
2015-02-20 02:35:34 +02:00
|
|
|
}
|
|
|
|
|
2011-05-24 17:46:28 +03:00
|
|
|
#define av_clip_uintp2 av_clip_uintp2_arm
|
|
|
|
static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
|
|
|
|
{
|
2022-08-26 10:26:32 +02:00
|
|
|
if (av_builtin_constant_p(p)) {
|
|
|
|
unsigned x;
|
|
|
|
__asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
|
|
|
|
return x;
|
|
|
|
} else {
|
|
|
|
if (a & ~((1<<p) - 1)) return (~a) >> 31 & ((1<<p) - 1);
|
|
|
|
else return a;
|
|
|
|
}
|
2011-05-24 17:46:28 +03:00
|
|
|
}
|
|
|
|
|
2012-08-11 03:15:19 +03:00
|
|
|
#define av_sat_add32 av_sat_add32_arm
|
|
|
|
static av_always_inline int av_sat_add32_arm(int a, int b)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
__asm__ ("qadd %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_sat_dadd32 av_sat_dadd32_arm
|
|
|
|
static av_always_inline int av_sat_dadd32_arm(int a, int b)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
__asm__ ("qdadd %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
|
|
|
|
return r;
|
|
|
|
}
|
2011-05-24 17:46:28 +03:00
|
|
|
|
2017-12-02 19:36:24 +02:00
|
|
|
#define av_sat_sub32 av_sat_sub32_arm
|
|
|
|
static av_always_inline int av_sat_sub32_arm(int a, int b)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
__asm__ ("qsub %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define av_sat_dsub32 av_sat_dsub32_arm
|
|
|
|
static av_always_inline int av_sat_dsub32_arm(int a, int b)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
__asm__ ("qdsub %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-12-01 19:41:39 +03:00
|
|
|
#endif /* HAVE_ARMV6_INLINE */
|
2010-01-20 01:25:36 +02:00
|
|
|
|
2012-08-07 19:43:29 +03:00
|
|
|
#if HAVE_ASM_MOD_Q
|
|
|
|
|
2010-07-07 20:27:51 +03:00
|
|
|
#define av_clipl_int32 av_clipl_int32_arm
|
2011-02-16 20:20:54 +02:00
|
|
|
static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
|
2010-07-07 20:27:51 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
2011-05-24 17:45:50 +03:00
|
|
|
__asm__ ("adds %1, %R2, %Q2, lsr #31 \n\t"
|
2011-06-14 13:29:48 +03:00
|
|
|
"itet ne \n\t"
|
2011-05-24 17:45:50 +03:00
|
|
|
"mvnne %1, #1<<31 \n\t"
|
|
|
|
"moveq %0, %Q2 \n\t"
|
|
|
|
"eorne %0, %1, %R2, asr #31 \n\t"
|
2012-08-10 00:45:51 +03:00
|
|
|
: "=r"(x), "=&r"(y) : "r"(a) : "cc");
|
2010-07-07 20:27:51 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2012-08-07 19:43:29 +03:00
|
|
|
#endif /* HAVE_ASM_MOD_Q */
|
|
|
|
|
2010-01-20 01:25:36 +02:00
|
|
|
#endif /* HAVE_INLINE_ASM */
|
|
|
|
|
|
|
|
#endif /* AVUTIL_ARM_INTMATH_H */
|