nengel@2: /* nengel@2: * simple math operations nengel@2: * Copyright (c) 2001, 2002 Fabrice Bellard 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_PPC_MATHOPS_H nengel@2: #define AVCODEC_PPC_MATHOPS_H nengel@2: nengel@2: #include nengel@2: #include "config.h" nengel@2: #include "libavutil/common.h" nengel@2: nengel@2: #if HAVE_PPC4XX nengel@2: /* signed 16x16 -> 32 multiply add accumulate */ nengel@2: #define MAC16(rt, ra, rb) \ nengel@2: __asm__ ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb)); nengel@2: nengel@2: /* signed 16x16 -> 32 multiply */ nengel@2: #define MUL16(ra, rb) \ nengel@2: ({ int __rt; \ nengel@2: __asm__ ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); \ nengel@2: __rt; }) nengel@2: #endif nengel@2: nengel@2: #define MULH MULH nengel@2: static inline av_const int MULH(int a, int b){ nengel@2: int r; nengel@2: __asm__ ("mulhw %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); nengel@2: return r; nengel@2: } nengel@2: nengel@2: #if !ARCH_PPC64 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: int h, l; nengel@2: __asm__ ("mullw %3, %4, %5 \n\t" nengel@2: "mulhw %2, %4, %5 \n\t" nengel@2: "addc %1, %1, %3 \n\t" nengel@2: "adde %0, %0, %2 \n\t" nengel@2: : "+r"(x.hl[0]), "+r"(x.hl[1]), "=&r"(h), "=&r"(l) nengel@2: : "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: nengel@2: static inline av_const int64_t MLS64(int64_t d, int a, int b) nengel@2: { nengel@2: union { uint64_t x; unsigned hl[2]; } x = { d }; nengel@2: int h, l; nengel@2: __asm__ ("mullw %3, %4, %5 \n\t" nengel@2: "mulhw %2, %4, %5 \n\t" nengel@2: "subfc %1, %3, %1 \n\t" nengel@2: "subfe %0, %2, %0 \n\t" nengel@2: : "+r"(x.hl[0]), "+r"(x.hl[1]), "=&r"(h), "=&r"(l) nengel@2: : "r"(a), "r"(b)); nengel@2: return x.x; nengel@2: } nengel@2: #define MLS64(d, a, b) ((d) = MLS64(d, a, b)) nengel@2: #endif nengel@2: nengel@2: #endif /* AVCODEC_PPC_MATHOPS_H */