Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] swscale/x86/input: add AVX2 optimized RGB24 to YUV functions
Date: Tue, 4 Jun 2024 21:25:05 +0200
Message-ID: <GV1P250MB0737977C9E4CBA9C19F1E5208FF82@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20240604190742.1742-1-jamrial@gmail.com>

James Almer:
> rgb24_to_uv_8_c: 39.3
> rgb24_to_uv_8_sse2: 14.3
> rgb24_to_uv_8_ssse3: 13.3
> rgb24_to_uv_8_avx: 12.8
> rgb24_to_uv_8_avx2: 14.3

Worse than avx and ssse3

> rgb24_to_uv_128_c: 582.8
> rgb24_to_uv_128_sse2: 127.3
> rgb24_to_uv_128_ssse3: 107.3
> rgb24_to_uv_128_avx: 111.3

Worse than ssse3

> rgb24_to_uv_128_avx2: 62.3
> rgb24_to_uv_1080_c: 4981.3
> rgb24_to_uv_1080_sse2: 1048.3
> rgb24_to_uv_1080_ssse3: 876.8
> rgb24_to_uv_1080_avx: 887.8

Worse than ssse3

> rgb24_to_uv_1080_avx2: 492.3
> rgb24_to_uv_1280_c: 5906.8
> rgb24_to_uv_1280_sse2: 1263.3
> rgb24_to_uv_1280_ssse3: 1048.3
> rgb24_to_uv_1280_avx: 1045.8

Not really better than ssse3

> rgb24_to_uv_1280_avx2: 579.8
> rgb24_to_uv_1920_c: 8665.3
> rgb24_to_uv_1920_sse2: 1888.8
> rgb24_to_uv_1920_ssse3: 1571.8
> rgb24_to_uv_1920_avx: 1558.8

Not really better than ssse3

> rgb24_to_uv_1920_avx2: 869.3
> rgb24_to_y_8_c: 20.3
> rgb24_to_y_8_sse2: 11.8
> rgb24_to_y_8_ssse3: 10.3
> rgb24_to_y_8_avx: 10.3

Not better than ssse3

> rgb24_to_y_8_avx2: 10.8

Worse than ssse3

> rgb24_to_y_128_c: 284.8
> rgb24_to_y_128_sse2: 83.3
> rgb24_to_y_128_ssse3: 66.8
> rgb24_to_y_128_avx: 64.8

Not really better than ssse3

> rgb24_to_y_128_avx2: 39.3
> rgb24_to_y_1080_c: 2451.3
> rgb24_to_y_1080_sse2: 696.3
> rgb24_to_y_1080_ssse3: 516.8
> rgb24_to_y_1080_avx: 518.8

Worse than ssse3

> rgb24_to_y_1080_avx2: 301.8
> rgb24_to_y_1280_c: 2892.8
> rgb24_to_y_1280_sse2: 816.8
> rgb24_to_y_1280_ssse3: 623.3
> rgb24_to_y_1280_avx: 616.3

Not really better than ssse3

> rgb24_to_y_1280_avx2: 350.8
> rgb24_to_y_1920_c: 4338.8
> rgb24_to_y_1920_sse2: 1210.8
> rgb24_to_y_1920_ssse3: 928.3
> rgb24_to_y_1920_avx: 920.3

Not really better than ssse3

