Libav
|
00001 /* 00002 * simple math operations 00003 * Copyright (c) 2001, 2002 Fabrice Bellard 00004 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef AVCODEC_PPC_MATHOPS_H 00024 #define AVCODEC_PPC_MATHOPS_H 00025 00026 #include <stdint.h> 00027 #include "config.h" 00028 #include "libavutil/common.h" 00029 00030 #if HAVE_PPC4XX 00031 /* signed 16x16 -> 32 multiply add accumulate */ 00032 #define MAC16(rt, ra, rb) \ 00033 __asm__ ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb)); 00034 00035 /* signed 16x16 -> 32 multiply */ 00036 #define MUL16(ra, rb) \ 00037 ({ int __rt; \ 00038 __asm__ ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); \ 00039 __rt; }) 00040 #endif 00041 00042 #define MULH MULH 00043 static inline av_const int MULH(int a, int b){ 00044 int r; 00045 __asm__ ("mulhw %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); 00046 return r; 00047 } 00048 00049 #if !ARCH_PPC64 00050 static inline av_const int64_t MAC64(int64_t d, int a, int b) 00051 { 00052 union { uint64_t x; unsigned hl[2]; } x = { d }; 00053 int h, l; 00054 __asm__ ("mullw %3, %4, %5 \n\t" 00055 "mulhw %2, %4, %5 \n\t" 00056 "addc %1, %1, %3 \n\t" 00057 "adde %0, %0, %2 \n\t" 00058 : "+r"(x.hl[0]), "+r"(x.hl[1]), "=&r"(h), "=&r"(l) 00059 : "r"(a), "r"(b)); 00060 return x.x; 00061 } 00062 #define MAC64(d, a, b) ((d) = MAC64(d, a, b)) 00063 00064 static inline av_const int64_t MLS64(int64_t d, int a, int b) 00065 { 00066 union { uint64_t x; unsigned hl[2]; } x = { d }; 00067 int h, l; 00068 __asm__ ("mullw %3, %4, %5 \n\t" 00069 "mulhw %2, %4, %5 \n\t" 00070 "subfc %1, %3, %1 \n\t" 00071 "subfe %0, %2, %0 \n\t" 00072 : "+r"(x.hl[0]), "+r"(x.hl[1]), "=&r"(h), "=&r"(l) 00073 : "r"(a), "r"(b)); 00074 return x.x; 00075 } 00076 #define MLS64(d, a, b) ((d) = MLS64(d, a, b)) 00077 #endif 00078 00079 #endif /* AVCODEC_PPC_MATHOPS_H */