mathops.h 2.18 KB
Newer Older
1 2 3 4
/*
 * simple math operations
 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
 *
5 6 7
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
8 9
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13 14 15 16 17
 * 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
18
 * License along with FFmpeg; if not, write to the Free Software
19 20 21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

22 23
#ifndef AVCODEC_ARM_MATHOPS_H
#define AVCODEC_ARM_MATHOPS_H
24

25
#include <stdint.h>
26
#include "config.h"
27 28
#include "libavutil/common.h"

29 30
#if HAVE_INLINE_ASM

31
#if HAVE_ARMV6
32
#define MULH MULH
33 34 35
static inline av_const int MULH(int a, int b)
{
    int r;
36
    __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
37 38
    return r;
}
39
#endif
Måns Rullgård's avatar
Måns Rullgård committed
40

41 42
#define MLS64(d, a, b) MAC64(d, -(a), b)

43
#if HAVE_ARMV5TE
44 45

/* signed 16x16 -> 32 multiply add accumulate */
46 47 48
#   define MAC16(rt, ra, rb)                                            \
    __asm__ ("smlabb %0, %1, %2, %0" : "+r"(rt) : "r"(ra), "r"(rb));

49
/* signed 16x16 -> 32 multiply */
50
#   define MUL16 MUL16
51
static inline av_const int MUL16(int ra, int rb)
52 53 54 55 56
{
    int rt;
    __asm__ ("smulbb %0, %1, %2" : "=r"(rt) : "r"(ra), "r"(rb));
    return rt;
}
57 58

#endif
59

60 61 62 63
#define mid_pred mid_pred
static inline av_const int mid_pred(int a, int b, int c)
{
    int m;
64
    __asm__ (
65 66
        "mov   %0, %2  \n\t"
        "cmp   %1, %2  \n\t"
67
        "itt   gt      \n\t"
68 69 70
        "movgt %0, %1  \n\t"
        "movgt %1, %2  \n\t"
        "cmp   %1, %3  \n\t"
71
        "it    le      \n\t"
72 73
        "movle %1, %3  \n\t"
        "cmp   %0, %1  \n\t"
74
        "it    gt      \n\t"
75 76
        "movgt %0, %1  \n\t"
        : "=&r"(m), "+r"(a)
77 78
        : "r"(b), "r"(c)
        : "cc");
79 80 81
    return m;
}

82 83
#endif /* HAVE_INLINE_ASM */

84
#endif /* AVCODEC_ARM_MATHOPS_H */