> rgb24_to_y_1920_avx2: 534.8
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libswscale/x86/input.asm | 49 ++++++++++++++++++++++++++++++++++++----
>  libswscale/x86/swscale.c |  7 ++++++
>  2 files changed, 51 insertions(+), 5 deletions(-)
> 
> diff --git a/libswscale/x86/input.asm b/libswscale/x86/input.asm
> index a197183f1f..e79fe11405 100644
> --- a/libswscale/x86/input.asm
> +++ b/libswscale/x86/input.asm
> @@ -23,7 +23,7 @@
>  
>  %include "libavutil/x86/x86util.asm"
>  
> -SECTION_RODATA
> +SECTION_RODATA 32
>  
>  %define RY 0x20DE
>  %define GY 0x4087
> @@ -90,8 +90,12 @@ rgb_UVrnd:       times 4 dd 0x400100       ; 128.5 << 15
>  ; rgba_Vcoeff_ag:  times 4 dw 0,  GV
>  
>  shuf_rgb_12x4:   db 0, 0x80, 1, 0x80,  2, 0x80,  3, 0x80, \
> +                    6, 0x80, 7, 0x80,  8, 0x80,  9, 0x80, \
> +                    0, 0x80, 1, 0x80,  2, 0x80,  3, 0x80, \
>                      6, 0x80, 7, 0x80,  8, 0x80,  9, 0x80
>  shuf_rgb_3x56:   db 2, 0x80, 3, 0x80,  4, 0x80,  5, 0x80, \
> +                    8, 0x80, 9, 0x80, 10, 0x80, 11, 0x80, \
> +                    2, 0x80, 3, 0x80,  4, 0x80,  5, 0x80, \
>                      8, 0x80, 9, 0x80, 10, 0x80, 11, 0x80
>  pd_65535f:     times 8 dd 65535.0
>  pb_pack_shuffle16le:    db  0,  1,  4,  5, \
> @@ -134,8 +138,13 @@ SECTION .text
>  %macro RGB24_TO_Y_FN 2-3
>  cglobal %2 %+ 24ToY, 6, 6, %1, dst, src, u1, u2, w, table
>  %if ARCH_X86_64
> +%if mmsize == 32
> +    vbroadcasti128 m8, [%2_Ycoeff_12x4]
> +    vbroadcasti128 m9, [%2_Ycoeff_3x56]
> +%else
>      mova           m8, [%2_Ycoeff_12x4]
>      mova           m9, [%2_Ycoeff_3x56]
> +%endif
>  %define coeff1 m8
>  %define coeff2 m9
>  %else ; x86-32
> @@ -165,11 +174,19 @@ cglobal %2 %+ 24ToY, 6, 6, %1, dst, src, u1, u2, w, table
>  %if notcpuflag(ssse3)
>      pxor           m7, m7
>  %endif ; !cpuflag(ssse3)
> +%if mmsize == 32
> +    vbroadcasti128 m4, [rgb_Yrnd]
> +%else
>      mova           m4, [rgb_Yrnd]
> +%endif
>  .loop:
>  %if cpuflag(ssse3)
> -    movu           m0, [srcq+0]           ; (byte) { Bx, Gx, Rx }[0-3]
> -    movu           m2, [srcq+12]          ; (byte) { Bx, Gx, Rx }[4-7]
> +    movu          xm0, [srcq+0]           ; (byte) { Bx, Gx, Rx }[0-3]
> +    movu          xm2, [srcq+12]          ; (byte) { Bx, Gx, Rx }[4-7]
> +%if mmsize == 32
> +    vinserti128    m0, m0, [srcq+24], 1
> +    vinserti128    m2, m2, [srcq+36], 1
> +%endif
>      pshufb         m1, m0, shuf_rgb2      ; (word) { R0, B1, G1, R1, R2, B3, G3, R3 }
>      pshufb         m0, shuf_rgb1          ; (word) { B0, G0, R0, B1, B2, G2, R2, B3 }
>      pshufb         m3, m2, shuf_rgb2      ; (word) { R4, B5, G5, R5, R6, B7, G7, R7 }
> @@ -216,10 +233,17 @@ cglobal %2 %+ 24ToY, 6, 6, %1, dst, src, u1, u2, w, table
>  %macro RGB24_TO_UV_FN 2-3
>  cglobal %2 %+ 24ToUV, 7, 7, %1, dstU, dstV, u1, src, u2, w, table
>  %if ARCH_X86_64
> +%if mmsize == 32
> +    vbroadcasti128  m8, [%2_Ucoeff_12x4]
> +    vbroadcasti128  m9, [%2_Ucoeff_3x56]
> +    vbroadcasti128 m10, [%2_Vcoeff_12x4]
> +    vbroadcasti128 m11, [%2_Vcoeff_3x56]
> +%else
>      mova           m8, [%2_Ucoeff_12x4]
>      mova           m9, [%2_Ucoeff_3x56]
>      mova          m10, [%2_Vcoeff_12x4]
>      mova          m11, [%2_Vcoeff_3x56]
> +%endif
>  %define coeffU1 m8
>  %define coeffU2 m9
>  %define coeffV1 m10
> @@ -253,14 +277,22 @@ cglobal %2 %+ 24ToUV, 7, 7, %1, dstU, dstV, u1, src, u2, w, table
>      add         dstUq, wq
>      add         dstVq, wq
>      neg            wq
> +%if mmsize == 32
> +    vbroadcasti128 m6, [rgb_UVrnd]
> +%else
>      mova           m6, [rgb_UVrnd]
> +%endif
>  %if notcpuflag(ssse3)
>      pxor           m7, m7
>  %endif
>  .loop:
>  %if cpuflag(ssse3)
> -    movu           m0, [srcq+0]           ; (byte) { Bx, Gx, Rx }[0-3]
> -    movu           m4, [srcq+12]          ; (byte) { Bx, Gx, Rx }[4-7]
> +    movu          xm0, [srcq+0]           ; (byte) { Bx, Gx, Rx }[0-3]
> +    movu          xm4, [srcq+12]          ; (byte) { Bx, Gx, Rx }[4-7]
> +%if mmsize == 32
> +    vinserti128    m0, m0, [srcq+24], 1
> +    vinserti128    m4, m4, [srcq+36], 1
> +%endif
>      pshufb         m1, m0, shuf_rgb2      ; (word) { R0, B1, G1, R1, R2, B3, G3, R3 }
>      pshufb         m0, shuf_rgb1          ; (word) { B0, G0, R0, B1, B2, G2, R2, B3 }
>  %else ; !cpuflag(ssse3)
> @@ -337,6 +369,13 @@ INIT_XMM avx
>  RGB24_FUNCS 11, 13
>  %endif
>  
> +%if ARCH_X86_64
> +%if HAVE_AVX2_EXTERNAL
> +INIT_YMM avx2
> +RGB24_FUNCS 11, 13
> +%endif
> +%endif
> +
>  ; %1 = nr. of XMM registers
>  ; %2-5 = rgba, bgra, argb or abgr (in individual characters)
>  %macro RGB32_TO_Y_FN 5-6
> diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
> index fff8bb4396..1438c077e6 100644
> --- a/libswscale/x86/swscale.c
> +++ b/libswscale/x86/swscale.c
> @@ -321,6 +321,8 @@ void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
>  INPUT_FUNCS(sse2);
>  INPUT_FUNCS(ssse3);
>  INPUT_FUNCS(avx);
> +INPUT_FUNC(rgb24, avx2);
> +INPUT_FUNC(bgr24, avx2);
>  
>  #if ARCH_X86_64
>  #define YUV2NV_DECL(fmt, opt) \
> @@ -634,6 +636,11 @@ switch(c->dstBpc){ \
>      }
>  
>      if (EXTERNAL_AVX2_FAST(cpu_flags)) {
> +        if (ARCH_X86_64)
> +            switch (c->srcFormat) {
> +            case_rgb(rgb24, RGB24, avx2);
> +            case_rgb(bgr24, BGR24, avx2);
> +            }
>          switch (c->dstFormat) {
>          case AV_PIX_FMT_NV12:
>          case AV_PIX_FMT_NV24:

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2024-06-04 19:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 19:07 James Almer
2024-06-04 19:25 ` Andreas Rheinhardt [this message]
2024-06-04 19:30   ` James Almer
2024-06-04 19:32     ` Andreas Rheinhardt
2024-06-04 19:37       ` James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB0737977C9E4CBA9C19F1E5208FF82@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git