hevc/sao: use aligned copies
ffmpeg | branch: master | Christophe Gisquet <christophe.gisquet@gmail.com> | Sun Feb 1 15:34:41 2015 -0300| [6a6aeb538b4bb3a7afac35bf807dd34a391a21e8] | committer: James Almer hevc/sao: use aligned copies For band filter, source and destination are aligned (except for 16x16 ctbs), and otherwise, they are most often aligned. Overall, the total width is also too small for amortizing memcpy. Timings (using an intrinsic version of edge filters): B/32 B/64 E/32 E/64 Before: 32045 93952 38925 126896 After: 26772 83803 33942 117182
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6a6aeb538b4bb3a7af...
libavcodec/hevc_filter.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 9354c14..7a0ec6d 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -139,15 +139,25 @@ static int get_qPy(HEVCContext *s, int xC, int yC) return s->qp_y_tab[x + y * s->sps->min_cb_width]; } -static void copy_CTB(uint8_t *dst, uint8_t *src, - int width, int height, int stride_dst, int stride_src) +static void copy_CTB(uint8_t *dst, uint8_t *src, int width, int height, + intptr_t stride_dst, intptr_t stride_src) { - int i; - - for (i = 0; i < height; i++) { - memcpy(dst, src, width); - dst += stride_dst; - src += stride_src; +int i, j; + + if (((intptr_t)dst | (intptr_t)src | stride_dst | stride_src) & 15) { + for (i = 0; i < height; i++) { + for (j = 0; j < width; j+=8) + AV_COPY64(dst+j, src+j); + dst += stride_dst; + src += stride_src; + } + } else { + for (i = 0; i < height; i++) { + for (j = 0; j < width; j+=16) + AV_COPY128(dst+j, src+j); + dst += stride_dst; + src += stride_src; + } } }
Christophe Gisquet <git <at> videolan.org> writes:
hevc/sao: use aligned copies
This makes reading hevc files crash if compiled with icc 14.0.2 on Linux: http://fate.ffmpeg.org/history.cgi?slot=x86_64-linux-gnu-icc-2013_sp1.0.080 Program received signal SIGSEGV, Segmentation fault. 0x000000000048af01 in copy_CTB (dst=<optimized out>, src=0x7ffff67ed07f, width=<optimized out>, height=<optimized out>, stride_dst=<optimized out>, stride_src=<optimized out>) at libavcodec/hevc_filter.c:150 150 AV_COPY64(dst+j, src+j); AV_COPY64() in libavutil/x86/intreadwrite.h looks like this: __asm__("movq %1, %%mm0 \n\t" "movq %%mm0, %0 \n\t" : "=m"(*(uint64_t*)d) : "m" (*(const uint64_t*)s) : "mm0"); (gdb) disass $pc-32,$pc+32 0x000000000048aee1 <sao_filter_CTB+4209>: test $0xf,%edi 0x000000000048aee7 <sao_filter_CTB+4215>: je 0x48af0b <sao_filter_CTB+4251> 0x000000000048aee9 <sao_filter_CTB+4217>: lea 0x0(,%r12,8),%r15d 0x000000000048aef1 <sao_filter_CTB+4225>: add $0x2,%r12d 0x000000000048aef5 <sao_filter_CTB+4229>: movslq %r15d,%r15 0x000000000048aef8 <sao_filter_CTB+4232>: cmp %r13d,%r12d 0x000000000048aefb <sao_filter_CTB+4235>: movdqu (%r15,%r8,1),%xmm0 => 0x000000000048af01 <sao_filter_CTB+4241>: movdqa %xmm0,(%r15,%r9,1) 0x000000000048af07 <sao_filter_CTB+4247>: jb 0x48aee9 <sao_filter_CTB+4217> 0x000000000048af09 <sao_filter_CTB+4249>: jmp 0x48af2b <sao_filter_CTB+4283> 0x000000000048af0b <sao_filter_CTB+4251>: lea 0x0(,%r12,8),%r15d 0x000000000048af13 <sao_filter_CTB+4259>: add $0x2,%r12d 0x000000000048af17 <sao_filter_CTB+4263>: movslq %r15d,%r15 0x000000000048af1a <sao_filter_CTB+4266>: cmp %r13d,%r12d 0x000000000048af1d <sao_filter_CTB+4269>: movdqa (%r15,%r8,1),%xmm0 (gdb) info register rax 0x4 4 rbx 0x1 1 rcx 0x42 66 rdx 0x9 9 rsi 0xa00 2560 rdi 0x0 0 rbp 0x0 0x0 rsp 0x7fffffffc9b0 0x7fffffffc9b0 r8 0x7ffff67ed07f 140737328894079 r9 0x7ffff6de2adf 140737335143135 r10 0x49 73 r11 0xa40 2624 r12 0x3 3 r13 0x9 9 r14 0x40 64 r15 0x8 8 rip 0x48af01 0x48af01 <sao_filter_CTB+4241> eflags 0x10297 [ CF PF AF SF IF RF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 ymm0 v2_int128 = {0x1b1b1b1b1b1c1c1c1d1d1d1d1d1e1f25, 0x00000000000000000000000000000000} Note that I do not know where to report icc bugs. Carl Eugen
Carl Eugen Hoyos <cehoyos <at> ag.or.at> writes:
Christophe Gisquet <git <at> videolan.org> writes:
hevc/sao: use aligned copies
This makes reading hevc files crash if compiled with icc 14.0.2 on Linux:
I believe this issue was fixed by James Almer in 5c8f7470 Thank you, Carl Eugen
participants (2)
-
Carl Eugen Hoyos -
git@videolan.org