History

avcodec/x86/mpegvideoencdsp: speed up draw_edges_mmx by using memcpy()

The mmx memory copy code is not nearly as efficient as memcpy(), which would make draw_edges_mmx much slower than draw_edges_8_c. Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz: before after draw_edges_8_1724_4_mmx: 8700.5 8751.8 ( 0.99x) draw_edges_8_1724_8_mmx: 10441.7 10558.0 ( 0.99x) draw_edges_8_1724_16_mmx: 10660.7 10799.5 ( 0.99x) draw_edges_128_407_4_mmx: 4202.2 4099.3 ( 1.03x) draw_edges_128_407_8_mmx: 4579.0 4511.3 ( 1.02x) draw_edges_128_407_16_mmx: 5479.7 4729.5 ( 1.16x) draw_edges_1080_31_4_mmx: 1546.7 658.0 ( 2.35x) draw_edges_1080_31_8_mmx: 2745.5 1442.5 ( 1.90x) draw_edges_1080_31_16_mmx: 12511.5 4901.0 ( 2.55x) draw_edges_1920_4_4_mmx: 2659.0 705.0 ( 3.77x) draw_edges_1920_4_4_negstride_mmx: 2643.0 729.0 ( 3.63x) draw_edges_1920_4_8_mmx: 7845.0 2819.0 ( 2.78x) draw_edges_1920_4_8_negstride_mmx: 7777.0 2747.3 ( 2.83x) draw_edges_1920_4_16_mmx: 24583.7 6358.3 ( 3.87x) draw_edges_1920_4_16_negstride_mmx: 24589.0 6367.0 ( 3.86x)

Ramiro Polla committed 2 years ago

Commit 3bfce2a1 parent 9cdcbb61 file · +11 −41Browse files

Unified · Split

libavcodec/x86/mpegvideoencdsp_init.c+11−41
@@ -102,7 +102,6 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, · 101 unmodified lines
102102 uint8_t *ptr, *last_line;
103103 int i;
104104
105− last_line = buf + (height - 1) * wrap;
106105 /* left and right */
107106 ptr = buf;
108107 if (w == 8) {
@@ -166,46 +165,17 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, · 57 unmodified lines
166165 "r" (ptr + wrap * height));
167166 }
168167
169− /* top and bottom (and hopefully also the corners) */
170− if (sides & EDGE_TOP) {
171− for (i = 0; i < h; i += 4) {
172− ptr = buf - (i + 1) * wrap - w;
173− __asm__ volatile (
174− "1: \n\t"
175− "movq (%1, %0), %%mm0 \n\t"
176− "movq %%mm0, (%0) \n\t"
177− "movq %%mm0, (%0, %2) \n\t"
178− "movq %%mm0, (%0, %2, 2) \n\t"
179− "movq %%mm0, (%0, %3) \n\t"
180− "add $8, %0 \n\t"
181− "cmp %4, %0 \n\t"
182− "jb 1b \n\t"
183− : "+r" (ptr)
184− : "r" ((x86_reg) buf - (x86_reg) ptr - w),
185− "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
186− "r" (ptr + width + 2 * w));
187− }
188− }
189−
190− if (sides & EDGE_BOTTOM) {
191− for (i = 0; i < h; i += 4) {
192− ptr = last_line + (i + 1) * wrap - w;
193− __asm__ volatile (
194− "1: \n\t"
195− "movq (%1, %0), %%mm0 \n\t"
196− "movq %%mm0, (%0) \n\t"
197− "movq %%mm0, (%0, %2) \n\t"
198− "movq %%mm0, (%0, %2, 2) \n\t"
199− "movq %%mm0, (%0, %3) \n\t"
200− "add $8, %0 \n\t"
201− "cmp %4, %0 \n\t"
202− "jb 1b \n\t"
203− : "+r" (ptr)
204− : "r" ((x86_reg) last_line - (x86_reg) ptr - w),
205− "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
206− "r" (ptr + width + 2 * w));
207− }
208− }
168+ /* top and bottom + corners */
169+ buf -= w;
170+ last_line = buf + (height - 1) * wrap;
171+ if (sides & EDGE_TOP)
172+ for (i = 0; i < h; i++)
173+ // top
174+ memcpy(buf - (i + 1) * wrap, buf, width + w + w);
175+ if (sides & EDGE_BOTTOM)
176+ for (i = 0; i < h; i++)
177+ // bottom
178+ memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
209179 }
210180
211181 #endif /* HAVE_INLINE_ASM */

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