History

dsputil: Split off *_8x8basis to a separate context

Diego Biurrun committed 12 years ago

Commit 8d686ca1 parent a7985cf11 files · +245 −125Browse files

Unified · Split

11 files
  1. libavcodec/Makefile +2 −1
  2. libavcodec/dsputil.c +0 −32
  3. libavcodec/dsputil.h +0 −6
  4. libavcodec/mpegvideo.h +2 −0
  5. libavcodec/mpegvideo_enc.c +8 −5
  6. libavcodec/mpegvideoencdsp.c +64 −0
  7. libavcodec/mpegvideoencdsp.h +41 −0
  8. libavcodec/x86/Makefile +2 −1
  9. libavcodec/x86/dsputilenc_mmx.c +0 −79
  10. libavcodec/x86/mpegvideoenc_qns_template.c +1 −1
  11. libavcodec/x86/mpegvideoencdsp_init.c +125 −0
libavcodec/Makefile+2−1
@@ -67,7 +67,8 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ · 66 unmodified lines
6767 OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideodsp.o \
6868 mpegvideo_motion.o mpegutils.o
6969 OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
70− motion_est.o ratecontrol.o
70+ motion_est.o ratecontrol.o \
71+ mpegvideoencdsp.o
7172 OBJS-$(CONFIG_QPELDSP) += qpeldsp.o
7273 OBJS-$(CONFIG_RANGECODER) += rangecoder.o
7374 RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o
libavcodec/dsputil.c+0−32
@@ -464,35 +464,6 @@ static int nsse8_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, int stride, int · 463 unmodified lines
464464 return score1 + FFABS(score2) * 8;
465465 }
466466
467−static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
468− int16_t basis[64], int scale)
469−{
470− int i;
471− unsigned int sum = 0;
472−
473− for (i = 0; i < 8 * 8; i++) {
474− int b = rem[i] + ((basis[i] * scale +
475− (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
476− (BASIS_SHIFT - RECON_SHIFT));
477− int w = weight[i];
478− b >>= RECON_SHIFT;
479− assert(-512 < b && b < 512);
480−
481− sum += (w * b) * (w * b) >> 4;
482− }
483− return sum >> 2;
484−}
485−
486−static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
487−{
488− int i;
489−
490− for (i = 0; i < 8 * 8; i++)
491− rem[i] += (basis[i] * scale +
492− (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
493− (BASIS_SHIFT - RECON_SHIFT);
494−}
495−
496467 static int zero_cmp(MpegEncContext *s, uint8_t *a, uint8_t *b,
497468 int stride, int h)
498469 {
@@ -1126,9 +1097,6 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx) · 627 unmodified lines
11261097 c->nsse[0] = nsse16_c;
11271098 c->nsse[1] = nsse8_c;
11281099
1129− c->try_8x8basis = try_8x8basis_c;
1130− c->add_8x8basis = add_8x8basis_c;
1131−
11321100 c->shrink[0] = av_image_copy_plane;
11331101 c->shrink[1] = ff_shrink22;
11341102 c->shrink[2] = ff_shrink44;
libavcodec/dsputil.h+0−6
@@ -87,12 +87,6 @@ typedef struct DSPContext { · 86 unmodified lines
8787 void (*fdct)(int16_t *block /* align 16 */);
8888 void (*fdct248)(int16_t *block /* align 16 */);
8989
90− int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
91− int16_t basis[64], int scale);
92− void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
93−#define BASIS_SHIFT 16
94−#define RECON_SHIFT 6
95−
9690 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
9791 int w, int h, int sides);
9892 #define EDGE_WIDTH 16
libavcodec/mpegvideo.h+2−0
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #include "hpeldsp.h"
3838 #include "idctdsp.h"
3939 #include "mpegvideodsp.h"
40+#include "mpegvideoencdsp.h"
4041 #include "put_bits.h"
4142 #include "ratecontrol.h"
4243 #include "parser.h"
@@ -355,6 +356,7 @@ typedef struct MpegEncContext { · 312 unmodified lines
355356 HpelDSPContext hdsp;
356357 IDCTDSPContext idsp;
357358 MpegVideoDSPContext mdsp;
359+ MpegvideoEncDSPContext mpvencdsp;
358360 QpelDSPContext qdsp;
359361 VideoDSPContext vdsp;
360362 H263DSPContext h263dsp;
libavcodec/mpegvideo_enc.c+8−5
@@ -701,6 +701,7 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 700 unmodified lines
701701 if (ARCH_X86)
702702 ff_MPV_encode_init_x86(s);
703703
704+ ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
704705 ff_qpeldsp_init(&s->qdsp);
705706
706707 s->avctx->coded_frame = s->current_picture.f;
@@ -3871,7 +3872,7 @@ STOP_TIMER("memset rem[]")} · 3164 unmodified lines
38713872 run_tab[rle_index++]=run;
38723873 run=0;
38733874
3874− s->dsp.add_8x8basis(rem, basis[j], coeff);
3875+ s->mpvencdsp.add_8x8basis(rem, basis[j], coeff);
38753876 }else{
38763877 run++;
38773878 }
@@ -3885,7 +3886,7 @@ STOP_TIMER("init rem[]") · 7 unmodified lines
38853886 {START_TIMER
38863887 #endif
38873888 for(;;){
3888− int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0);
3889+ int best_score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0], 0);
38893890 int best_coeff=0;
38903891 int best_change=0;
38913892 int run2, best_unquant_change=0, analyze_gradient;
@@ -3929,7 +3930,8 @@ STOP_TIMER("dct")} · 37 unmodified lines
39293930 if(new_coeff >= 2048 || new_coeff < 0)
39303931 continue;
39313932
3932− score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
3933+ score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0],
3934+ new_coeff - old_coeff);
39333935 if(score<best_score){
39343936 best_score= score;
39353937 best_coeff= 0;
@@ -4052,7 +4054,8 @@ STOP_TIMER("dct")} · 116 unmodified lines
40524054 unquant_change= new_coeff - old_coeff;
40534055 assert((score < 100*lambda && score > -100*lambda) || lambda==0);
40544056
4055− score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change);
4057+ score += s->mpvencdsp.try_8x8basis(rem, weight, basis[j],
4058+ unquant_change);
40564059 if(score<best_score){
40574060 best_score= score;
40584061 best_coeff= i;
@@ -4126,7 +4129,7 @@ if(256*256*256*64 % count == 0){ · 67 unmodified lines
41264129 }
41274130 }
41284131
4129− s->dsp.add_8x8basis(rem, basis[j], best_unquant_change);
4132+ s->mpvencdsp.add_8x8basis(rem, basis[j], best_unquant_change);
41304133 }else{
41314134 break;
41324135 }
libavcodec/mpegvideoencdsp.c+64−0
@@ -0,0 +1,64 @@
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 <assert.h>
20+#include <stdint.h>
21+
22+#include "config.h"
23+#include "libavutil/attributes.h"
24+#include "avcodec.h"
25+#include "mpegvideoencdsp.h"
26+
27+static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
28+ int16_t basis[64], int scale)
29+{
30+ int i;
31+ unsigned int sum = 0;
32+
33+ for (i = 0; i < 8 * 8; i++) {
34+ int b = rem[i] + ((basis[i] * scale +
35+ (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
36+ (BASIS_SHIFT - RECON_SHIFT));
37+ int w = weight[i];
38+ b >>= RECON_SHIFT;
39+ assert(-512 < b && b < 512);
40+
41+ sum += (w * b) * (w * b) >> 4;
42+ }
43+ return sum >> 2;
44+}
45+
46+static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
47+{
48+ int i;
49+
50+ for (i = 0; i < 8 * 8; i++)
51+ rem[i] += (basis[i] * scale +
52+ (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
53+ (BASIS_SHIFT - RECON_SHIFT);
54+}
55+
56+av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
57+ AVCodecContext *avctx)
58+{
59+ c->try_8x8basis = try_8x8basis_c;
60+ c->add_8x8basis = add_8x8basis_c;
61+
62+ if (ARCH_X86)
63+ ff_mpegvideoencdsp_init_x86(c, avctx);
64+}
libavcodec/mpegvideoencdsp.h+41−0
@@ -0,0 +1,41 @@
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+#ifndef AVCODEC_MPEGVIDEOENCDSP_H
20+#define AVCODEC_MPEGVIDEOENCDSP_H
21+
22+#include <stdint.h>
23+
24+#include "avcodec.h"
25+
26+#define BASIS_SHIFT 16
27+#define RECON_SHIFT 6
28+
29+typedef struct MpegvideoEncDSPContext {
30+ int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
31+ int16_t basis[64], int scale);
32+ void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
33+
34+} MpegvideoEncDSPContext;
35+
36+void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
37+ AVCodecContext *avctx);
38+void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c,
39+ AVCodecContext *avctx);
40+
41+#endif /* AVCODEC_MPEGVIDEOENCDSP_H */
libavcodec/x86/Makefile+2−1
@@ -23,7 +23,8 @@ OBJS-$(CONFIG_LPC) += x86/lpc.o · 22 unmodified lines
2323 OBJS-$(CONFIG_MPEGAUDIODSP) += x86/mpegaudiodsp.o
2424 OBJS-$(CONFIG_MPEGVIDEO) += x86/mpegvideo.o \
2525 x86/mpegvideodsp.o
26−OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoenc.o
26+OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoenc.o \
27+ x86/mpegvideoencdsp_init.o
2728 OBJS-$(CONFIG_QPELDSP) += x86/qpeldsp_init.o
2829 OBJS-$(CONFIG_VIDEODSP) += x86/videodsp_init.o
2930 OBJS-$(CONFIG_VP3DSP) += x86/vp3dsp_init.o
libavcodec/x86/dsputilenc_mmx.c+0−79
@@ -805,72 +805,6 @@ DCT_SAD_FUNC(ssse3) · 804 unmodified lines
805805 #undef HSUM
806806 #undef DCT_SAD
807807
808−#define PHADDD(a, t) \
809− "movq " #a ", " #t " \n\t" \
810− "psrlq $32, " #a " \n\t" \
811− "paddd " #t ", " #a " \n\t"
812−
813−/*
814− * pmulhw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15])[16 - 31]
815− * pmulhrw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15] + 0x8000)[16 - 31]
816− * pmulhrsw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15] + 0x4000)[15 - 30]
817− */
818−#define PMULHRW(x, y, s, o) \
819− "pmulhw " #s ", " #x " \n\t" \
820− "pmulhw " #s ", " #y " \n\t" \
821− "paddw " #o ", " #x " \n\t" \
822− "paddw " #o ", " #y " \n\t" \
823− "psraw $1, " #x " \n\t" \
824− "psraw $1, " #y " \n\t"
825−#define DEF(x) x ## _mmx
826−#define SET_RND MOVQ_WONE
827−#define SCALE_OFFSET 1
828−
829−#include "dsputil_qns_template.c"
830−
831−#undef DEF
832−#undef SET_RND
833−#undef SCALE_OFFSET
834−#undef PMULHRW
835−
836−#define DEF(x) x ## _3dnow
837−#define SET_RND(x)
838−#define SCALE_OFFSET 0
839−#define PMULHRW(x, y, s, o) \
840− "pmulhrw " #s ", " #x " \n\t" \
841− "pmulhrw " #s ", " #y " \n\t"
842−
843−#include "dsputil_qns_template.c"
844−
845−#undef DEF
846−#undef SET_RND
847−#undef SCALE_OFFSET
848−#undef PMULHRW
849−
850−#if HAVE_SSSE3_INLINE
851−#undef PHADDD
852−#define DEF(x) x ## _ssse3
853−#define SET_RND(x)
854−#define SCALE_OFFSET -1
855−
856−#define PHADDD(a, t) \
857− "pshufw $0x0E, " #a ", " #t " \n\t" \
858− /* faster than phaddd on core2 */ \
859− "paddd " #t ", " #a " \n\t"
860−
861−#define PMULHRW(x, y, s, o) \
862− "pmulhrsw " #s ", " #x " \n\t" \
863− "pmulhrsw " #s ", " #y " \n\t"
864−
865−#include "dsputil_qns_template.c"
866−
867−#undef DEF
868−#undef SET_RND
869−#undef SCALE_OFFSET
870−#undef PMULHRW
871−#undef PHADDD
872−#endif /* HAVE_SSSE3_INLINE */
873−
874808 #endif /* HAVE_INLINE_ASM */
875809
876810 int ff_sse16_sse2(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
@@ -921,16 +855,7 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx, · 44 unmodified lines
921855 c->nsse[1] = nsse8_mmx;
922856 if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
923857 c->vsad[0] = vsad16_mmx;
924− c->try_8x8basis = try_8x8basis_mmx;
925− }
926− c->add_8x8basis = add_8x8basis_mmx;
927− }
928−
929− if (INLINE_AMD3DNOW(cpu_flags)) {
930− if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
931− c->try_8x8basis = try_8x8basis_3dnow;
932858 }
933− c->add_8x8basis = add_8x8basis_3dnow;
934859 }
935860
936861 if (INLINE_MMXEXT(cpu_flags)) {
@@ -956,10 +881,6 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx, · 19 unmodified lines
956881
957882 #if HAVE_SSSE3_INLINE
958883 if (INLINE_SSSE3(cpu_flags)) {
959− if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
960− c->try_8x8basis = try_8x8basis_ssse3;
961− }
962− c->add_8x8basis = add_8x8basis_ssse3;
963884 c->sum_abs_dctelem = sum_abs_dctelem_ssse3;
964885 }
965886 #endif
libavcodec/x86/mpegvideoenc_qns_template.crenamed from libavcodec/x86/dsputil_qns_template.c+1−1
@@ -1,5 +1,5 @@
11 /*
2− * DSP utils : QNS functions are compiled 3 times for mmx/3dnow/ssse3
2+ * QNS functions are compiled 3 times for MMX/3DNOW/SSSE3
33 * Copyright (c) 2004 Michael Niedermayer
44 *
55 * MMX optimization by Michael Niedermayer <michaelni@gmx.at>
libavcodec/x86/mpegvideoencdsp_init.c+125−0
@@ -0,0 +1,125 @@
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 "libavutil/attributes.h"
20+#include "libavutil/cpu.h"
21+#include "libavutil/x86/cpu.h"
22+#include "libavcodec/avcodec.h"
23+#include "libavcodec/mpegvideoencdsp.h"
24+
25+#if HAVE_INLINE_ASM
26+
27+#define PHADDD(a, t) \
28+ "movq " #a ", " #t " \n\t" \
29+ "psrlq $32, " #a " \n\t" \
30+ "paddd " #t ", " #a " \n\t"
31+
32+/*
33+ * pmulhw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15])[16 - 31]
34+ * pmulhrw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15] + 0x8000)[16 - 31]
35+ * pmulhrsw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15] + 0x4000)[15 - 30]
36+ */
37+#define PMULHRW(x, y, s, o) \
38+ "pmulhw " #s ", " #x " \n\t" \
39+ "pmulhw " #s ", " #y " \n\t" \
40+ "paddw " #o ", " #x " \n\t" \
41+ "paddw " #o ", " #y " \n\t" \
42+ "psraw $1, " #x " \n\t" \
43+ "psraw $1, " #y " \n\t"
44+#define DEF(x) x ## _mmx
45+#define SET_RND MOVQ_WONE
46+#define SCALE_OFFSET 1
47+
48+#include "mpegvideoenc_qns_template.c"
49+
50+#undef DEF
51+#undef SET_RND
52+#undef SCALE_OFFSET
53+#undef PMULHRW
54+
55+#define DEF(x) x ## _3dnow
56+#define SET_RND(x)
57+#define SCALE_OFFSET 0
58+#define PMULHRW(x, y, s, o) \
59+ "pmulhrw " #s ", " #x " \n\t" \
60+ "pmulhrw " #s ", " #y " \n\t"
61+
62+#include "mpegvideoenc_qns_template.c"
63+
64+#undef DEF
65+#undef SET_RND
66+#undef SCALE_OFFSET
67+#undef PMULHRW
68+
69+#if HAVE_SSSE3_INLINE
70+#undef PHADDD
71+#define DEF(x) x ## _ssse3
72+#define SET_RND(x)
73+#define SCALE_OFFSET -1
74+
75+#define PHADDD(a, t) \
76+ "pshufw $0x0E, " #a ", " #t " \n\t" \
77+ /* faster than phaddd on core2 */ \
78+ "paddd " #t ", " #a " \n\t"
79+
80+#define PMULHRW(x, y, s, o) \
81+ "pmulhrsw " #s ", " #x " \n\t" \
82+ "pmulhrsw " #s ", " #y " \n\t"
83+
84+#include "mpegvideoenc_qns_template.c"
85+
86+#undef DEF
87+#undef SET_RND
88+#undef SCALE_OFFSET
89+#undef PMULHRW
90+#undef PHADDD
91+#endif /* HAVE_SSSE3_INLINE */
92+
93+#endif /* HAVE_INLINE_ASM */
94+
95+av_cold void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c,
96+ AVCodecContext *avctx)
97+{
98+#if HAVE_INLINE_ASM
99+ int cpu_flags = av_get_cpu_flags();
100+
101+ if (INLINE_MMX(cpu_flags)) {
102+ if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
103+ c->try_8x8basis = try_8x8basis_mmx;
104+ }
105+ c->add_8x8basis = add_8x8basis_mmx;
106+ }
107+
108+ if (INLINE_AMD3DNOW(cpu_flags)) {
109+ if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
110+ c->try_8x8basis = try_8x8basis_3dnow;
111+ }
112+ c->add_8x8basis = add_8x8basis_3dnow;
113+ }
114+
115+#if HAVE_SSSE3_INLINE
116+ if (INLINE_SSSE3(cpu_flags)) {
117+ if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
118+ c->try_8x8basis = try_8x8basis_ssse3;
119+ }
120+ c->add_8x8basis = add_8x8basis_ssse3;
121+ }
122+#endif /* HAVE_SSSE3_INLINE */
123+
124+#endif /* HAVE_INLINE_ASM */
125+}

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