History

dsputil: Move pix_sum, pix_norm1, shrink function pointers to mpegvideoenc

Diego Biurrun committed 12 years ago

Commit c1661481 parent 8d686ca21 files · +444 −296Browse files

Unified · Split

21 files
  1. libavcodec/arm/Makefile +2 −0
  2. libavcodec/arm/dsputil_armv6.S +0 −55
  3. libavcodec/arm/dsputil_init_armv6.c +0 −6
  4. libavcodec/arm/mpegvideoencdsp_armv6.S +76 −0
  5. libavcodec/arm/mpegvideoencdsp_init_arm.c +38 −0
  6. libavcodec/dnxhdenc.c +3 −2
  7. libavcodec/dsputil.c +0 −79
  8. libavcodec/dsputil.h +0 −6
  9. libavcodec/motion_est.c +3 −2
  10. libavcodec/mpegvideo_enc.c +19 −12
  11. libavcodec/mpegvideoencdsp.c +83 −0
  12. libavcodec/mpegvideoencdsp.h +9 −0
  13. libavcodec/ppc/Makefile +1 −0
  14. libavcodec/ppc/dsputil_altivec.c +0 −60
  15. libavcodec/ppc/mpegvideoencdsp.c +103 −0
  16. libavcodec/svq1enc.c +1 −0
  17. libavcodec/x86/Makefile +1 −0
  18. libavcodec/x86/dsputilenc.asm +0 −69
  19. libavcodec/x86/dsputilenc_mmx.c +0 −4
  20. libavcodec/x86/mpegvideoencdsp.asm +95 −0
  21. libavcodec/x86/mpegvideoencdsp_init.c +10 −1
