yading@10: /* yading@10: * Copyright (c) 2004 Romain Dolbeau yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #include "config.h" yading@10: #include "libavutil/attributes.h" yading@10: #include "libavcodec/h264qpel.h" yading@10: yading@10: #if HAVE_ALTIVEC yading@10: #include "libavutil/cpu.h" yading@10: #include "libavutil/intreadwrite.h" yading@10: #include "libavutil/ppc/types_altivec.h" yading@10: #include "libavutil/ppc/util_altivec.h" yading@10: #include "dsputil_altivec.h" yading@10: yading@10: #define PUT_OP_U8_ALTIVEC(d, s, dst) d = s yading@10: #define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s) yading@10: yading@10: #define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC yading@10: #define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec yading@10: #define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num yading@10: #define PREFIX_h264_qpel16_v_lowpass_altivec put_h264_qpel16_v_lowpass_altivec yading@10: #define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num yading@10: #define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec yading@10: #define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num yading@10: #include "h264_qpel_template.c" yading@10: #undef OP_U8_ALTIVEC yading@10: #undef PREFIX_h264_qpel16_h_lowpass_altivec yading@10: #undef PREFIX_h264_qpel16_h_lowpass_num yading@10: #undef PREFIX_h264_qpel16_v_lowpass_altivec yading@10: #undef PREFIX_h264_qpel16_v_lowpass_num yading@10: #undef PREFIX_h264_qpel16_hv_lowpass_altivec yading@10: #undef PREFIX_h264_qpel16_hv_lowpass_num yading@10: yading@10: #define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC yading@10: #define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec yading@10: #define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num yading@10: #define PREFIX_h264_qpel16_v_lowpass_altivec avg_h264_qpel16_v_lowpass_altivec yading@10: #define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num yading@10: #define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec yading@10: #define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num yading@10: #include "h264_qpel_template.c" yading@10: #undef OP_U8_ALTIVEC yading@10: #undef PREFIX_h264_qpel16_h_lowpass_altivec yading@10: #undef PREFIX_h264_qpel16_h_lowpass_num yading@10: #undef PREFIX_h264_qpel16_v_lowpass_altivec yading@10: #undef PREFIX_h264_qpel16_v_lowpass_num yading@10: #undef PREFIX_h264_qpel16_hv_lowpass_altivec yading@10: #undef PREFIX_h264_qpel16_hv_lowpass_num yading@10: yading@10: #define H264_MC(OPNAME, SIZE, CODETYPE) \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: ff_ ## OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: { \ yading@10: DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ yading@10: OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ yading@10: put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: \ yading@10: static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\ yading@10: {\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ yading@10: DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ yading@10: put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ yading@10: put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ yading@10: OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ yading@10: }\ yading@10: yading@10: static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, yading@10: const uint8_t * src2, int dst_stride, yading@10: int src_stride1, int h) yading@10: { yading@10: int i; yading@10: vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align; yading@10: yading@10: mask_ = vec_lvsl(0, src2); yading@10: yading@10: for (i = 0; i < h; i++) { yading@10: yading@10: tmp1 = vec_ld(i * src_stride1, src1); yading@10: mask = vec_lvsl(i * src_stride1, src1); yading@10: tmp2 = vec_ld(i * src_stride1 + 15, src1); yading@10: yading@10: a = vec_perm(tmp1, tmp2, mask); yading@10: yading@10: tmp1 = vec_ld(i * 16, src2); yading@10: tmp2 = vec_ld(i * 16 + 15, src2); yading@10: yading@10: b = vec_perm(tmp1, tmp2, mask_); yading@10: yading@10: tmp1 = vec_ld(0, dst); yading@10: mask = vec_lvsl(0, dst); yading@10: tmp2 = vec_ld(15, dst); yading@10: yading@10: d = vec_avg(a, b); yading@10: yading@10: edges = vec_perm(tmp2, tmp1, mask); yading@10: yading@10: align = vec_lvsr(0, dst); yading@10: yading@10: tmp2 = vec_perm(d, edges, align); yading@10: tmp1 = vec_perm(edges, d, align); yading@10: yading@10: vec_st(tmp2, 15, dst); yading@10: vec_st(tmp1, 0 , dst); yading@10: yading@10: dst += dst_stride; yading@10: } yading@10: } yading@10: yading@10: static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, yading@10: const uint8_t * src2, int dst_stride, yading@10: int src_stride1, int h) yading@10: { yading@10: int i; yading@10: vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align; yading@10: yading@10: mask_ = vec_lvsl(0, src2); yading@10: yading@10: for (i = 0; i < h; i++) { yading@10: yading@10: tmp1 = vec_ld(i * src_stride1, src1); yading@10: mask = vec_lvsl(i * src_stride1, src1); yading@10: tmp2 = vec_ld(i * src_stride1 + 15, src1); yading@10: yading@10: a = vec_perm(tmp1, tmp2, mask); yading@10: yading@10: tmp1 = vec_ld(i * 16, src2); yading@10: tmp2 = vec_ld(i * 16 + 15, src2); yading@10: yading@10: b = vec_perm(tmp1, tmp2, mask_); yading@10: yading@10: tmp1 = vec_ld(0, dst); yading@10: mask = vec_lvsl(0, dst); yading@10: tmp2 = vec_ld(15, dst); yading@10: yading@10: d = vec_avg(vec_perm(tmp1, tmp2, mask), vec_avg(a, b)); yading@10: yading@10: edges = vec_perm(tmp2, tmp1, mask); yading@10: yading@10: align = vec_lvsr(0, dst); yading@10: yading@10: tmp2 = vec_perm(d, edges, align); yading@10: tmp1 = vec_perm(edges, d, align); yading@10: yading@10: vec_st(tmp2, 15, dst); yading@10: vec_st(tmp1, 0 , dst); yading@10: yading@10: dst += dst_stride; yading@10: } yading@10: } yading@10: yading@10: /* Implemented but could be faster yading@10: #define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h) yading@10: #define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h) yading@10: */ yading@10: yading@10: H264_MC(put_, 16, altivec) yading@10: H264_MC(avg_, 16, altivec) yading@10: #endif /* HAVE_ALTIVEC */ yading@10: yading@10: av_cold void ff_h264qpel_init_ppc(H264QpelContext *c, int bit_depth) yading@10: { yading@10: #if HAVE_ALTIVEC yading@10: const int high_bit_depth = bit_depth > 8; yading@10: yading@10: if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { yading@10: if (!high_bit_depth) { yading@10: #define dspfunc(PFX, IDX, NUM) \ yading@10: c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \ yading@10: c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec yading@10: yading@10: dspfunc(put_h264_qpel, 0, 16); yading@10: dspfunc(avg_h264_qpel, 0, 16); yading@10: #undef dspfunc yading@10: } yading@10: } yading@10: #endif /* HAVE_ALTIVEC */ yading@10: }