[FFmpeg-devel] [PATCH v2 3/4] swscale/x86: add avx2 {lum, chr}ConvertRange
Ramiro Polla
ramiro.polla at gmail.com
Tue Jun 11 15:28:57 EEST 2024
chrRangeFromJpeg_8_c: 24.1
chrRangeFromJpeg_8_sse4: 16.1
chrRangeFromJpeg_8_avx2: 19.9
chrRangeFromJpeg_24_c: 72.6
chrRangeFromJpeg_24_sse4: 34.6
chrRangeFromJpeg_24_avx2: 30.9
chrRangeFromJpeg_128_c: 341.1
chrRangeFromJpeg_128_sse4: 160.9
chrRangeFromJpeg_128_avx2: 94.1
chrRangeFromJpeg_144_c: 381.9
chrRangeFromJpeg_144_sse4: 183.6
chrRangeFromJpeg_144_avx2: 108.9
chrRangeFromJpeg_256_c: 646.1
chrRangeFromJpeg_256_sse4: 320.4
chrRangeFromJpeg_256_avx2: 190.6
chrRangeFromJpeg_512_c: 1255.9
chrRangeFromJpeg_512_sse4: 654.1
chrRangeFromJpeg_512_avx2: 392.4
chrRangeToJpeg_8_c: 36.9
chrRangeToJpeg_8_sse4: 13.9
chrRangeToJpeg_8_avx2: 20.6
chrRangeToJpeg_24_c: 113.4
chrRangeToJpeg_24_sse4: 29.6
chrRangeToJpeg_24_avx2: 28.9
chrRangeToJpeg_128_c: 632.1
chrRangeToJpeg_128_sse4: 162.4
chrRangeToJpeg_128_avx2: 94.6
chrRangeToJpeg_144_c: 709.9
chrRangeToJpeg_144_sse4: 183.9
chrRangeToJpeg_144_avx2: 108.1
chrRangeToJpeg_256_c: 2672.9
chrRangeToJpeg_256_sse4: 334.4
chrRangeToJpeg_256_avx2: 190.6
chrRangeToJpeg_512_c: 2500.9
chrRangeToJpeg_512_sse4: 654.1
chrRangeToJpeg_512_avx2: 379.6
lumRangeFromJpeg_8_c: 10.9
lumRangeFromJpeg_8_sse4: 12.4
lumRangeFromJpeg_8_avx2: 17.6
lumRangeFromJpeg_24_c: 38.4
lumRangeFromJpeg_24_sse4: 16.9
lumRangeFromJpeg_24_avx2: 20.6
lumRangeFromJpeg_128_c: 233.6
lumRangeFromJpeg_128_sse4: 79.9
lumRangeFromJpeg_128_avx2: 51.6
lumRangeFromJpeg_144_c: 263.9
lumRangeFromJpeg_144_sse4: 90.1
lumRangeFromJpeg_144_avx2: 57.6
lumRangeFromJpeg_256_c: 436.9
lumRangeFromJpeg_256_sse4: 162.1
lumRangeFromJpeg_256_avx2: 100.6
lumRangeFromJpeg_512_c: 878.4
lumRangeFromJpeg_512_sse4: 335.1
lumRangeFromJpeg_512_avx2: 199.4
lumRangeToJpeg_8_c: 19.1
lumRangeToJpeg_8_sse4: 11.6
lumRangeToJpeg_8_avx2: 17.6
lumRangeToJpeg_24_c: 56.9
lumRangeToJpeg_24_sse4: 17.6
lumRangeToJpeg_24_avx2: 21.4
lumRangeToJpeg_128_c: 335.9
lumRangeToJpeg_128_sse4: 79.1
lumRangeToJpeg_128_avx2: 48.9
lumRangeToJpeg_144_c: 372.9
lumRangeToJpeg_144_sse4: 91.6
lumRangeToJpeg_144_avx2: 55.4
lumRangeToJpeg_256_c: 651.9
lumRangeToJpeg_256_sse4: 163.6
lumRangeToJpeg_256_avx2: 99.1
lumRangeToJpeg_512_c: 1289.9
lumRangeToJpeg_512_sse4: 333.6
lumRangeToJpeg_512_avx2: 211.1
---
libswscale/x86/range_convert.asm | 46 ++++++++++++++++++++++++++------
libswscale/x86/swscale.c | 5 +++-
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/libswscale/x86/range_convert.asm b/libswscale/x86/range_convert.asm
index 13983a386b..54c2f64769 100644
--- a/libswscale/x86/range_convert.asm
+++ b/libswscale/x86/range_convert.asm
@@ -22,20 +22,20 @@
SECTION_RODATA
-chr_to_mult: times 4 dd 4663
-chr_to_offset: times 4 dd -9289992
+chr_to_mult: times 8 dd 4663
+chr_to_offset: times 8 dd -9289992
%define chr_to_shift 12
-chr_from_mult: times 4 dd 1799
-chr_from_offset: times 4 dd 4081085
+chr_from_mult: times 8 dd 1799
+chr_from_offset: times 8 dd 4081085
%define chr_from_shift 11
-lum_to_mult: times 4 dd 19077
-lum_to_offset: times 4 dd -39057361
+lum_to_mult: times 8 dd 19077
+lum_to_offset: times 8 dd -39057361
%define lum_to_shift 14
-lum_from_mult: times 4 dd 14071
-lum_from_offset: times 4 dd 33561947
+lum_from_mult: times 8 dd 14071
+lum_from_offset: times 8 dd 33561947
%define lum_from_shift 14
SECTION .text
@@ -66,10 +66,19 @@ cglobal %1, 2, 3, 3, dst, width, x
paddd m1, m5
psrad m0, %4
psrad m1, %4
+%if mmsize == 16
packssdw m0, m0
packssdw m1, m1
movq [dstq+xq*2], m0
movq [dstq+xq*2+mmsize/2], m1
+%else
+ vextracti128 xm7, ym0, 1
+ packssdw xm0, xm7
+ vextracti128 xm7, ym1, 1
+ packssdw xm1, xm7
+ movdqu [dstq+xq*2], xm0
+ movdqu [dstq+xq*2+mmsize/2], xm1
+%endif
add xq, mmsize / 2
cmp xd, widthd
jl .loop
@@ -107,6 +116,7 @@ cglobal %1, 3, 4, 4, dstU, dstV, width, x
psrad m1, %4
psrad m2, %4
psrad m3, %4
+%if mmsize == 16
packssdw m0, m0
packssdw m1, m1
packssdw m2, m2
@@ -115,6 +125,20 @@ cglobal %1, 3, 4, 4, dstU, dstV, width, x
movq [dstUq+xq*2+mmsize/2], m1
movq [dstVq+xq*2], m2
movq [dstVq+xq*2+mmsize/2], m3
+%else
+ vextracti128 xm7, ym0, 1
+ packssdw xm0, xm7
+ vextracti128 xm7, ym1, 1
+ packssdw xm1, xm7
+ vextracti128 xm7, ym2, 1
+ packssdw xm2, xm7
+ vextracti128 xm7, ym3, 1
+ packssdw xm3, xm7
+ movdqu [dstUq+xq*2], xm0
+ movdqu [dstUq+xq*2+mmsize/2], xm1
+ movdqu [dstVq+xq*2], xm2
+ movdqu [dstVq+xq*2+mmsize/2], xm3
+%endif
add xq, mmsize / 2
cmp xd, widthd
jl .loop
@@ -127,4 +151,10 @@ LUMCONVERTRANGE lumRangeToJpeg, lum_to_mult, lum_to_offset, lum_to_shift
CHRCONVERTRANGE chrRangeToJpeg, chr_to_mult, chr_to_offset, chr_to_shift
LUMCONVERTRANGE lumRangeFromJpeg, lum_from_mult, lum_from_offset, lum_from_shift
CHRCONVERTRANGE chrRangeFromJpeg, chr_from_mult, chr_from_offset, chr_from_shift
+
+INIT_YMM avx2
+LUMCONVERTRANGE lumRangeToJpeg, lum_to_mult, lum_to_offset, lum_to_shift
+CHRCONVERTRANGE chrRangeToJpeg, chr_to_mult, chr_to_offset, chr_to_shift
+LUMCONVERTRANGE lumRangeFromJpeg, lum_from_mult, lum_from_offset, lum_from_shift
+CHRCONVERTRANGE chrRangeFromJpeg, chr_from_mult, chr_from_offset, chr_from_shift
%endif
diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
index 8f477b7b72..704e5f9c85 100644
--- a/libswscale/x86/swscale.c
+++ b/libswscale/x86/swscale.c
@@ -473,12 +473,15 @@ void ff_lumRangeToJpeg_ ##opt(int16_t *dst, int width); \
void ff_chrRangeToJpeg_ ##opt(int16_t *dstU, int16_t *dstV, int width); \
RANGE_CONVERT_FUNCS_DECL(sse4);
+RANGE_CONVERT_FUNCS_DECL(avx2);
av_cold void ff_sws_init_range_convert_x86(SwsContext *c)
{
if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
int cpu_flags = av_get_cpu_flags();
- if (EXTERNAL_SSE4(cpu_flags)) {
+ if (EXTERNAL_AVX2_FAST(cpu_flags)) {
+ RANGE_CONVERT_FUNCS(avx2);
+ } else if (EXTERNAL_SSE4(cpu_flags)) {
RANGE_CONVERT_FUNCS(sse4);
}
}
--
2.30.2
More information about the ffmpeg-devel
mailing list