libavcodec/arm/Makefile+2−0
@@ -21,6 +21,7 @@ OBJS-$(CONFIG_IDCTDSP) += arm/idctdsp_init_arm.o \ · 20 unmodified lines
2121 arm/simple_idct_arm.o
2222 OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_init_arm.o
2323 OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_arm.o
24+OBJS-$(CONFIG_MPEGVIDEOENC) += arm/mpegvideoencdsp_init_arm.o
2425 OBJS-$(CONFIG_NEON_CLOBBER_TEST) += arm/neontest.o
2526 OBJS-$(CONFIG_VIDEODSP) += arm/videodsp_init_arm.o
2627 OBJS-$(CONFIG_VP3DSP) += arm/vp3dsp_init_arm.o
@@ -60,6 +61,7 @@ ARMV6-OBJS-$(CONFIG_IDCTDSP) += arm/idctdsp_init_armv6.o \ · 33 unmodified lines
6061 arm/idctdsp_armv6.o \
6162 arm/simple_idct_armv6.o
6263 ARMV6-OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_fixed_armv6.o
64+ARMV6-OBJS-$(CONFIG_MPEGVIDEOENC) += arm/mpegvideoencdsp_armv6.o
6365
6466 ARMV6-OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_armv6.o
6567 ARMV6-OBJS-$(CONFIG_VP7_DECODER) += arm/vp8_armv6.o \
libavcodec/arm/dsputil_armv6.S+0−55
@@ -297,58 +297,3 @@ function ff_sse16_armv6, export=1 · 296 unmodified lines
297297
298298 pop {r4-r9, pc}
299299 endfunc
300−
301−function ff_pix_norm1_armv6, export=1
302− push {r4-r6, lr}
303− mov r12, #16
304− mov lr, #0
305−1:
306− ldm r0, {r2-r5}
307− uxtb16 r6, r2
308− uxtb16 r2, r2, ror #8
309− smlad lr, r6, r6, lr
310− uxtb16 r6, r3
311− smlad lr, r2, r2, lr
312− uxtb16 r3, r3, ror #8
313− smlad lr, r6, r6, lr
314− uxtb16 r6, r4
315− smlad lr, r3, r3, lr
316− uxtb16 r4, r4, ror #8
317− smlad lr, r6, r6, lr
318− uxtb16 r6, r5
319− smlad lr, r4, r4, lr
320− uxtb16 r5, r5, ror #8
321− smlad lr, r6, r6, lr
322− subs r12, r12, #1
323− add r0, r0, r1
324− smlad lr, r5, r5, lr
325− bgt 1b
326−
327− mov r0, lr
328− pop {r4-r6, pc}
329−endfunc
330−
331−function ff_pix_sum_armv6, export=1
332− push {r4-r7, lr}
333− mov r12, #16
334− mov r2, #0
335− mov r3, #0
336− mov lr, #0
337− ldr r4, [r0]
338−1:
339− subs r12, r12, #1
340− ldr r5, [r0, #4]
341− usada8 r2, r4, lr, r2
342− ldr r6, [r0, #8]
343− usada8 r3, r5, lr, r3
344− ldr r7, [r0, #12]
345− usada8 r2, r6, lr, r2
346− beq 2f
347− ldr_pre r4, r0, r1
348− usada8 r3, r7, lr, r3
349− bgt 1b
350−2:
351− usada8 r3, r7, lr, r3
352− add r0, r2, r3
353− pop {r4-r7, pc}
354−endfunc
libavcodec/arm/dsputil_init_armv6.c+0−6
@@ -43,9 +43,6 @@ int ff_pix_abs8_armv6(MpegEncContext *s, uint8_t *blk1, uint8_t *blk2, · 42 unmodified lines
4343 int ff_sse16_armv6(MpegEncContext *s, uint8_t *blk1, uint8_t *blk2,
4444 int line_size, int h);
4545
46−int ff_pix_norm1_armv6(uint8_t *pix, int line_size);
47−int ff_pix_sum_armv6(uint8_t *pix, int line_size);
48−
4946 av_cold void ff_dsputil_init_armv6(DSPContext *c, AVCodecContext *avctx,
5047 unsigned high_bit_depth)
5148 {
@@ -63,7 +60,4 @@ av_cold void ff_dsputil_init_armv6(DSPContext *c, AVCodecContext *avctx, · 11 unmodified lines
6360 c->sad[1] = ff_pix_abs8_armv6;
6461
6562 c->sse[0] = ff_sse16_armv6;
66−
67− c->pix_norm1 = ff_pix_norm1_armv6;
68− c->pix_sum = ff_pix_sum_armv6;
6963 }
libavcodec/arm/mpegvideoencdsp_armv6.S+76−0
@@ -0,0 +1,76 @@
1+/*
2+ * Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
3+ *
4+ * This file is part of Libav.
5+ *
6+ * Libav is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * Libav is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with Libav; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include "libavutil/arm/asm.S"
22+
23+function ff_pix_norm1_armv6, export=1
24+ push {r4-r6, lr}
25+ mov r12, #16
26+ mov lr, #0
27+1:
28+ ldm r0, {r2-r5}
29+ uxtb16 r6, r2
30+ uxtb16 r2, r2, ror #8
31+ smlad lr, r6, r6, lr
32+ uxtb16 r6, r3
33+ smlad lr, r2, r2, lr
34+ uxtb16 r3, r3, ror #8
35+ smlad lr, r6, r6, lr
36+ uxtb16 r6, r4
37+ smlad lr, r3, r3, lr
38+ uxtb16 r4, r4, ror #8
39+ smlad lr, r6, r6, lr
40+ uxtb16 r6, r5
41+ smlad lr, r4, r4, lr
42+ uxtb16 r5, r5, ror #8
43+ smlad lr, r6, r6, lr
44+ subs r12, r12, #1
45+ add r0, r0, r1
46+ smlad lr, r5, r5, lr
47+ bgt 1b
48+
49+ mov r0, lr
50+ pop {r4-r6, pc}
51+endfunc
52+
53+function ff_pix_sum_armv6, export=1
54+ push {r4-r7, lr}
55+ mov r12, #16
56+ mov r2, #0
57+ mov r3, #0
58+ mov lr, #0
59+ ldr r4, [r0]
60+1:
61+ subs r12, r12, #1
62+ ldr r5, [r0, #4]
63+ usada8 r2, r4, lr, r2
64+ ldr r6, [r0, #8]
65+ usada8 r3, r5, lr, r3
66+ ldr r7, [r0, #12]
67+ usada8 r2, r6, lr, r2
68+ beq 2f
69+ ldr_pre r4, r0, r1
70+ usada8 r3, r7, lr, r3
71+ bgt 1b
72+2:
73+ usada8 r3, r7, lr, r3
74+ add r0, r2, r3
75+ pop {r4-r7, pc}
76+endfunc
libavcodec/arm/mpegvideoencdsp_init_arm.c+38−0
@@ -0,0 +1,38 @@
1+/*
2+ * This file is part of Libav.
3+ *
4+ * Libav is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * Libav is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with Libav; if not, write to the Free Software
16+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+ */
18+
19+#include <stdint.h>
20+
21+#include "libavutil/cpu.h"
22+#include "libavutil/arm/cpu.h"
23+#include "libavcodec/avcodec.h"
24+#include "libavcodec/mpegvideoencdsp.h"
25+
26+int ff_pix_norm1_armv6(uint8_t *pix, int line_size);
27+int ff_pix_sum_armv6(uint8_t *pix, int line_size);
28+
29+av_cold void ff_mpegvideoencdsp_init_arm(MpegvideoEncDSPContext *c,
30+ AVCodecContext *avctx)
31+{
32+ int cpu_flags = av_get_cpu_flags();
33+
34+ if (have_armv6(cpu_flags)) {
35+ c->pix_norm1 = ff_pix_norm1_armv6;
36+ c->pix_sum = ff_pix_sum_armv6;
37+ }
38+}
libavcodec/dnxhdenc.c+3−2
@@ -309,6 +309,7 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) · 308 unmodified lines
309309 ff_blockdsp_init(&ctx->bdsp, avctx);
310310 ff_dsputil_init(&ctx->m.dsp, avctx);
311311 ff_idctdsp_init(&ctx->m.idsp, avctx);
312+ ff_mpegvideoencdsp_init(&ctx->m.mpvencdsp, avctx);
312313 ff_dct_common_init(&ctx->m);
313314 if (!ctx->m.dct_quantize)
314315 ctx->m.dct_quantize = ff_dct_quantize_c;
@@ -719,8 +720,8 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, · 404 unmodified lines
719720 int varc;
720721
721722 if (!partial_last_row && mb_x * 16 <= avctx->width - 16) {
722− sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize);
723− varc = ctx->m.dsp.pix_norm1(pix, ctx->m.linesize);
723+ sum = ctx->m.mpvencdsp.pix_sum(pix, ctx->m.linesize);
724+ varc = ctx->m.mpvencdsp.pix_norm1(pix, ctx->m.linesize);
724725 } else {
725726 int bw = FFMIN(avctx->width - 16 * mb_x, 16);
726727 int bh = FFMIN((avctx->height >> ctx->interlaced) - 16 * mb_y, 16);
libavcodec/dsputil.c+0−79
@@ -26,15 +26,12 @@ · 25 unmodified lines
2626 */
2727
2828 #include "libavutil/attributes.h"
29−#include "libavutil/imgutils.h"
3029 #include "avcodec.h"
3130 #include "copy_block.h"
3231 #include "dct.h"
3332 #include "dsputil.h"
3433 #include "simple_idct.h"
3534 #include "faandct.h"
36−#include "imgconvert.h"
37−#include "mathops.h"
3835 #include "mpegvideo.h"
3936 #include "config.h"
4037
@@ -47,74 +44,6 @@ uint32_t ff_square_tab[512] = { 0, }; · 6 unmodified lines
4744 #define BIT_DEPTH 8
4845 #include "dsputilenc_template.c"
4946
50−static int pix_sum_c(uint8_t *pix, int line_size)
51−{
52− int s = 0, i, j;
53−
54− for (i = 0; i < 16; i++) {
55− for (j = 0; j < 16; j += 8) {
56− s += pix[0];
57− s += pix[1];
58− s += pix[2];
59− s += pix[3];
60− s += pix[4];
61− s += pix[5];
62− s += pix[6];
63− s += pix[7];
64− pix += 8;
65− }
66− pix += line_size - 16;
67− }
68− return s;
69−}
70−
71−static int pix_norm1_c(uint8_t *pix, int line_size)
72−{
73− int s = 0, i, j;
74− uint32_t *sq = ff_square_tab + 256;
75−
76− for (i = 0; i < 16; i++) {
77− for (j = 0; j < 16; j += 8) {
78−#if 0
79− s += sq[pix[0]];
80− s += sq[pix[1]];
81− s += sq[pix[2]];
82− s += sq[pix[3]];
83− s += sq[pix[4]];
84− s += sq[pix[5]];
85− s += sq[pix[6]];
86− s += sq[pix[7]];
87−#else
88−#if HAVE_FAST_64BIT
89− register uint64_t x = *(uint64_t *) pix;
90− s += sq[x & 0xff];
91− s += sq[(x >> 8) & 0xff];
92− s += sq[(x >> 16) & 0xff];
93− s += sq[(x >> 24) & 0xff];
94− s += sq[(x >> 32) & 0xff];
95− s += sq[(x >> 40) & 0xff];
96− s += sq[(x >> 48) & 0xff];
97− s += sq[(x >> 56) & 0xff];
98−#else
99− register uint32_t x = *(uint32_t *) pix;
100− s += sq[x & 0xff];
101− s += sq[(x >> 8) & 0xff];
102− s += sq[(x >> 16) & 0xff];
103− s += sq[(x >> 24) & 0xff];
104− x = *(uint32_t *) (pix + 4);
105− s += sq[x & 0xff];
106− s += sq[(x >> 8) & 0xff];
107− s += sq[(x >> 16) & 0xff];
108− s += sq[(x >> 24) & 0xff];
109−#endif
110−#endif
111− pix += 8;
112− }
113− pix += line_size - 16;
114− }
115− return s;
116−}
117−
11847 static int sse4_c(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
11948 int line_size, int h)
12049 {
@@ -1055,9 +984,6 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx) · 934 unmodified lines
1055984
1056985 c->sum_abs_dctelem = sum_abs_dctelem_c;
1057986
1058− c->pix_sum = pix_sum_c;
1059− c->pix_norm1 = pix_norm1_c;
1060−
1061987 /* TODO [0] 16 [1] 8 */
1062988 c->pix_abs[0][0] = pix_abs16_c;
1063989 c->pix_abs[0][1] = pix_abs16_x2_c;
@@ -1097,11 +1023,6 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx) · 33 unmodified lines
10971023 c->nsse[0] = nsse16_c;
10981024 c->nsse[1] = nsse8_c;
10991025
1100− c->shrink[0] = av_image_copy_plane;
1101− c->shrink[1] = ff_shrink22;
1102− c->shrink[2] = ff_shrink44;
1103− c->shrink[3] = ff_shrink88;
1104−
11051026 c->draw_edges = draw_edges_8_c;
11061027
11071028 switch (avctx->bits_per_raw_sample) {
libavcodec/dsputil.h+0−6
@@ -58,9 +58,6 @@ typedef struct DSPContext { · 57 unmodified lines
5858 int stride);
5959 int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
6060
61− int (*pix_sum)(uint8_t *pix, int line_size);
62− int (*pix_norm1)(uint8_t *pix, int line_size);
63−
6461 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
6562 me_cmp_func sse[6];
6663 me_cmp_func hadamard8_diff[6];
@@ -92,9 +89,6 @@ typedef struct DSPContext { · 25 unmodified lines
9289 #define EDGE_WIDTH 16
9390 #define EDGE_TOP 1
9491 #define EDGE_BOTTOM 2
95−
96− void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
97− int src_wrap, int width, int height);
9892 } DSPContext;
9993
10094 void ff_dsputil_static_init(void);
libavcodec/motion_est.c+3−2
@@ -881,8 +881,9 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, · 880 unmodified lines
881881
882882 /* intra / predictive decision */
883883 pix = c->src[0][0];
884− sum = s->dsp.pix_sum(pix, s->linesize);
885− varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500;
884+ sum = s->mpvencdsp.pix_sum(pix, s->linesize);
885+ varc = s->mpvencdsp.pix_norm1(pix, s->linesize) -
886+ (((unsigned) sum * sum) >> 8) + 500;
886887
887888 pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
888889 pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
libavcodec/mpegvideo_enc.c+19−12
@@ -895,7 +895,7 @@ static int get_intra_count(MpegEncContext *s, uint8_t *src, · 894 unmodified lines
895895 int offset = x + y * stride;
896896 int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride,
897897 16);
898− int mean = (s->dsp.pix_sum(src + offset, stride) + 128) >> 8;
898+ int mean = (s->mpvencdsp.pix_sum(src + offset, stride) + 128) >> 8;
899899 int sae = get_sae(src + offset, mean, stride);
900900
901901 acc += sae + 500 < sad;
@@ -1138,15 +1138,21 @@ static int estimate_best_b_count(MpegEncContext *s) · 236 unmodified lines
11381138 pre_input.f->data[2] += INPLACE_OFFSET;
11391139 }
11401140
1141− s->dsp.shrink[scale](s->tmp_frames[i]->data[0], s->tmp_frames[i]->linesize[0],
1142− pre_input.f->data[0], pre_input.f->linesize[0],
1143− c->width, c->height);
1144− s->dsp.shrink[scale](s->tmp_frames[i]->data[1], s->tmp_frames[i]->linesize[1],
1145− pre_input.f->data[1], pre_input.f->linesize[1],
1146− c->width >> 1, c->height >> 1);
1147− s->dsp.shrink[scale](s->tmp_frames[i]->data[2], s->tmp_frames[i]->linesize[2],
1148− pre_input.f->data[2], pre_input.f->linesize[2],
1149− c->width >> 1, c->height >> 1);
1141+ s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0],
1142+ s->tmp_frames[i]->linesize[0],
1143+ pre_input.f->data[0],
1144+ pre_input.f->linesize[0],
1145+ c->width, c->height);
1146+ s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1],
1147+ s->tmp_frames[i]->linesize[1],
1148+ pre_input.f->data[1],
1149+ pre_input.f->linesize[1],
1150+ c->width >> 1, c->height >> 1);
1151+ s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2],
1152+ s->tmp_frames[i]->linesize[2],
1153+ pre_input.f->data[2],
1154+ pre_input.f->linesize[2],
1155+ c->width >> 1, c->height >> 1);
11501156 }
11511157 }
11521158
@@ -2420,9 +2426,10 @@ static int mb_var_thread(AVCodecContext *c, void *arg){ · 1267 unmodified lines
24202426 int yy = mb_y * 16;
24212427 uint8_t *pix = s->new_picture.f->data[0] + (yy * s->linesize) + xx;
24222428 int varc;
2423− int sum = s->dsp.pix_sum(pix, s->linesize);
2429+ int sum = s->mpvencdsp.pix_sum(pix, s->linesize);
24242430
2425− varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500 + 128)>>8;
2431+ varc = (s->mpvencdsp.pix_norm1(pix, s->linesize) -
2432+ (((unsigned) sum * sum) >> 8) + 500 + 128) >> 8;
24262433
24272434 s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
24282435 s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
libavcodec/mpegvideoencdsp.c+83−0
@@ -21,7 +21,10 @@ · 20 unmodified lines
2121
2222 #include "config.h"
2323 #include "libavutil/attributes.h"
24+#include "libavutil/imgutils.h"
2425 #include "avcodec.h"
26+#include "dsputil.h"
27+#include "imgconvert.h"
2528 #include "mpegvideoencdsp.h"
2629
2730 static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
@@ -53,12 +56,92 @@ static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale) · 25 unmodified lines
5356 (BASIS_SHIFT - RECON_SHIFT);
5457 }
5558
59+static int pix_sum_c(uint8_t *pix, int line_size)
60+{
61+ int s = 0, i, j;
62+
63+ for (i = 0; i < 16; i++) {
64+ for (j = 0; j < 16; j += 8) {
65+ s += pix[0];
66+ s += pix[1];
67+ s += pix[2];
68+ s += pix[3];
69+ s += pix[4];
70+ s += pix[5];
71+ s += pix[6];
72+ s += pix[7];
73+ pix += 8;
74+ }
75+ pix += line_size - 16;
76+ }
77+ return s;
78+}
79+
80+static int pix_norm1_c(uint8_t *pix, int line_size)
81+{
82+ int s = 0, i, j;
83+ uint32_t *sq = ff_square_tab + 256;
84+
85+ for (i = 0; i < 16; i++) {
86+ for (j = 0; j < 16; j += 8) {
87+#if 0
88+ s += sq[pix[0]];
89+ s += sq[pix[1]];
90+ s += sq[pix[2]];
91+ s += sq[pix[3]];
92+ s += sq[pix[4]];
93+ s += sq[pix[5]];
94+ s += sq[pix[6]];
95+ s += sq[pix[7]];
96+#else
97+#if HAVE_FAST_64BIT
98+ register uint64_t x = *(uint64_t *) pix;
99+ s += sq[x & 0xff];
100+ s += sq[(x >> 8) & 0xff];
101+ s += sq[(x >> 16) & 0xff];
102+ s += sq[(x >> 24) & 0xff];
103+ s += sq[(x >> 32) & 0xff];
104+ s += sq[(x >> 40) & 0xff];
105+ s += sq[(x >> 48) & 0xff];
106+ s += sq[(x >> 56) & 0xff];
107+#else
108+ register uint32_t x = *(uint32_t *) pix;
109+ s += sq[x & 0xff];
110+ s += sq[(x >> 8) & 0xff];
111+ s += sq[(x >> 16) & 0xff];
112+ s += sq[(x >> 24) & 0xff];
113+ x = *(uint32_t *) (pix + 4);
114+ s += sq[x & 0xff];
115+ s += sq[(x >> 8) & 0xff];
116+ s += sq[(x >> 16) & 0xff];
117+ s += sq[(x >> 24) & 0xff];
118+#endif
119+#endif
120+ pix += 8;
121+ }
122+ pix += line_size - 16;
123+ }
124+ return s;
125+}
126+
56127 av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
57128 AVCodecContext *avctx)
58129 {
59130 c->try_8x8basis = try_8x8basis_c;
60131 c->add_8x8basis = add_8x8basis_c;
61132
133+ c->shrink[0] = av_image_copy_plane;
134+ c->shrink[1] = ff_shrink22;
135+ c->shrink[2] = ff_shrink44;
136+ c->shrink[3] = ff_shrink88;
137+
138+ c->pix_sum = pix_sum_c;
139+ c->pix_norm1 = pix_norm1_c;
140+
141+ if (ARCH_ARM)
142+ ff_mpegvideoencdsp_init_arm(c, avctx);
143+ if (ARCH_PPC)
144+ ff_mpegvideoencdsp_init_ppc(c, avctx);
62145 if (ARCH_X86)
63146 ff_mpegvideoencdsp_init_x86(c, avctx);
64147 }
libavcodec/mpegvideoencdsp.h+9−0
@@ -31,10 +31,19 @@ typedef struct MpegvideoEncDSPContext { · 30 unmodified lines
3131 int16_t basis[64], int scale);
3232 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
3333
34+ int (*pix_sum)(uint8_t *pix, int line_size);
35+ int (*pix_norm1)(uint8_t *pix, int line_size);
36+
37+ void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
38+ int src_wrap, int width, int height);
3439 } MpegvideoEncDSPContext;
3540
3641 void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
3742 AVCodecContext *avctx);
43+void ff_mpegvideoencdsp_init_arm(MpegvideoEncDSPContext *c,
44+ AVCodecContext *avctx);
45+void ff_mpegvideoencdsp_init_ppc(MpegvideoEncDSPContext *c,
46+ AVCodecContext *avctx);
3847 void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c,
3948 AVCodecContext *avctx);
4049
libavcodec/ppc/Makefile+1−0
@@ -13,6 +13,7 @@ OBJS-$(CONFIG_IDCTDSP) += ppc/idctdsp.o · 12 unmodified lines
1313 OBJS-$(CONFIG_MPEGAUDIODSP) += ppc/mpegaudiodsp_altivec.o
1414 OBJS-$(CONFIG_MPEGVIDEO) += ppc/mpegvideo_altivec.o \
1515 ppc/mpegvideodsp.o
16+OBJS-$(CONFIG_MPEGVIDEOENC) += ppc/mpegvideoencdsp.o
1617 OBJS-$(CONFIG_VIDEODSP) += ppc/videodsp_ppc.o
1718 OBJS-$(CONFIG_VP3DSP) += ppc/vp3dsp_altivec.o
1819
libavcodec/ppc/dsputil_altivec.c+0−60
@@ -308,34 +308,6 @@ static int sad8_altivec(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, · 307 unmodified lines
308308 return s;
309309 }
310310
311−static int pix_norm1_altivec(uint8_t *pix, int line_size)
312−{
313− int i, s = 0;
314− const vector unsigned int zero =
315− (const vector unsigned int) vec_splat_u32(0);
316− vector unsigned char perm = vec_lvsl(0, pix);
317− vector unsigned int sv = (vector unsigned int) vec_splat_u32(0);
318− vector signed int sum;
319−
320− for (i = 0; i < 16; i++) {
321− /* Read the potentially unaligned pixels. */
322− vector unsigned char pixl = vec_ld(0, pix);
323− vector unsigned char pixr = vec_ld(15, pix);
324− vector unsigned char pixv = vec_perm(pixl, pixr, perm);
325−
326− /* Square the values, and add them to our sum. */
327− sv = vec_msum(pixv, pixv, sv);
328−
329− pix += line_size;
330− }
331− /* Sum up the four partial sums, and put the result into s. */
332− sum = vec_sums((vector signed int) sv, (vector signed int) zero);
333− sum = vec_splat(sum, 3);
334− vec_ste(sum, 0, &s);
335−
336− return s;
337−}
338−
339311 /* Sum of Squared Errors for an 8x8 block, AltiVec-enhanced.
340312 * It's the sad8_altivec code above w/ squaring added. */
341313 static int sse8_altivec(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
@@ -430,35 +402,6 @@ static int sse16_altivec(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, · 88 unmodified lines
430402 return s;
431403 }
432404
433−static int pix_sum_altivec(uint8_t *pix, int line_size)
434−{
435− int i, s;
436− const vector unsigned int zero =
437− (const vector unsigned int) vec_splat_u32(0);
438− vector unsigned char perm = vec_lvsl(0, pix);
439− vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
440− vector signed int sumdiffs;
441−
442− for (i = 0; i < 16; i++) {
443− /* Read the potentially unaligned 16 pixels into t1. */
444− vector unsigned char pixl = vec_ld(0, pix);
445− vector unsigned char pixr = vec_ld(15, pix);
446− vector unsigned char t1 = vec_perm(pixl, pixr, perm);
447−
448− /* Add each 4 pixel group together and put 4 results into sad. */
449− sad = vec_sum4s(t1, sad);
450−
451− pix += line_size;
452− }
453−
454− /* Sum up the four partial sums, and put the result into s. */
455− sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
456− sumdiffs = vec_splat(sumdiffs, 3);
457− vec_ste(sumdiffs, 0, &s);
458−
459− return s;
460−}
461−
462405 static void get_pixels_altivec(int16_t *restrict block, const uint8_t *pixels,
463406 int line_size)
464407 {
@@ -911,9 +854,6 @@ av_cold void ff_dsputil_init_altivec(DSPContext *c, AVCodecContext *avctx, · 446 unmodified lines
911854 c->sse[0] = sse16_altivec;
912855 c->sse[1] = sse8_altivec;
913856
914− c->pix_norm1 = pix_norm1_altivec;
915− c->pix_sum = pix_sum_altivec;
916−
917857 c->diff_pixels = diff_pixels_altivec;
918858
919859 if (!high_bit_depth) {
libavcodec/ppc/mpegvideoencdsp.c+103−0
@@ -0,0 +1,103 @@
1+/*
2+ * This file is part of Libav.
3+ *
4+ * Libav is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * Libav is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with Libav; if not, write to the Free Software
16+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+ */
18+
19+#include "config.h"
20+#include <stdint.h>
21+#if HAVE_ALTIVEC_H
22+#include <altivec.h>
23+#endif
24+
25+#include "libavutil/attributes.h"
26+#include "libavutil/cpu.h"
27+#include "libavutil/ppc/cpu.h"
28+#include "libavutil/ppc/types_altivec.h"
29+#include "libavutil/ppc/util_altivec.h"
30+#include "libavcodec/mpegvideoencdsp.h"
31+
32+#if HAVE_ALTIVEC
33+
34+static int pix_norm1_altivec(uint8_t *pix, int line_size)
35+{
36+ int i, s = 0;
37+ const vector unsigned int zero =
38+ (const vector unsigned int) vec_splat_u32(0);
39+ vector unsigned char perm = vec_lvsl(0, pix);
40+ vector unsigned int sv = (vector unsigned int) vec_splat_u32(0);
41+ vector signed int sum;
42+
43+ for (i = 0; i < 16; i++) {
44+ /* Read the potentially unaligned pixels. */
45+ vector unsigned char pixl = vec_ld(0, pix);
46+ vector unsigned char pixr = vec_ld(15, pix);
47+ vector unsigned char pixv = vec_perm(pixl, pixr, perm);
48+
49+ /* Square the values, and add them to our sum. */
50+ sv = vec_msum(pixv, pixv, sv);
51+
52+ pix += line_size;
53+ }
54+ /* Sum up the four partial sums, and put the result into s. */
55+ sum = vec_sums((vector signed int) sv, (vector signed int) zero);
56+ sum = vec_splat(sum, 3);
57+ vec_ste(sum, 0, &s);
58+
59+ return s;
60+}
61+
62+static int pix_sum_altivec(uint8_t *pix, int line_size)
63+{
64+ int i, s;
65+ const vector unsigned int zero =
66+ (const vector unsigned int) vec_splat_u32(0);
67+ vector unsigned char perm = vec_lvsl(0, pix);
68+ vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
69+ vector signed int sumdiffs;
70+
71+ for (i = 0; i < 16; i++) {
72+ /* Read the potentially unaligned 16 pixels into t1. */
73+ vector unsigned char pixl = vec_ld(0, pix);
74+ vector unsigned char pixr = vec_ld(15, pix);
75+ vector unsigned char t1 = vec_perm(pixl, pixr, perm);
76+
77+ /* Add each 4 pixel group together and put 4 results into sad. */
78+ sad = vec_sum4s(t1, sad);
79+
80+ pix += line_size;
81+ }
82+
83+ /* Sum up the four partial sums, and put the result into s. */
84+ sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
85+ sumdiffs = vec_splat(sumdiffs, 3);
86+ vec_ste(sumdiffs, 0, &s);
87+
88+ return s;
89+}
90+
91+#endif /* HAVE_ALTIVEC */
92+
93+av_cold void ff_mpegvideoencdsp_init_ppc(MpegvideoEncDSPContext *c,
94+ AVCodecContext *avctx)
95+{
96+#if HAVE_ALTIVEC
97+ if (!PPC_ALTIVEC(av_get_cpu_flags()))
98+ return;
99+
100+ c->pix_norm1 = pix_norm1_altivec;
101+ c->pix_sum = pix_sum_altivec;
102+#endif /* HAVE_ALTIVEC */
103+}
libavcodec/svq1enc.c+1−0
@@ -511,6 +511,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx) · 510 unmodified lines
511511
512512 ff_dsputil_init(&s->dsp, avctx);
513513 ff_hpeldsp_init(&s->hdsp, avctx->flags);
514+ ff_mpegvideoencdsp_init(&s->m.mpvencdsp, avctx);
514515
515516 avctx->coded_frame = av_frame_alloc();
516517 s->current_picture = av_frame_alloc();
libavcodec/x86/Makefile+1−0
@@ -92,6 +92,7 @@ YASM-OBJS-$(CONFIG_HPELDSP) += x86/fpel.o \ · 91 unmodified lines
9292 x86/hpeldsp.o
9393 YASM-OBJS-$(CONFIG_HUFFYUVDSP) += x86/huffyuvdsp.o
9494 YASM-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/imdct36.o
95+YASM-OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoencdsp.o
9596 YASM-OBJS-$(CONFIG_QPELDSP) += x86/qpeldsp.o \
9697 x86/fpel.o \
9798 x86/qpel.o
libavcodec/x86/dsputilenc.asm+0−69
@@ -418,72 +418,3 @@ cglobal diff_pixels, 4,5 · 417 unmodified lines
418418 add r4, 16
419419 jne .loop
420420 REP_RET
421−
422−INIT_MMX mmx
423−; int ff_pix_sum16_mmx(uint8_t *pix, int line_size)
424−cglobal pix_sum16, 2, 3
425− movsxdifnidn r1, r1d
426− mov r2, r1
427− neg r2
428− shl r2, 4
429− sub r0, r2
430− pxor m7, m7
431− pxor m6, m6
432−.loop:
433− mova m0, [r0+r2+0]
434− mova m1, [r0+r2+0]
435− mova m2, [r0+r2+8]
436− mova m3, [r0+r2+8]
437− punpcklbw m0, m7
438− punpckhbw m1, m7
439− punpcklbw m2, m7
440− punpckhbw m3, m7
441− paddw m1, m0
442− paddw m3, m2
443− paddw m3, m1
444− paddw m6, m3
445− add r2, r1
446− js .loop
447− mova m5, m6
448− psrlq m6, 32
449− paddw m6, m5
450− mova m5, m6
451− psrlq m6, 16
452− paddw m6, m5
453− movd eax, m6
454− and eax, 0xffff
455− RET
456−
457−INIT_MMX mmx
458−; int ff_pix_norm1_mmx(uint8_t *pix, int line_size)
459−cglobal pix_norm1, 2, 4
460− movsxdifnidn r1, r1d
461− mov r2, 16
462− pxor m0, m0
463− pxor m7, m7
464−.loop:
465− mova m2, [r0+0]
466− mova m3, [r0+8]
467− mova m1, m2
468− punpckhbw m1, m0
469− punpcklbw m2, m0
470− mova m4, m3
471− punpckhbw m3, m0
472− punpcklbw m4, m0
473− pmaddwd m1, m1
474− pmaddwd m2, m2
475− pmaddwd m3, m3
476− pmaddwd m4, m4
477− paddd m2, m1
478− paddd m4, m3
479− paddd m7, m2
480− add r0, r1
481− paddd m7, m4
482− dec r2
483− jne .loop
484− mova m1, m7
485− psrlq m7, 32
486− paddd m1, m7
487− movd eax, m1
488− RET
489−
libavcodec/x86/dsputilenc_mmx.c+0−4
@@ -35,8 +35,6 @@ void ff_get_pixels_mmx(int16_t *block, const uint8_t *pixels, int line_size); · 34 unmodified lines
3535 void ff_get_pixels_sse2(int16_t *block, const uint8_t *pixels, int line_size);
3636 void ff_diff_pixels_mmx(int16_t *block, const uint8_t *s1, const uint8_t *s2,
3737 int stride);
38−int ff_pix_sum16_mmx(uint8_t *pix, int line_size);
39−int ff_pix_norm1_mmx(uint8_t *pix, int line_size);
4038
4139 #if HAVE_INLINE_ASM
4240
@@ -831,8 +829,6 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx, · 788 unmodified lines
831829 if (!high_bit_depth)
832830 c->get_pixels = ff_get_pixels_mmx;
833831 c->diff_pixels = ff_diff_pixels_mmx;
834− c->pix_sum = ff_pix_sum16_mmx;
835− c->pix_norm1 = ff_pix_norm1_mmx;
836832 }
837833
838834 if (EXTERNAL_SSE2(cpu_flags))
libavcodec/x86/mpegvideoencdsp.asm+95−0
@@ -0,0 +1,95 @@
1+;*****************************************************************************
2+;* SIMD-optimized MPEG encoding functions
3+;*****************************************************************************
4+;* Copyright (c) 2000, 2001 Fabrice Bellard
5+;* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6+;*
7+;* This file is part of Libav.
8+;*
9+;* Libav is free software; you can redistribute it and/or
10+;* modify it under the terms of the GNU Lesser General Public
11+;* License as published by the Free Software Foundation; either
12+;* version 2.1 of the License, or (at your option) any later version.
13+;*
14+;* Libav is distributed in the hope that it will be useful,
15+;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+;* Lesser General Public License for more details.
18+;*
19+;* You should have received a copy of the GNU Lesser General Public
20+;* License along with Libav; if not, write to the Free Software
21+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22+;*****************************************************************************
23+
24+%include "libavutil/x86/x86util.asm"
25+
26+SECTION .text
27+
28+INIT_MMX mmx
29+; int ff_pix_sum16_mmx(uint8_t *pix, int line_size)
30+cglobal pix_sum16, 2, 3
31+ movsxdifnidn r1, r1d
32+ mov r2, r1
33+ neg r2
34+ shl r2, 4
35+ sub r0, r2
36+ pxor m7, m7
37+ pxor m6, m6
38+.loop:
39+ mova m0, [r0+r2+0]
40+ mova m1, [r0+r2+0]
41+ mova m2, [r0+r2+8]
42+ mova m3, [r0+r2+8]
43+ punpcklbw m0, m7
44+ punpckhbw m1, m7
45+ punpcklbw m2, m7
46+ punpckhbw m3, m7
47+ paddw m1, m0
48+ paddw m3, m2
49+ paddw m3, m1
50+ paddw m6, m3
51+ add r2, r1
52+ js .loop
53+ mova m5, m6
54+ psrlq m6, 32
55+ paddw m6, m5
56+ mova m5, m6
57+ psrlq m6, 16
58+ paddw m6, m5
59+ movd eax, m6
60+ and eax, 0xffff
61+ RET
62+
63+INIT_MMX mmx
64+; int ff_pix_norm1_mmx(uint8_t *pix, int line_size)
65+cglobal pix_norm1, 2, 4
66+ movsxdifnidn r1, r1d
67+ mov r2, 16
68+ pxor m0, m0
69+ pxor m7, m7
70+.loop:
71+ mova m2, [r0+0]
72+ mova m3, [r0+8]
73+ mova m1, m2
74+ punpckhbw m1, m0
75+ punpcklbw m2, m0
76+ mova m4, m3
77+ punpckhbw m3, m0
78+ punpcklbw m4, m0
79+ pmaddwd m1, m1
80+ pmaddwd m2, m2
81+ pmaddwd m3, m3
82+ pmaddwd m4, m4
83+ paddd m2, m1
84+ paddd m4, m3
85+ paddd m7, m2
86+ add r0, r1
87+ paddd m7, m4
88+ dec r2
89+ jne .loop
90+ mova m1, m7
91+ psrlq m7, 32
92+ paddd m1, m7
93+ movd eax, m1
94+ RET
95+
libavcodec/x86/mpegvideoencdsp_init.c+10−1
@@ -22,6 +22,9 @@ · 21 unmodified lines
2222 #include "libavcodec/avcodec.h"
2323 #include "libavcodec/mpegvideoencdsp.h"
2424
25+int ff_pix_sum16_mmx(uint8_t *pix, int line_size);
26+int ff_pix_norm1_mmx(uint8_t *pix, int line_size);
27+
2528 #if HAVE_INLINE_ASM
2629
2730 #define PHADDD(a, t) \
@@ -95,9 +98,15 @@ · 67 unmodified lines
9598 av_cold void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c,
9699 AVCodecContext *avctx)
97100 {
98−#if HAVE_INLINE_ASM
99101 int cpu_flags = av_get_cpu_flags();
100102
103+ if (EXTERNAL_MMX(cpu_flags)) {
104+ c->pix_sum = ff_pix_sum16_mmx;
105+ c->pix_norm1 = ff_pix_norm1_mmx;
106+ }
107+
108+#if HAVE_INLINE_ASM
109+
101110 if (INLINE_MMX(cpu_flags)) {
102111 if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
103112 c->try_8x8basis = try_8x8basis_mmx;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t