intmath.h 3.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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

24 25
#include <stdint.h>

26
#include "config.h"
27
#include "libavutil/attributes.h"
28 29 30

#if HAVE_INLINE_ASM

31
#if HAVE_ARMV6_INLINE
32

33
#define av_clip_uint8 av_clip_uint8_arm
34
static av_always_inline av_const int av_clip_uint8_arm(int a)
35
{
36
    int x;
37
    __asm__ ("usat %0, #8,  %1" : "=r"(x) : "r"(a));
38 39 40 41
    return x;
}

#define av_clip_int8 av_clip_int8_arm
42
static av_always_inline av_const int av_clip_int8_arm(int a)
43
{
44
    int x;
45
    __asm__ ("ssat %0, #8,  %1" : "=r"(x) : "r"(a));
46 47 48 49
    return x;
}

#define av_clip_uint16 av_clip_uint16_arm
50
static av_always_inline av_const int av_clip_uint16_arm(int a)
51
{
52
    int x;
53
    __asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a));
54 55 56 57
    return x;
}

#define av_clip_int16 av_clip_int16_arm
58
static av_always_inline av_const int av_clip_int16_arm(int a)
59 60
{
    int x;
61
    __asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
62 63 64
    return x;
}

65 66 67 68 69 70 71 72
#define av_clip_intp2 av_clip_intp2_arm
static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
{
    unsigned x;
    __asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
    return x;
}

73 74 75 76 77 78 79 80
#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;
}

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#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;
}
96

97
#endif /* HAVE_ARMV6_INLINE */
98

99 100
#if HAVE_ASM_MOD_Q

101
#define av_clipl_int32 av_clipl_int32_arm
102
static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
103 104
{
    int x, y;
105
    __asm__ ("adds   %1, %R2, %Q2, lsr #31  \n\t"
106
             "itet   ne                     \n\t"
107 108 109
             "mvnne  %1, #1<<31             \n\t"
             "moveq  %0, %Q2                \n\t"
             "eorne  %0, %1,  %R2, asr #31  \n\t"
110
             : "=r"(x), "=&r"(y) : "r"(a) : "cc");
111 112 113
    return x;
}

114 115
#endif /* HAVE_ASM_MOD_Q */

116 117 118
#endif /* HAVE_INLINE_ASM */

#endif /* AVUTIL_ARM_INTMATH_H */