nengel@2: /* nengel@2: * simple math operations nengel@2: * Copyright (c) 2006 Michael Niedermayer et al nengel@2: * nengel@2: * This file is part of FFmpeg. nengel@2: * nengel@2: * FFmpeg is free software; you can redistribute it and/or nengel@2: * modify it under the terms of the GNU Lesser General Public nengel@2: * License as published by the Free Software Foundation; either nengel@2: * version 2.1 of the License, or (at your option) any later version. nengel@2: * nengel@2: * FFmpeg is distributed in the hope that it will be useful, nengel@2: * but WITHOUT ANY WARRANTY; without even the implied warranty of nengel@2: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU nengel@2: * Lesser General Public License for more details. nengel@2: * nengel@2: * You should have received a copy of the GNU Lesser General Public nengel@2: * License along with FFmpeg; if not, write to the Free Software nengel@2: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA nengel@2: */ nengel@2: nengel@2: #ifndef AVCODEC_ARM_MATHOPS_H nengel@2: #define AVCODEC_ARM_MATHOPS_H nengel@2: nengel@2: #include nengel@2: #include "config.h" nengel@2: #include "libavutil/common.h" nengel@2: nengel@2: #if HAVE_INLINE_ASM nengel@2: nengel@2: # define MULL MULL nengel@2: static inline av_const int MULL(int a, int b, unsigned shift) nengel@2: { nengel@2: int lo, hi; nengel@2: __asm__("smull %0, %1, %2, %3 \n\t" nengel@2: "mov %0, %0, lsr %4 \n\t" nengel@2: "add %1, %0, %1, lsl %5 \n\t" nengel@2: : "=&r"(lo), "=&r"(hi) nengel@2: : "r"(b), "r"(a), "ir"(shift), "ir"(32-shift)); nengel@2: return hi; nengel@2: } nengel@2: nengel@2: #define MULH MULH nengel@2: #if HAVE_ARMV6 nengel@2: static inline av_const int MULH(int a, int b) nengel@2: { nengel@2: int r; nengel@2: __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); nengel@2: return r; nengel@2: } nengel@2: #else nengel@2: static inline av_const int MULH(int a, int b) nengel@2: { nengel@2: int lo, hi; nengel@2: __asm__ ("smull %0, %1, %2, %3" : "=&r"(lo), "=&r"(hi) : "r"(b), "r"(a)); nengel@2: return hi; nengel@2: } nengel@2: #endif nengel@2: nengel@2: static inline av_const int64_t MUL64(int a, int b) nengel@2: { nengel@2: union { uint64_t x; unsigned hl[2]; } x; nengel@2: __asm__ ("smull %0, %1, %2, %3" nengel@2: : "=r"(x.hl[0]), "=r"(x.hl[1]) : "r"(a), "r"(b)); nengel@2: return x.x; nengel@2: } nengel@2: #define MUL64 MUL64 nengel@2: nengel@2: static inline av_const int64_t MAC64(int64_t d, int a, int b) nengel@2: { nengel@2: union { uint64_t x; unsigned hl[2]; } x = { d }; nengel@2: __asm__ ("smlal %0, %1, %2, %3" nengel@2: : "+r"(x.hl[0]), "+r"(x.hl[1]) : "r"(a), "r"(b)); nengel@2: return x.x; nengel@2: } nengel@2: #define MAC64(d, a, b) ((d) = MAC64(d, a, b)) nengel@2: #define MLS64(d, a, b) MAC64(d, -(a), b) nengel@2: nengel@2: #if HAVE_ARMV5TE nengel@2: nengel@2: /* signed 16x16 -> 32 multiply add accumulate */ nengel@2: # define MAC16(rt, ra, rb) \ nengel@2: __asm__ ("smlabb %0, %1, %2, %0" : "+r"(rt) : "r"(ra), "r"(rb)); nengel@2: nengel@2: /* signed 16x16 -> 32 multiply */ nengel@2: # define MUL16 MUL16 nengel@2: static inline av_const int MUL16(int ra, int rb) nengel@2: { nengel@2: int rt; nengel@2: __asm__ ("smulbb %0, %1, %2" : "=r"(rt) : "r"(ra), "r"(rb)); nengel@2: return rt; nengel@2: } nengel@2: nengel@2: #endif nengel@2: nengel@2: #define mid_pred mid_pred nengel@2: static inline av_const int mid_pred(int a, int b, int c) nengel@2: { nengel@2: int m; nengel@2: __asm__ volatile ( nengel@2: "mov %0, %2 \n\t" nengel@2: "cmp %1, %2 \n\t" nengel@2: "movgt %0, %1 \n\t" nengel@2: "movgt %1, %2 \n\t" nengel@2: "cmp %1, %3 \n\t" nengel@2: "movle %1, %3 \n\t" nengel@2: "cmp %0, %1 \n\t" nengel@2: "movgt %0, %1 \n\t" nengel@2: : "=&r"(m), "+r"(a) nengel@2: : "r"(b), "r"(c)); nengel@2: return m; nengel@2: } nengel@2: nengel@2: #endif /* HAVE_INLINE_ASM */ nengel@2: nengel@2: #endif /* AVCODEC_ARM_MATHOPS_H */