From patchwork Wed Nov 24 21:15:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 31633 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp11121575iob; Wed, 24 Nov 2021 13:15:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg3/+DgXY4ItHfA0E/BMonlycWFzvZG0EnzhnDj+953SgYK9QobfkkWcHjrXbIP3U6r2ol X-Received: by 2002:aa7:c2c6:: with SMTP id m6mr29043888edp.42.1637788548898; Wed, 24 Nov 2021 13:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637788548; cv=none; d=google.com; s=arc-20160816; b=m8iRgnPyMkkZeTKtJBFE2JX3prskNlKMkP3WjSSMCTQXiS/Z/szD2caAVTMc4ohp1O M+86S7kxmYL5EEqBflpAz0K+yr51HyuHv5S348ENkCU+MBJ078Ar5CnTHI5JqIealKIX 66rfZWuKuxS7hmdP71bPT6MHTvBlLw02lFg39HjEUGOQitWi1cjNWVJYhamG19mxmiKl xVrckOdosItwBa4TLX9MNawV05K9+2bNKwMU0qbOZSSV/jfYiXNTId+SxLY/QD+t5jsj E+25t73ZS36yTnoRCPhlIJDRcZ+WWxVytvrq4okjKkXpO1+PU7zjHsHecQotMTeAC5Di 1qrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=LqGxBgRH9USvCfbz+XFPsSqsX2steBjwcFxLYL3BdqA=; b=FgEvfShs84gcKBKtg/9aZsSDVDmH/xfWEx3A+nSPu4YsuO+BFJ//dMmK1OvfZqE6f4 L1BFDrSlhn1ApstD1SfOvHC2b5rU6VydemgYYSIH3HzxaRCWBYSLzRZI3ZKsBDs1A5E3 lwi/SbfhpaZrJOpl3nXu7fcL03uPGtJKV8DE2Snv/RInfjnbm0/iNw1l+ychfcl3frVT fZgAFruFVvvzcGkd+zpnjhaGz1HT6BMwWSkmmehwFZTUDG3U6167010PCe/PuBGXILJJ VxugFahuWeBWgnn4tLEq/Jv4mWSD5fCGie6fana0KEOwvuGcRnOXHiyH7BS6c82VLuje 9m9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=EeETguTX; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c12si2578358edx.280.2021.11.24.13.15.47; Wed, 24 Nov 2021 13:15:48 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=EeETguTX; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0FF0068A93E; Wed, 24 Nov 2021 23:15:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 19F6968A43D for ; Wed, 24 Nov 2021 23:15:37 +0200 (EET) Received: by mail-pj1-f51.google.com with SMTP id gb13-20020a17090b060d00b001a674e2c4a8so3865490pjb.4 for ; Wed, 24 Nov 2021 13:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e4LaAySUpHvpK1WeH3A2LGiLqCglg2yA5xtqnF+NKJk=; b=EeETguTXCrdiSt+xXqBFJL3gxswTd7TIOtc7Wrp/l3+pC2O2+vMAOxjI9WXo9V7yPm IqbB1HsCnNzr8Zh4TUbzQH2gfVk8Ce2ct69KhxgLfafNnaVnveecSGuhyeahYT4BXYCS 5IZ362w5ecqHUDdqa1ZWWZxom09xCqg0TByxYTrZOF6MDPn7d1bPlFXXEngccRIqTB/9 vCHn4FDy2GqpIAkmVVqSqqXv/wgTHTuxPt5gj3T6OSUPVWSJ7MMNHLPE6XHxioO2fB/P LM38qaqfWJtmLRlGlpltcj/Li7qainrakll6mZu53KGUwmCx3v1VPtGrf3EoQk41p5Fs 9sBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e4LaAySUpHvpK1WeH3A2LGiLqCglg2yA5xtqnF+NKJk=; b=HDbENNFpciWYMMj0iL32j2Fyncp5hKWCF2eHGCS/L2DQPnmuqAQFPQwbDGdmm4hP/h Poe/ZdeHA9iFXe3I+SBFezqdhnHtTAU+kCteUCp9R6z5R3yU4xsm3A8NsshVkMJpV8VS L6Tw9gpuVlEWZnfUZJRrCW9PSdt6CZ+sip+p0nBEQ/Ah5UxgpAGOYNFLT3EkFROG5ins 0pDKxBkIrSSkhgTrGHHSoZAUioGNrng6YHvWRdo+ve48nRaxseMA2aZQMN9WAfyOByx9 rurUe2vt5h29hRK+htxWTbXa3n0BZtYp0HDmFNmYGqPquBT0+EJEwBqtRKGwiGInrbky 8jJA== X-Gm-Message-State: AOAM533Lu+uxtZiXdOub52t5R1GudSO/CZgk0L9TCQ3vW5ezmwZ5seXK OMdmI77zyU7rMhh2MkWSHTxFgtXcpS0= X-Received: by 2002:a17:90b:1a88:: with SMTP id ng8mr88301pjb.180.1637788534271; Wed, 24 Nov 2021 13:15:34 -0800 (PST) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id j13sm444971pgm.35.2021.11.24.13.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 13:15:33 -0800 (PST) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Nov 2021 13:15:20 -0800 Message-Id: <20211124211521.1509-1-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/2] swscale/x86/output.asm: add x86-optimized planer gbr yuv2anyX functions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: I5AHRMSeWqYj From: Mark Reid changes since v2: * fixed label changes since v1: * remove vex intruction on sse4 path * some load/pack marcos use less intructions * fixed some typos yuv2gbrp_full_X_4_512_c: 12757.6 yuv2gbrp_full_X_4_512_sse2: 8946.6 yuv2gbrp_full_X_4_512_sse4: 5138.6 yuv2gbrp_full_X_4_512_avx2: 3889.6 yuv2gbrap_full_X_4_512_c: 15368.6 yuv2gbrap_full_X_4_512_sse2: 11916.1 yuv2gbrap_full_X_4_512_sse4: 6294.6 yuv2gbrap_full_X_4_512_avx2: 3477.1 yuv2gbrp9be_full_X_4_512_c: 14381.6 yuv2gbrp9be_full_X_4_512_sse2: 9139.1 yuv2gbrp9be_full_X_4_512_sse4: 5150.1 yuv2gbrp9be_full_X_4_512_avx2: 2834.6 yuv2gbrp9le_full_X_4_512_c: 12990.1 yuv2gbrp9le_full_X_4_512_sse2: 9118.1 yuv2gbrp9le_full_X_4_512_sse4: 5132.1 yuv2gbrp9le_full_X_4_512_avx2: 2833.1 yuv2gbrp10be_full_X_4_512_c: 14401.6 yuv2gbrp10be_full_X_4_512_sse2: 9133.1 yuv2gbrp10be_full_X_4_512_sse4: 5126.1 yuv2gbrp10be_full_X_4_512_avx2: 2837.6 yuv2gbrp10le_full_X_4_512_c: 12718.1 yuv2gbrp10le_full_X_4_512_sse2: 9106.1 yuv2gbrp10le_full_X_4_512_sse4: 5120.1 yuv2gbrp10le_full_X_4_512_avx2: 2826.1 yuv2gbrap10be_full_X_4_512_c: 18535.6 yuv2gbrap10be_full_X_4_512_sse2: 33617.6 yuv2gbrap10be_full_X_4_512_sse4: 6264.1 yuv2gbrap10be_full_X_4_512_avx2: 3422.1 yuv2gbrap10le_full_X_4_512_c: 16724.1 yuv2gbrap10le_full_X_4_512_sse2: 11787.1 yuv2gbrap10le_full_X_4_512_sse4: 6282.1 yuv2gbrap10le_full_X_4_512_avx2: 3441.6 yuv2gbrp12be_full_X_4_512_c: 13723.6 yuv2gbrp12be_full_X_4_512_sse2: 9128.1 yuv2gbrp12be_full_X_4_512_sse4: 7997.6 yuv2gbrp12be_full_X_4_512_avx2: 2844.1 yuv2gbrp12le_full_X_4_512_c: 12257.1 yuv2gbrp12le_full_X_4_512_sse2: 9107.6 yuv2gbrp12le_full_X_4_512_sse4: 5142.6 yuv2gbrp12le_full_X_4_512_avx2: 2837.6 yuv2gbrap12be_full_X_4_512_c: 18511.1 yuv2gbrap12be_full_X_4_512_sse2: 12156.6 yuv2gbrap12be_full_X_4_512_sse4: 6251.1 yuv2gbrap12be_full_X_4_512_avx2: 3444.6 yuv2gbrap12le_full_X_4_512_c: 16687.1 yuv2gbrap12le_full_X_4_512_sse2: 11785.1 yuv2gbrap12le_full_X_4_512_sse4: 6243.6 yuv2gbrap12le_full_X_4_512_avx2: 3446.1 yuv2gbrp14be_full_X_4_512_c: 13690.6 yuv2gbrp14be_full_X_4_512_sse2: 9120.6 yuv2gbrp14be_full_X_4_512_sse4: 5138.1 yuv2gbrp14be_full_X_4_512_avx2: 2843.1 yuv2gbrp14le_full_X_4_512_c: 14995.6 yuv2gbrp14le_full_X_4_512_sse2: 9119.1 yuv2gbrp14le_full_X_4_512_sse4: 5126.1 yuv2gbrp14le_full_X_4_512_avx2: 2843.1 yuv2gbrp16be_full_X_4_512_c: 12367.1 yuv2gbrp16be_full_X_4_512_sse2: 8233.6 yuv2gbrp16be_full_X_4_512_sse4: 4820.1 yuv2gbrp16be_full_X_4_512_avx2: 2666.6 yuv2gbrp16le_full_X_4_512_c: 10904.1 yuv2gbrp16le_full_X_4_512_sse2: 8214.1 yuv2gbrp16le_full_X_4_512_sse4: 4824.1 yuv2gbrp16le_full_X_4_512_avx2: 2629.1 yuv2gbrap16be_full_X_4_512_c: 26569.6 yuv2gbrap16be_full_X_4_512_sse2: 10884.1 yuv2gbrap16be_full_X_4_512_sse4: 5488.1 yuv2gbrap16be_full_X_4_512_avx2: 3272.1 yuv2gbrap16le_full_X_4_512_c: 14010.1 yuv2gbrap16le_full_X_4_512_sse2: 10562.1 yuv2gbrap16le_full_X_4_512_sse4: 5463.6 yuv2gbrap16le_full_X_4_512_avx2: 3255.1 yuv2gbrpf32be_full_X_4_512_c: 14524.1 yuv2gbrpf32be_full_X_4_512_sse2: 8552.6 yuv2gbrpf32be_full_X_4_512_sse4: 4636.1 yuv2gbrpf32be_full_X_4_512_avx2: 2474.6 yuv2gbrpf32le_full_X_4_512_c: 13060.6 yuv2gbrpf32le_full_X_4_512_sse2: 9682.6 yuv2gbrpf32le_full_X_4_512_sse4: 4298.1 yuv2gbrpf32le_full_X_4_512_avx2: 2453.1 yuv2gbrapf32be_full_X_4_512_c: 18629.6 yuv2gbrapf32be_full_X_4_512_sse2: 11363.1 yuv2gbrapf32be_full_X_4_512_sse4: 15201.6 yuv2gbrapf32be_full_X_4_512_avx2: 3727.1 yuv2gbrapf32le_full_X_4_512_c: 16677.6 yuv2gbrapf32le_full_X_4_512_sse2: 10221.6 yuv2gbrapf32le_full_X_4_512_sse4: 5693.6 yuv2gbrapf32le_full_X_4_512_avx2: 3656.6 --- libswscale/x86/output.asm | 434 +++++++++++++++++++++++++++++++++++++- libswscale/x86/swscale.c | 98 +++++++++ tests/checkasm/Makefile | 2 +- tests/checkasm/checkasm.c | 1 + tests/checkasm/checkasm.h | 1 + tests/checkasm/sw_gbrp.c | 198 +++++++++++++++++ tests/fate/checkasm.mak | 1 + 7 files changed, 733 insertions(+), 2 deletions(-) create mode 100644 tests/checkasm/sw_gbrp.c -- 2.31.1.windows.1 diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm index 52cf9f2c2e..e277a61449 100644 --- a/libswscale/x86/output.asm +++ b/libswscale/x86/output.asm @@ -38,7 +38,49 @@ pw_32: times 8 dw 32 pd_255: times 8 dd 255 pw_512: times 8 dw 512 pw_1024: times 8 dw 1024 - +pd_65535_invf: times 8 dd 0x37800080 ;1.0/65535.0 +pd_yuv2gbrp16_start: times 8 dd -0x40000000 +pd_yuv2gbrp_y_start: times 8 dd (1 << 9) +pd_yuv2gbrp_uv_start: times 8 dd ((1 << 9) - (128 << 19)) +pd_yuv2gbrp_a_start: times 8 dd (1 << 18) +pd_yuv2gbrp16_offset: times 8 dd 0x10000 ;(1 << 16) +pd_yuv2gbrp16_round13: times 8 dd 0x02000 ;(1 << 13) +pd_yuv2gbrp16_a_offset: times 8 dd 0x20002000 +pd_yuv2gbrp16_upper30: times 8 dd 0x3FFFFFFF ;(1<<30) - 1 +pd_yuv2gbrp16_upper27: times 8 dd 0x07FFFFFF ;(1<<27) - 1 +pd_yuv2gbrp16_upperC: times 8 dd 0xC0000000 +pb_pack_shuffle8: db 0, 4, 8, 12, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + 0, 4, 8, 12, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1 +pb_pack_shuffle16le: db 0, 1, 4, 5, \ + 8, 9, 12, 13, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + 0, 1, 4, 5, \ + 8, 9, 12, 13 +pb_pack_shuffle16be: db 1, 0, 5, 4, \ + 9, 8, 13, 12, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + 1, 0, 5, 4, \ + 9, 8, 13, 12 +pb_shuffle32be: db 3, 2, 1, 0, \ + 7, 6, 5, 4, \ + 11, 10, 9, 8, \ + 15, 14, 13, 12, \ + 3, 2, 1, 0, \ + 7, 6, 5, 4, \ + 11, 10, 9, 8, \ + 15, 14, 13, 12 yuv2nv12_shuffle_mask: times 2 db 0, 4, 8, 12, \ -1, -1, -1, -1, \ -1, -1, -1, -1, \ @@ -549,3 +591,393 @@ yuv2nv12cX_fn yuv2nv12 yuv2nv12cX_fn yuv2nv21 %endif %endif ; ARCH_X86_64 + +;----------------------------------------------------------------------------- +; planar grb yuv2anyX functions +; void ff_yuv2_full_X_(SwsContext *c, const int16_t *lumFilter, +; const int16_t **lumSrcx, int lumFilterSize, +; const int16_t *chrFilter, const int16_t **chrUSrcx, +; const int16_t **chrVSrcx, int chrFilterSize, +; const int16_t **alpSrcx, uint8_t **dest, +; int dstW, int y) +;----------------------------------------------------------------------------- + +%if ARCH_X86_64 +struc SwsContext + .padding: resb 40292 ; offsetof(SwsContext, yuv2rgb_y_offset) + .yuv2rgb_y_offset: resd 1 + .yuv2rgb_y_coeff: resd 1 + .yuv2rgb_v2r_coeff: resd 1 + .yuv2rgb_v2g_coeff: resd 1 + .yuv2rgb_u2g_coeff: resd 1 + .yuv2rgb_u2b_coeff: resd 1 +endstruc + +%define R m0 +%define G m1 +%define B m2 +%define A m3 + +%define Y m4 +%define U m5 +%define V m6 + +; Clip a signed integer to an unsigned power of two range. +; av_clip_uintp2 +; 1 - dest +; 2 - bit position to clip at +%macro CLIPP2 2 + ; (~a) >> 31 & ((1<= 16 + movu m%1, [ptrq + xq*4] +%else + LOAD16 %1, [ptrq + xq*2] +%endif +%endmacro + +; 1 - dest +; 2 - source +%macro STORE8 2 + mov ptrq, %1 + %if mmsize > 16 + pshufb m%2, [pb_pack_shuffle8] + vextractf128 xm4, m%2, 1 + por xm%2, xm4 + movq [ptrq + xq], xm%2 + %else + %if cpuflag(sse4) + pshufb m%2, [pb_pack_shuffle8] + %else + psrldq m4, m%2, 3 + por m%2, m4 + psrldq m4, m%2, 6 + por m%2, m4 + %endif + movd [ptrq + xq], m%2 + %endif +%endmacro + +; 1 - dest +; 2 - source +; 3 - is big endian +%macro STORE16 3 + mov ptrq, %1 + %if mmsize > 16 + %if %3 ; bigendian + pshufb m%2, [pb_pack_shuffle16be] + %else + pshufb m%2, [pb_pack_shuffle16le] + %endif + vpermq m%2, m%2, (3 << 6 | 0 << 4 | 3 << 2 | 0 << 0) + movu [ptrq + xq*2], xm%2 + %else + %if cpuflag(sse4) && %3 ; bigendian + pshufb m%2, [pb_pack_shuffle16be] + %elif cpuflag(sse4) + pshufb m%2, [pb_pack_shuffle16le] + %else + pshuflw m%2, m%2, (1 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshufhw m%2, m%2, (1 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshufd m%2, m%2, (3 << 6 | 3 << 4 | 2 << 2 | 0 << 0) + %if %3 ; bigendian + psrlw m4, m%2, 8 + psllw m%2, 8 + por m%2, m4 + %endif + %endif + movq [ptrq + xq*2], m%2 + %endif +%endmacro + +%macro SWAP32 1 +%if mmsize > 16 || cpuflag(sse4) + pshufb m%1, [pb_shuffle32be] +%else + psrlw m4, m%1, 8 + psllw m%1, 8 + por m%1, m4 + pshuflw m%1, m%1, (2 << 6 | 3 << 4 | 0 << 2 | 1 << 0) + pshufhw m%1, m%1, (2 << 6 | 3 << 4 | 0 << 2 | 1 << 0) +%endif +%endmacro + +; 1 - dest +; 2 - source +; 3 - depth +; 4 - is big endian +%macro STORE_PIXELS 4 +%if %3 > 16 + %if %4 + SWAP32 %2 + %endif + mov ptrq, %1 + movu [ptrq + xq*4], m%2 +%elif %3 > 8 + STORE16 %1, %2, %4 +%else + STORE8 %1, %2 +%endif +%endmacro + +%macro PMULLO 3 +%if cpuflag(sse4) || mmsize > 16 + pmulld %1, %2, %3 +%else + %ifidni %1, %2 + %else + mova %1, %2 + %endif + pshufd m7, %1, (2 << 6 | 3 << 4 | 0 << 2 | 1 << 0) ; 0xb1 + pshufd m8, %3, (2 << 6 | 3 << 4 | 0 << 2 | 1 << 0) ; 0xb1 + pmuludq m7, m8 + pshufd m7, m7, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) ; 0xd8 + pmuludq %1, %3 + pshufd %1, %1, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) ; 0xd8 + punpckldq %1, m7 +%endif +%endmacro + +; 1 - name +; 2 - depth +; 3 - has alpha +; 3 - is big endian +; 5 - is float +%macro yuv2gbrp_fn 5 +%define DEPTH %2 +%define HAS_ALPHA %3 +%define IS_BE %4 +%define FLOAT %5 +%define SH (22 + 8 - DEPTH) + +%if DEPTH >= 16 + %define RGB_SHIFT 14 + %define A_SHIFT 14 +%elif 22 != SH + %define RGB_SHIFT SH + %define A_SHIFT (SH-3) +%else + %define RGB_SHIFT 22 + %define A_SHIFT 19 +%endif + +%if DEPTH >= 16 + %define YUV_SHIFT 14 + %define Y_START m9 + %define Y_ROUND [pd_yuv2gbrp16_round13] + %define UV_START m9 + %define A_START m9 + %define A_CLIP2P 30 +%else + %define YUV_SHIFT 10 + %define Y_START [pd_yuv2gbrp_y_start] + %define Y_ROUND m9 + %define UV_START [pd_yuv2gbrp_uv_start] + %define A_START [pd_yuv2gbrp_a_start] + %define A_CLIP2P 27 +%endif + +cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter, lumSrcx, lumFilterSize, chrFilter, chrUSrcx, chrVSrcx, chrFilterSize, alpSrcx, dest, dstW, y, x, j + VBROADCASTSS m10, dword [ptrq + SwsContext.yuv2rgb_y_offset] + VBROADCASTSS m11, dword [ptrq + SwsContext.yuv2rgb_y_coeff] + VBROADCASTSS m12, dword [ptrq + SwsContext.yuv2rgb_v2r_coeff] + VBROADCASTSS m13, dword [ptrq + SwsContext.yuv2rgb_v2g_coeff] + VBROADCASTSS m14, dword [ptrq + SwsContext.yuv2rgb_u2g_coeff] + VBROADCASTSS m15, dword [ptrq + SwsContext.yuv2rgb_u2b_coeff] + +%if DEPTH >= 16 + movu m9, [pd_yuv2gbrp16_start] +%else + mov xq, (1 << (SH-1)) + movq xm9, xq + VBROADCASTSS m9, xm9 +%endif + xor xq, xq + + %%loop_x: + movu Y, Y_START + movu U, UV_START + movu V, UV_START + + xor jq, jq + %%loop_luma: + movsx ptrd, word [lumFilterq + jq*2] + movd xm0, ptrd + VBROADCASTSS m0, xm0 + LOAD_PIXELS 1, lumSrcxq, DEPTH + PMULLO m1, m1, m0 + paddd Y, m1 + inc jd + cmp jd, lumFilterSized + jl %%loop_luma + +%if HAS_ALPHA + cmp alpSrcxq, 0 + je %%skip_alpha_load + xor jq, jq + movu A, A_START + %%loop_alpha: + movsx ptrd, word [lumFilterq + jq*2] + movd xm0, ptrd + VBROADCASTSS m0, xm0 + LOAD_PIXELS 1, alpSrcxq, DEPTH + PMULLO m1, m1, m0 + paddd A, m1 + inc jd + cmp jd, lumFilterSized + jl %%loop_alpha +%if DEPTH >= 16 + psrad A, 1 + paddd A, [pd_yuv2gbrp16_a_offset] +%endif + %%skip_alpha_load: +%endif + xor jq, jq + %%loop_chr: + movsx ptrd, word [chrFilterq + jq*2] + movd xm0, ptrd + VBROADCASTSS m0, xm0 + LOAD_PIXELS 1, chrUSrcxq, DEPTH + LOAD_PIXELS 2, chrVSrcxq, DEPTH + PMULLO m1, m1, m0 + PMULLO m2, m2, m0 + paddd U, m1 + paddd V, m2 + inc jd + cmp jd, chrFilterSized + jl %%loop_chr + + psrad Y, YUV_SHIFT +%if DEPTH >= 16 + paddd Y, [pd_yuv2gbrp16_offset] +%endif + psrad U, YUV_SHIFT + psrad V, YUV_SHIFT + + psubd Y, m10 ; yuv2rgb_y_offset + PMULLO Y, Y, m11 ; yuv2rgb_y_coeff + paddd Y, Y_ROUND + + PMULLO R, V, m12 ; yuv2rgb_v2r_coeff + PMULLO B, U, m15 ; yuv2rgb_u2b_coeff + + PMULLO U, U, m14 ; yuv2rgb_u2g_coeff + PMULLO V, V, m13 ; yuv2rgb_v2g_coeff + paddd G, U, V + paddd R, Y + paddd G, Y + paddd B, Y + + CLIPP2 R, 30 + CLIPP2 G, 30 + CLIPP2 B, 30 + + psrad R, RGB_SHIFT + psrad G, RGB_SHIFT + psrad B, RGB_SHIFT + +%if FLOAT + cvtdq2ps R, R + cvtdq2ps G, G + cvtdq2ps B, B + mulps R, [pd_65535_invf] + mulps G, [pd_65535_invf] + mulps B, [pd_65535_invf] +%endif + STORE_PIXELS [destq + 0], 1, DEPTH, IS_BE ; G + STORE_PIXELS [destq + 8], 2, DEPTH, IS_BE ; B + STORE_PIXELS [destq + 16], 0, DEPTH, IS_BE ; R + +%if HAS_ALPHA + cmp alpSrcxq, 0 + je %%skip_alpha_store + CLIPP2 A, A_CLIP2P + psrad A, A_SHIFT +%if FLOAT + cvtdq2ps A, A + mulps A, [pd_65535_invf] +%endif + STORE_PIXELS [destq + 24], 3, DEPTH, IS_BE + %%skip_alpha_store: +%endif + add xq, mmsize/4 + cmp xd, dstWd + jl %%loop_x + + RET +%endmacro + +%macro yuv2gbrp_fn_decl 2 +INIT_%1 %2 +yuv2gbrp_fn gbrp, 8, 0, 0, 0 +yuv2gbrp_fn gbrap, 8, 1, 0, 0 +yuv2gbrp_fn gbrp9le, 9, 0, 0, 0 +yuv2gbrp_fn gbrp10le, 10, 0, 0, 0 +yuv2gbrp_fn gbrap10le, 10, 1, 0, 0 +yuv2gbrp_fn gbrp12le, 12, 0, 0, 0 +yuv2gbrp_fn gbrap12le, 12, 1, 0, 0 +yuv2gbrp_fn gbrp14le, 14, 0, 0, 0 +yuv2gbrp_fn gbrp16le, 16, 0, 0, 0 +yuv2gbrp_fn gbrap16le, 16, 1, 0, 0 +yuv2gbrp_fn gbrpf32le, 32, 0, 0, 1 +yuv2gbrp_fn gbrapf32le, 32, 1, 0, 1 + +yuv2gbrp_fn gbrp9be, 9, 0, 1, 0 +yuv2gbrp_fn gbrp10be, 10, 0, 1, 0 +yuv2gbrp_fn gbrap10be, 10, 1, 1, 0 +yuv2gbrp_fn gbrp12be, 12, 0, 1, 0 +yuv2gbrp_fn gbrap12be, 12, 1, 1, 0 +yuv2gbrp_fn gbrp14be, 14, 0, 1, 0 +yuv2gbrp_fn gbrp16be, 16, 0, 1, 0 +yuv2gbrp_fn gbrap16be, 16, 1, 1, 0 +yuv2gbrp_fn gbrpf32be, 32, 0, 1, 1 +yuv2gbrp_fn gbrapf32be, 32, 1, 1, 1 +%endmacro + +yuv2gbrp_fn_decl XMM, sse2 +yuv2gbrp_fn_decl XMM, sse4 + +%if HAVE_AVX2_EXTERNAL +yuv2gbrp_fn_decl YMM, avx2 +%endif + +%endif ; ARCH_X86_64 \ No newline at end of file diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 0848a31461..e8bc15b6ee 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -350,6 +350,43 @@ void ff_yuv2 ## fmt ## cX_ ## opt(enum AVPixelFormat format, const uint8_t *dith YUV2NV_DECL(nv12, avx2); YUV2NV_DECL(nv21, avx2); + +#define YUV2GBRP_FN_DECL(fmt, opt) \ +void ff_yuv2##fmt##_full_X_ ##opt(SwsContext *c, const int16_t *lumFilter, \ + const int16_t **lumSrcx, int lumFilterSize, \ + const int16_t *chrFilter, const int16_t **chrUSrcx, \ + const int16_t **chrVSrcx, int chrFilterSize, \ + const int16_t **alpSrcx, uint8_t **dest, \ + int dstW, int y) + +#define YUV2GBRP_DECL(opt) \ +YUV2GBRP_FN_DECL(gbrp, opt); \ +YUV2GBRP_FN_DECL(gbrap, opt); \ +YUV2GBRP_FN_DECL(gbrp9le, opt); \ +YUV2GBRP_FN_DECL(gbrp10le, opt); \ +YUV2GBRP_FN_DECL(gbrap10le, opt); \ +YUV2GBRP_FN_DECL(gbrp12le, opt); \ +YUV2GBRP_FN_DECL(gbrap12le, opt); \ +YUV2GBRP_FN_DECL(gbrp14le, opt); \ +YUV2GBRP_FN_DECL(gbrp16le, opt); \ +YUV2GBRP_FN_DECL(gbrap16le, opt); \ +YUV2GBRP_FN_DECL(gbrpf32le, opt); \ +YUV2GBRP_FN_DECL(gbrapf32le, opt); \ +YUV2GBRP_FN_DECL(gbrp9be, opt); \ +YUV2GBRP_FN_DECL(gbrp10be, opt); \ +YUV2GBRP_FN_DECL(gbrap10be, opt); \ +YUV2GBRP_FN_DECL(gbrp12be, opt); \ +YUV2GBRP_FN_DECL(gbrap12be, opt); \ +YUV2GBRP_FN_DECL(gbrp14be, opt); \ +YUV2GBRP_FN_DECL(gbrp16be, opt); \ +YUV2GBRP_FN_DECL(gbrap16be, opt); \ +YUV2GBRP_FN_DECL(gbrpf32be, opt); \ +YUV2GBRP_FN_DECL(gbrapf32be, opt); + +YUV2GBRP_DECL(sse2); +YUV2GBRP_DECL(sse4); +YUV2GBRP_DECL(avx2); + #endif av_cold void ff_sws_init_swscale_x86(SwsContext *c) @@ -582,5 +619,66 @@ switch(c->dstBpc){ \ break; } } + + if(c->flags & SWS_FULL_CHR_H_INT) { + + /* yuv2gbrp uses the SwsContext for yuv coefficients + if struct offsets change the asm needs to be updated too */ + av_assert0(offsetof(SwsContext, yuv2rgb_y_offset) == 40292); + +#define YUV2ANYX_FUNC_CASE(fmt, name, opt) \ + case fmt: \ + c->yuv2anyX = ff_yuv2##name##_full_X_##opt; \ + break; + +#define YUV2ANYX_GBRAP_CASES(opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP, gbrp, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP, gbrap, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP9LE, gbrp9le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP10LE, gbrp10le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP10LE, gbrap10le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP12LE, gbrp12le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP12LE, gbrap12le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP14LE, gbrp14le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP16LE, gbrp16le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP16LE, gbrap16le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRPF32LE, gbrpf32le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32LE, gbrapf32le, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP9BE, gbrp9be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP10BE, gbrp10be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP10BE, gbrap10be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP12BE, gbrp12be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP12BE, gbrap12be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP14BE, gbrp14be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP16BE, gbrp16be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP16BE, gbrap16be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRPF32BE, gbrpf32be, opt) \ + YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32BE, gbrapf32be, opt) + + if (EXTERNAL_SSE2(cpu_flags)) { + switch (c->dstFormat) { + YUV2ANYX_GBRAP_CASES(sse2) + default: + break; + } + } + + if (EXTERNAL_SSE4(cpu_flags)) { + switch (c->dstFormat) { + YUV2ANYX_GBRAP_CASES(sse4) + default: + break; + } + } + + if (EXTERNAL_AVX2_FAST(cpu_flags)) { + switch (c->dstFormat) { + YUV2ANYX_GBRAP_CASES(avx2) + default: + break; + } + } + } + #endif } diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index 4ef5fa87da..f768b1144e 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -45,7 +45,7 @@ AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) # swscale tests -SWSCALEOBJS += sw_rgb.o sw_scale.o +SWSCALEOBJS += sw_gbrp.o sw_rgb.o sw_scale.o CHECKASMOBJS-$(CONFIG_SWSCALE) += $(SWSCALEOBJS) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index b1353f7cbe..5fa8ac7bcc 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -183,6 +183,7 @@ static const struct { #endif #endif #if CONFIG_SWSCALE + { "sw_gbrp", checkasm_check_sw_gbrp }, { "sw_rgb", checkasm_check_sw_rgb }, { "sw_scale", checkasm_check_sw_scale }, #endif diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 68b0697d3e..c3192d8c23 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -72,6 +72,7 @@ void checkasm_check_opusdsp(void); void checkasm_check_pixblockdsp(void); void checkasm_check_sbrdsp(void); void checkasm_check_synth_filter(void); +void checkasm_check_sw_gbrp(void); void checkasm_check_sw_rgb(void); void checkasm_check_sw_scale(void); void checkasm_check_utvideodsp(void); diff --git a/tests/checkasm/sw_gbrp.c b/tests/checkasm/sw_gbrp.c new file mode 100644 index 0000000000..61b2b9d6a1 --- /dev/null +++ b/tests/checkasm/sw_gbrp.c @@ -0,0 +1,198 @@ +/* + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with FFmpeg; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include "libavutil/common.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mem_internal.h" +#include "libavutil/pixdesc.h" + +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" + +#include "checkasm.h" + +#define randomize_buffers(buf, size) \ + do { \ + int j; \ + for (j = 0; j < size; j+=4) \ + AV_WN32(buf + j, rnd()); \ + } while (0) + +static const int planar_fmts[] = { + AV_PIX_FMT_GBRP, + AV_PIX_FMT_GBRP9BE, + AV_PIX_FMT_GBRP9LE, + AV_PIX_FMT_GBRP10BE, + AV_PIX_FMT_GBRP10LE, + AV_PIX_FMT_GBRP12BE, + AV_PIX_FMT_GBRP12LE, + AV_PIX_FMT_GBRP14BE, + AV_PIX_FMT_GBRP14LE, + AV_PIX_FMT_GBRAP, + AV_PIX_FMT_GBRAP10BE, + AV_PIX_FMT_GBRAP10LE, + AV_PIX_FMT_GBRAP12BE, + AV_PIX_FMT_GBRAP12LE, + AV_PIX_FMT_GBRP16BE, + AV_PIX_FMT_GBRP16LE, + AV_PIX_FMT_GBRAP16BE, + AV_PIX_FMT_GBRAP16LE, + AV_PIX_FMT_GBRPF32BE, + AV_PIX_FMT_GBRPF32LE, + AV_PIX_FMT_GBRAPF32BE, + AV_PIX_FMT_GBRAPF32LE +}; + +static void check_output_yuv2gbrp(void) +{ + struct SwsContext *ctx; + const AVPixFmtDescriptor *desc; + int fmi, fsi, isi, i; + int dstW, byte_size, luma_filter_size, chr_filter_size; +#define LARGEST_FILTER 16 +#define FILTER_SIZES 4 + static const int filter_sizes[] = {1, 4, 8, 16}; +#define LARGEST_INPUT_SIZE 512 +#define INPUT_SIZES 6 + static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; + uint8_t *dst0[4]; + uint8_t *dst1[4]; + + declare_func(void, void *c, const int16_t *lumFilter, + const int16_t **lumSrcx, int lumFilterSize, + const int16_t *chrFilter, const int16_t **chrUSrcx, + const int16_t **chrVSrcx, int chrFilterSize, + const int16_t **alpSrcx, uint8_t **dest, + int dstW, int y); + + const int16_t *luma[LARGEST_FILTER]; + const int16_t *chru[LARGEST_FILTER]; + const int16_t *chrv[LARGEST_FILTER]; + const int16_t *alpha[LARGEST_FILTER]; + + LOCAL_ALIGNED_8(int16_t, luma_filter, [LARGEST_FILTER]); + LOCAL_ALIGNED_8(int16_t, chr_filter, [LARGEST_FILTER]); + + LOCAL_ALIGNED_8(int32_t, src_y, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_u, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_v, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); + + LOCAL_ALIGNED_8(uint8_t, dst0_r, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst0_g, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst0_b, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst0_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + + LOCAL_ALIGNED_8(uint8_t, dst1_r, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst1_g, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst1_b, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst1_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + + randomize_buffers((uint8_t*)src_y, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_u, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_v, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_a, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)luma_filter, LARGEST_FILTER * sizeof(int16_t)); + randomize_buffers((uint8_t*)chr_filter, LARGEST_FILTER * sizeof(int16_t)); + + dst0[0] = (uint8_t*)dst0_g; + dst0[1] = (uint8_t*)dst0_b; + dst0[2] = (uint8_t*)dst0_r; + dst0[3] = (uint8_t*)dst0_a; + + dst1[0] = (uint8_t*)dst1_g; + dst1[1] = (uint8_t*)dst1_b; + dst1[2] = (uint8_t*)dst1_r; + dst1[3] = (uint8_t*)dst1_a; + + for (i = 0; i < LARGEST_FILTER; i++) { + luma[i] = (int16_t *)(src_y + i*LARGEST_INPUT_SIZE); + chru[i] = (int16_t *)(src_u + i*LARGEST_INPUT_SIZE); + chrv[i] = (int16_t *)(src_v + i*LARGEST_INPUT_SIZE); + alpha[i] = (int16_t *)(src_a + i*LARGEST_INPUT_SIZE); + } + + ctx = sws_alloc_context(); + if (sws_init_context(ctx, NULL, NULL) < 0) + fail(); + + ctx->flags |= SWS_FULL_CHR_H_INT; + ctx->yuv2rgb_y_offset = rnd(); + ctx->yuv2rgb_y_coeff = rnd(); + ctx->yuv2rgb_v2r_coeff = rnd(); + ctx->yuv2rgb_v2g_coeff = rnd(); + ctx->yuv2rgb_u2g_coeff = rnd(); + ctx->yuv2rgb_u2b_coeff = rnd(); + + for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { + for (fsi = 0; fsi < FILTER_SIZES; fsi++) { + for (isi = 0; isi < INPUT_SIZES; isi++ ) { + desc = av_pix_fmt_desc_get(planar_fmts[fmi]); + ctx->dstFormat = planar_fmts[fmi]; + + dstW = input_sizes[isi]; + luma_filter_size = filter_sizes[fsi]; + chr_filter_size = filter_sizes[fsi]; + + if (desc->comp[0].depth > 16) { + byte_size = 4; + } else if (desc->comp[0].depth > 8) { + byte_size = 2; + } else { + byte_size = 1; + } + + ff_sws_init_scale(ctx); + if (check_func(ctx->yuv2anyX, "yuv2%s_full_X_%d_%d", desc->name, luma_filter_size, dstW)) { + for (i = 0; i < 4; i ++) { + memset(dst0[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + memset(dst1[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + } + + call_ref(ctx, luma_filter, luma, luma_filter_size, + chr_filter, chru, chrv, chr_filter_size, + alpha, dst0, dstW, 0); + call_new(ctx, luma_filter, luma, luma_filter_size, + chr_filter, chru, chrv, chr_filter_size, + alpha, dst1, dstW, 0); + + if (memcmp(dst0[0], dst1[0], dstW * byte_size) || + memcmp(dst0[1], dst1[1], dstW * byte_size) || + memcmp(dst0[2], dst1[2], dstW * byte_size) || + memcmp(dst0[3], dst1[3], dstW * byte_size) ) + fail(); + + bench_new(ctx, luma_filter, luma, luma_filter_size, + chr_filter, chru, chrv, chr_filter_size, + alpha, dst1, dstW, 0); + } + } + } + } + sws_freeContext(ctx); +} + + +void checkasm_check_sw_gbrp(void) +{ + check_output_yuv2gbrp(); + report("output_yuv2gbrp"); +} diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak index 6e7edbe655..6db8f09d12 100644 --- a/tests/fate/checkasm.mak +++ b/tests/fate/checkasm.mak @@ -26,6 +26,7 @@ FATE_CHECKASM = fate-checkasm-aacpsdsp \ fate-checkasm-pixblockdsp \ fate-checkasm-sbrdsp \ fate-checkasm-synth_filter \ + fate-checkasm-sw_gbrp \ fate-checkasm-sw_rgb \ fate-checkasm-sw_scale \ fate-checkasm-utvideodsp \ From patchwork Wed Nov 24 21:15:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 31632 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp11121799iob; Wed, 24 Nov 2021 13:16:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFBpCovZt/5m5Vhq/RbHOwtj6bXo5gxOgc/f6UwHpGhio9H0hj7M8SV9DABJbEK+xE1V3h X-Received: by 2002:a50:d6d9:: with SMTP id l25mr31312387edj.41.1637788560517; Wed, 24 Nov 2021 13:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637788560; cv=none; d=google.com; s=arc-20160816; b=0FHFVpaShca/hjSFxezTHMocTzZmMW2oElpNNItKfGel735E5jhrf+To8nlKha/g9N AYqLy3IpODczYWxP0uyyfdsXVVFaknkn33ZXznipAoBt4ZKM6mLNzEXAJ43fJikeNYek PivJPPHTn2vEJFN+oXMmJxSaGVncuhvOpYC+EV3dSiAEKeHQdOMoFcKSlGop4dN7dIsG 2Lj9xw0hdQS/2dA9tt9OPmujScdzDwxPqpwsnubhJeVuHy/EITxduWccg/fvzo1uwTBh kA7m5kQDDP+pJufO5joBePpQ/S/8dBurXf2VsWqB7UJJRlIzyNPeyyIWnhHdWN3jFzM0 M/Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=j5qOxObm6/vdfO3JvOZYjZr5/GLhO0c+T0pmkCuGYew=; b=S+jsEuJBgC20ic6hTL3fCdyrZIjJB8CWvOHle6701p4fn5Ueiy0s3qak3aLAljeC/i MfBwmqZyoJLaUrJiTmEQWFuGya/ndWuIuYHaGp2VaTsmsJwuzqC6MqfA03oE2qojFiJB sOpGNJwQiTwTMVcFJzyrc6TZCkw1ItcLgmtAPYAMqDnnWPC9gK7+HtjMEpvBw/AgfiKk YRBU4vPHMptLy3DYXwcRJhI0Kw1CzGVHh/kNm3CvBTp5Ld7AYzTNXdxxW5DZEwQim7Dw MTknsswNJ2xL5Ut943T/1QMIX5nM3w8mYq9w6K/tmzUeXDp2gqUJMtJt+B5jJgAb2JBb sj3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YI+Qt3ZP; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gn37si2506537ejc.204.2021.11.24.13.15.59; Wed, 24 Nov 2021 13:16:00 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YI+Qt3ZP; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3245268AB64; Wed, 24 Nov 2021 23:15:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 79CD468A43D for ; Wed, 24 Nov 2021 23:15:37 +0200 (EET) Received: by mail-pj1-f51.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso3865716pjo.3 for ; Wed, 24 Nov 2021 13:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/dkt7Ws6ydAajDN4Orho0+45c+O1H34eQfJA42nab3c=; b=YI+Qt3ZPixlL37MDn2RebyfZ2I/9azdZht0AlJBMGhScyRggrAsEQ21NFISvsSxLMN RReT4VYXRjS85ywVYHhZeqLjGNvLTxv32PmMKKPQw0Afhg+eKKk3vJsuSsMbD9bYHk/p wV7Yp7mjDqogMjVgw3AZ34kTUi7W5jzITjulKBN6wOF92r/INih41jOOBNRoSDHu1vx2 zpuVs0a21LVu0EAcqReIQtWFgVafcqCrEonyejCSPCv11DxLgBQhAO6rScBgViwZLAOg MtR+eyNodE5UA9pKCuPtNP9wPfU1hkBY1b8n6gUkm4URhV5jPqH8zmPlYha/3o9d7c+8 cgZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/dkt7Ws6ydAajDN4Orho0+45c+O1H34eQfJA42nab3c=; b=wruBdP1Eeke/guQwgumQB9UJ34GWMoEQYKFxgL1ZZktZ1ByceXf8oM6mMkbXrPK07F x31Ah2MeJxTCk6Nq3UnO1B/5m1XejDcDgH1ycTpaHpX1xDQ5q5ML6ZfapKAHBHUlzFJY zmP0p6tlOAOB5Aq/gVEtZX6Ng9OlgwymngJYf+0FoY7tKaoBdjQ7GH75I/JIpWG3K7m1 DUSnvD3ahroj4Qfer8hiwZzrzcrIm0SzDsRYbhmHkuDUw+p5SiQldI+tndwk99mIQYm4 1qKNfr4rI5PucgH7gH75m6xuS0PhRij4mjoElviWi+JSEwosjmAgpPvy3t17BpFEwbrF wVYw== X-Gm-Message-State: AOAM531AeoCfy1k79AL5CfzkgDxp36KHpdcdzDWUiYPEvNNsRW8twZhd TFeHwiGPPV0sRbDHLDZMHt4CFPbry3Q= X-Received: by 2002:a17:902:7fc5:b0:143:6d84:88eb with SMTP id t5-20020a1709027fc500b001436d8488ebmr22979112plb.61.1637788535417; Wed, 24 Nov 2021 13:15:35 -0800 (PST) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id j13sm444971pgm.35.2021.11.24.13.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 13:15:34 -0800 (PST) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Nov 2021 13:15:21 -0800 Message-Id: <20211124211521.1509-2-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20211124211521.1509-1-mindmark@gmail.com> References: <20211124211521.1509-1-mindmark@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/2] swscale/x86/input.asm: add x86-optimized planer rgb2yuv functions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7gRQyR3mcceh From: Mark Reid sse2 only operates on 2 lanes per loop for to_y and to_uv functions, due to the lack of pmulld instruction. Emulating pmulld with 2 pmuludq and shuffles proved too costly and made to_uv functions slower then the c implementation. For to_y on sse2 only float functions are generated, I was are not able outperform the c implementation on the integer pixel formats. For to_a on see4 only the float functions are generated. sse2 and sse4 generated nearly identical performing code on integer pixel formats, so only sse2/avx2 versions are generated. planar_gbrp_to_y_512_c: 1197.5 planar_gbrp_to_y_512_sse4: 444.5 planar_gbrp_to_y_512_avx2: 287.5 planar_gbrap_to_y_512_c: 1204.5 planar_gbrap_to_y_512_sse4: 447.5 planar_gbrap_to_y_512_avx2: 289.5 planar_gbrp9be_to_y_512_c: 1380.0 planar_gbrp9be_to_y_512_sse4: 543.5 planar_gbrp9be_to_y_512_avx2: 340.0 planar_gbrp9le_to_y_512_c: 1200.5 planar_gbrp9le_to_y_512_sse4: 442.0 planar_gbrp9le_to_y_512_avx2: 282.0 planar_gbrp10be_to_y_512_c: 1378.5 planar_gbrp10be_to_y_512_sse4: 544.0 planar_gbrp10be_to_y_512_avx2: 337.5 planar_gbrp10le_to_y_512_c: 1200.0 planar_gbrp10le_to_y_512_sse4: 448.0 planar_gbrp10le_to_y_512_avx2: 285.5 planar_gbrap10be_to_y_512_c: 1380.0 planar_gbrap10be_to_y_512_sse4: 542.0 planar_gbrap10be_to_y_512_avx2: 340.5 planar_gbrap10le_to_y_512_c: 1199.0 planar_gbrap10le_to_y_512_sse4: 446.0 planar_gbrap10le_to_y_512_avx2: 289.5 planar_gbrp12be_to_y_512_c: 10563.0 planar_gbrp12be_to_y_512_sse4: 542.5 planar_gbrp12be_to_y_512_avx2: 339.0 planar_gbrp12le_to_y_512_c: 1201.0 planar_gbrp12le_to_y_512_sse4: 440.5 planar_gbrp12le_to_y_512_avx2: 286.0 planar_gbrap12be_to_y_512_c: 1701.5 planar_gbrap12be_to_y_512_sse4: 917.0 planar_gbrap12be_to_y_512_avx2: 338.5 planar_gbrap12le_to_y_512_c: 1201.0 planar_gbrap12le_to_y_512_sse4: 444.5 planar_gbrap12le_to_y_512_avx2: 288.0 planar_gbrp14be_to_y_512_c: 1370.5 planar_gbrp14be_to_y_512_sse4: 545.0 planar_gbrp14be_to_y_512_avx2: 338.5 planar_gbrp14le_to_y_512_c: 1199.0 planar_gbrp14le_to_y_512_sse4: 444.0 planar_gbrp14le_to_y_512_avx2: 279.5 planar_gbrp16be_to_y_512_c: 1364.0 planar_gbrp16be_to_y_512_sse4: 544.5 planar_gbrp16be_to_y_512_avx2: 339.5 planar_gbrp16le_to_y_512_c: 1201.0 planar_gbrp16le_to_y_512_sse4: 445.5 planar_gbrp16le_to_y_512_avx2: 280.5 planar_gbrap16be_to_y_512_c: 1377.0 planar_gbrap16be_to_y_512_sse4: 545.0 planar_gbrap16be_to_y_512_avx2: 338.5 planar_gbrap16le_to_y_512_c: 1201.0 planar_gbrap16le_to_y_512_sse4: 442.0 planar_gbrap16le_to_y_512_avx2: 279.0 planar_gbrpf32be_to_y_512_c: 4113.0 planar_gbrpf32be_to_y_512_sse2: 2438.0 planar_gbrpf32be_to_y_512_sse4: 1068.0 planar_gbrpf32be_to_y_512_avx2: 904.5 planar_gbrpf32le_to_y_512_c: 3818.5 planar_gbrpf32le_to_y_512_sse2: 2024.5 planar_gbrpf32le_to_y_512_sse4: 1241.5 planar_gbrpf32le_to_y_512_avx2: 657.0 planar_gbrapf32be_to_y_512_c: 3707.0 planar_gbrapf32be_to_y_512_sse2: 2444.0 planar_gbrapf32be_to_y_512_sse4: 1077.0 planar_gbrapf32be_to_y_512_avx2: 909.0 planar_gbrapf32le_to_y_512_c: 3822.0 planar_gbrapf32le_to_y_512_sse2: 2024.5 planar_gbrapf32le_to_y_512_sse4: 1176.0 planar_gbrapf32le_to_y_512_avx2: 658.5 planar_gbrp_to_uv_512_c: 2325.8 planar_gbrp_to_uv_512_sse2: 1726.8 planar_gbrp_to_uv_512_sse4: 771.8 planar_gbrp_to_uv_512_avx2: 506.8 planar_gbrap_to_uv_512_c: 2281.8 planar_gbrap_to_uv_512_sse2: 1726.3 planar_gbrap_to_uv_512_sse4: 768.3 planar_gbrap_to_uv_512_avx2: 496.3 planar_gbrp9be_to_uv_512_c: 2336.8 planar_gbrp9be_to_uv_512_sse2: 1924.8 planar_gbrp9be_to_uv_512_sse4: 852.3 planar_gbrp9be_to_uv_512_avx2: 552.8 planar_gbrp9le_to_uv_512_c: 2270.3 planar_gbrp9le_to_uv_512_sse2: 1512.3 planar_gbrp9le_to_uv_512_sse4: 764.3 planar_gbrp9le_to_uv_512_avx2: 491.3 planar_gbrp10be_to_uv_512_c: 2281.8 planar_gbrp10be_to_uv_512_sse2: 1917.8 planar_gbrp10be_to_uv_512_sse4: 855.3 planar_gbrp10be_to_uv_512_avx2: 541.3 planar_gbrp10le_to_uv_512_c: 2269.8 planar_gbrp10le_to_uv_512_sse2: 1515.3 planar_gbrp10le_to_uv_512_sse4: 759.8 planar_gbrp10le_to_uv_512_avx2: 487.8 planar_gbrap10be_to_uv_512_c: 2382.3 planar_gbrap10be_to_uv_512_sse2: 1924.8 planar_gbrap10be_to_uv_512_sse4: 855.3 planar_gbrap10be_to_uv_512_avx2: 540.8 planar_gbrap10le_to_uv_512_c: 2382.3 planar_gbrap10le_to_uv_512_sse2: 1512.3 planar_gbrap10le_to_uv_512_sse4: 759.3 planar_gbrap10le_to_uv_512_avx2: 484.8 planar_gbrp12be_to_uv_512_c: 2283.8 planar_gbrp12be_to_uv_512_sse2: 1936.8 planar_gbrp12be_to_uv_512_sse4: 858.3 planar_gbrp12be_to_uv_512_avx2: 541.3 planar_gbrp12le_to_uv_512_c: 2278.8 planar_gbrp12le_to_uv_512_sse2: 1507.3 planar_gbrp12le_to_uv_512_sse4: 760.3 planar_gbrp12le_to_uv_512_avx2: 485.8 planar_gbrap12be_to_uv_512_c: 2385.3 planar_gbrap12be_to_uv_512_sse2: 1927.8 planar_gbrap12be_to_uv_512_sse4: 855.3 planar_gbrap12be_to_uv_512_avx2: 539.8 planar_gbrap12le_to_uv_512_c: 2377.3 planar_gbrap12le_to_uv_512_sse2: 1516.3 planar_gbrap12le_to_uv_512_sse4: 759.3 planar_gbrap12le_to_uv_512_avx2: 484.8 planar_gbrp14be_to_uv_512_c: 2283.8 planar_gbrp14be_to_uv_512_sse2: 1935.3 planar_gbrp14be_to_uv_512_sse4: 852.3 planar_gbrp14be_to_uv_512_avx2: 540.3 planar_gbrp14le_to_uv_512_c: 2276.8 planar_gbrp14le_to_uv_512_sse2: 1514.8 planar_gbrp14le_to_uv_512_sse4: 762.3 planar_gbrp14le_to_uv_512_avx2: 484.8 planar_gbrp16be_to_uv_512_c: 2383.3 planar_gbrp16be_to_uv_512_sse2: 1881.8 planar_gbrp16be_to_uv_512_sse4: 852.3 planar_gbrp16be_to_uv_512_avx2: 541.8 planar_gbrp16le_to_uv_512_c: 2378.3 planar_gbrp16le_to_uv_512_sse2: 1476.8 planar_gbrp16le_to_uv_512_sse4: 765.3 planar_gbrp16le_to_uv_512_avx2: 485.8 planar_gbrap16be_to_uv_512_c: 2382.3 planar_gbrap16be_to_uv_512_sse2: 1886.3 planar_gbrap16be_to_uv_512_sse4: 853.8 planar_gbrap16be_to_uv_512_avx2: 550.8 planar_gbrap16le_to_uv_512_c: 2381.8 planar_gbrap16le_to_uv_512_sse2: 1488.3 planar_gbrap16le_to_uv_512_sse4: 765.3 planar_gbrap16le_to_uv_512_avx2: 491.8 planar_gbrpf32be_to_uv_512_c: 4863.0 planar_gbrpf32be_to_uv_512_sse2: 3347.5 planar_gbrpf32be_to_uv_512_sse4: 1800.0 planar_gbrpf32be_to_uv_512_avx2: 1199.0 planar_gbrpf32le_to_uv_512_c: 4725.0 planar_gbrpf32le_to_uv_512_sse2: 2753.0 planar_gbrpf32le_to_uv_512_sse4: 1474.5 planar_gbrpf32le_to_uv_512_avx2: 927.5 planar_gbrapf32be_to_uv_512_c: 4859.0 planar_gbrapf32be_to_uv_512_sse2: 3269.0 planar_gbrapf32be_to_uv_512_sse4: 1802.0 planar_gbrapf32be_to_uv_512_avx2: 1201.5 planar_gbrapf32le_to_uv_512_c: 6338.0 planar_gbrapf32le_to_uv_512_sse2: 2756.5 planar_gbrapf32le_to_uv_512_sse4: 1476.0 planar_gbrapf32le_to_uv_512_avx2: 908.5 planar_gbrap_to_a_512_c: 383.3 planar_gbrap_to_a_512_sse2: 66.8 planar_gbrap_to_a_512_avx2: 43.8 planar_gbrap10be_to_a_512_c: 601.8 planar_gbrap10be_to_a_512_sse2: 86.3 planar_gbrap10be_to_a_512_avx2: 34.8 planar_gbrap10le_to_a_512_c: 602.3 planar_gbrap10le_to_a_512_sse2: 48.8 planar_gbrap10le_to_a_512_avx2: 31.3 planar_gbrap12be_to_a_512_c: 601.8 planar_gbrap12be_to_a_512_sse2: 111.8 planar_gbrap12be_to_a_512_avx2: 41.3 planar_gbrap12le_to_a_512_c: 385.8 planar_gbrap12le_to_a_512_sse2: 75.3 planar_gbrap12le_to_a_512_avx2: 39.8 planar_gbrap16be_to_a_512_c: 386.8 planar_gbrap16be_to_a_512_sse2: 79.8 planar_gbrap16be_to_a_512_avx2: 31.3 planar_gbrap16le_to_a_512_c: 600.3 planar_gbrap16le_to_a_512_sse2: 40.3 planar_gbrap16le_to_a_512_avx2: 30.3 planar_gbrapf32be_to_a_512_c: 1148.8 planar_gbrapf32be_to_a_512_sse2: 611.3 planar_gbrapf32be_to_a_512_sse4: 234.8 planar_gbrapf32be_to_a_512_avx2: 183.3 planar_gbrapf32le_to_a_512_c: 851.3 planar_gbrapf32le_to_a_512_sse2: 263.3 planar_gbrapf32le_to_a_512_sse4: 199.3 planar_gbrapf32le_to_a_512_avx2: 156.8 --- libswscale/x86/input.asm | 484 ++++++++++++++++++++++++++++++++++++++- libswscale/x86/swscale.c | 170 ++++++++++++++ tests/checkasm/sw_gbrp.c | 216 +++++++++++++++++ 3 files changed, 869 insertions(+), 1 deletion(-) diff --git a/libswscale/x86/input.asm b/libswscale/x86/input.asm index af9afcaa53..ab4baa1e65 100644 --- a/libswscale/x86/input.asm +++ b/libswscale/x86/input.asm @@ -93,7 +93,31 @@ shuf_rgb_12x4: db 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 - +pd_65535f: times 8 dd 65535.0 +pb_pack_shuffle16le: db 0, 1, 4, 5, \ + 8, 9, 12, 13, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + -1, -1, -1, -1, \ + 0, 1, 4, 5, \ + 8, 9, 12, 13 +pb_shuffle32be: db 3, 2, 1, 0, \ + 7, 6, 5, 4, \ + 11, 10, 9, 8, \ + 15, 14, 13, 12, \ + 3, 2, 1, 0, \ + 7, 6, 5, 4, \ + 11, 10, 9, 8, \ + 15, 14, 13, 12 +pb_shuffle16be: db 1, 0, 3, 2, \ + 5, 4, 7, 6, \ + 9, 8, 11, 10, \ + 13, 12, 15, 14, \ + 1, 0, 3, 2, \ + 5, 4, 7, 6, \ + 9, 8, 11, 10, \ + 13, 12, 15, 14 SECTION .text ;----------------------------------------------------------------------------- @@ -738,3 +762,461 @@ YUYV_TO_UV_FN 3, uyvy, 1 NVXX_TO_UV_FN 5, nv12 NVXX_TO_UV_FN 5, nv21 %endif + +%if ARCH_X86_64 +%define RY_IDX 0 +%define GY_IDX 1 +%define BY_IDX 2 +%define RU_IDX 3 +%define GU_IDX 4 +%define BU_IDX 5 +%define RV_IDX 6 +%define GV_IDX 7 +%define BV_IDX 8 +%define RGB2YUV_SHIFT 15 + +%define R m0 +%define G m1 +%define B m2 + +%macro SWAP32 1 +%if mmsize > 16 || cpuflag(sse4) + pshufb m%1, [pb_shuffle32be] +%else + psrlw xm7, xm%1, 8 + psllw xm%1, 8 + por xm%1, xm7 + pshuflw xm%1, xm%1, (2 << 6 | 3 << 4 | 0 << 2 | 1 << 0) + pshufhw xm%1, xm%1, (2 << 6 | 3 << 4 | 0 << 2 | 1 << 0) +%endif +%endmacro + +; 1 - dest +; 2 - source +; 3 - is big endian +; 4 - load only 2 values on sse2 +%macro LOADF32 4 + %if notcpuflag(sse4) && %4 + %if %3 ; big endian + mov tmp1q, %2 + bswap tmp1q + movq xm%1, tmp1q + %else + movq m%1, %2 + %endif + %else + movu m%1, %2 + %if %3 + SWAP32 %1 + %endif + %endif + maxps m%1, m9 ; 0.0 (nan, -inf) -> 0.0 + mulps m%1, m8 ; [pd_65535f] + minps m%1, m8 ; +inf -> 65535 + ; cvtps2dq rounds to nearest int + ; assuming mxcsr register is default rounding + ; 0.40 -> 0.0, 0.50 -> 0.0, 0.51 -> 1.0 + cvtps2dq m%1, m%1 + + %if notcpuflag(sse4) && %4 + ; line up the 2 values in lanes 0,2 + %if %3 ; big endian + pshufd m%1, m%1, (3 << 6 | 0 << 4 | 2 << 2 | 1 << 0) + %else + pshufd m%1, m%1, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + %endif + %endif +%endmacro + +; 1 - dest +; 2 - source +; 3 - is big endian +%macro LOAD16 3 + %if cpuflag(sse4) || mmsize > 16 + pmovzxwd m%1, %2 + %if %3 ; bigendian + pshufb m%1, m8 ; [pb_shuffle16be] + %endif + %else + %if %3 ; bigendian + mov tmp1d, dword %2 + bswap tmp1d + movd xm%1, tmp1d + pshuflw m%1, m%1, (3 << 6 | 0 << 4 | 3 << 2 | 1 << 0) + pshufd m%1, m%1, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + %else + movd xm%1, %2 + punpcklwd m%1, m9 ; interleave words with zero + pshufd m%1, m%1, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + %endif + %endif +%endmacro + +%macro LOAD8_RGB 0 + %if cpuflag(sse4) || mmsize > 16 + pmovzxbd R, [srcRq + xq] + pmovzxbd G, [srcGq + xq] + pmovzxbd B, [srcBq + xq] + %else + ; thought this would be faster but from my measurments its not + ; movd m0, [srcRq + xq + 0]; overeads by 2 bytes + ; punpcklbw m0, m9 ; interleave bytes with zero + ; punpcklwd m0, m9 ; interleave words with zero + ; pshufd m0, m0, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + + movzx tmp2q, byte [srcRq + xq + 1] + movzx tmp1q, byte [srcRq + xq + 0] + shl tmp2q, 32 + or tmp1q, tmp2q + movq xm0, tmp1q + + movzx tmp2q, byte [srcGq + xq + 1] + movzx tmp3q, byte [srcGq + xq + 0] + shl tmp2q, 32 + or tmp3q, tmp2q + movq xm1, tmp3q + + movzx tmp2q, byte [srcBq + xq + 1] + movzx tmp1q, byte [srcBq + xq + 0] + shl tmp2q, 32 + or tmp1q, tmp2q + movq xm2, tmp1q + + pshufd m0, m0, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshufd m1, m1, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshufd m2, m2, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + %endif +%endmacro + +; 1 - dest +; 2 - source +; 3 - store only 2 values on sse2 +%macro STORE16 3 + %if %3 && notcpuflag(sse4) + pshufd m%2, m%2, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshuflw m%2, m%2, (3 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + movd %1, m%2 + %elif mmsize > 16 + pshufb m%2, m7 ; [pb_pack_shuffle16le] + vpermq m%2, m%2, (3 << 6 | 0 << 4 | 3 << 2 | 0 << 0) + movu %1, xm%2 + %else + %if cpuflag(sse4) + pshufb m%2, m7 ; [pb_pack_shuffle16le] + %else + pshuflw m%2, m%2, (1 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshufhw m%2, m%2, (1 << 6 | 1 << 4 | 2 << 2 | 0 << 0) + pshufd m%2, m%2, (3 << 6 | 3 << 4 | 2 << 2 | 0 << 0) + %endif + movq %1, m%2 + %endif +%endmacro + +%macro PMUL 3 +%if cpuflag(sse4) || mmsize > 16 + pmulld %1, %2, %3 +%else + pmuludq %1, %2, %3 +%endif +%endmacro + +; 1 - name +; 2 - depth +; 3 - is big endian +; 4 - is float +; in sse2 mode only 2 values are done per loop, due to lack of pmulld instruction +%macro planar_rgb_to_y_fn 4 +%if %2 == 8 + %define OFFSET (0x801<<(RGB2YUV_SHIFT-7)) + %define RSHIFT (RGB2YUV_SHIFT-6) +%else + %if %2 < 16 + %define SHIFT %2 + %define BPC %2 + %else + %define SHIFT 14 + %define BPC 16 + %endif + %define OFFSET ((16 << (RGB2YUV_SHIFT + BPC - 8)) + (1 << (RGB2YUV_SHIFT + SHIFT - 15))) + %define RSHIFT (RGB2YUV_SHIFT + SHIFT - 14) +%endif +cglobal planar_%1_to_y, 4, 12, 13, dst, src, w, rgb2yuv, srcR, srcG, srcB, x, tmp1, tmp2, tmp3, tmp4 + VBROADCASTSS m10, dword [rgb2yuvq + RY_IDX*4] ; ry + VBROADCASTSS m11, dword [rgb2yuvq + GY_IDX*4] ; gy + VBROADCASTSS m12, dword [rgb2yuvq + BY_IDX*4] ; by + pxor m9, m9 + + %if %4 + movu m8, [pd_65535f] + %endif + + %if cpuflag(sse4) || mmsize > 16 + movu m7, [pb_pack_shuffle16le] + %if %3 && %2 > 8 && %2 <= 16 + movu m8, [pb_shuffle16be] + %endif + %endif + + mov xq, OFFSET + movq xm6, xq + VBROADCASTSS m6, xm6 + + mov srcGq, [srcq + 0] + mov srcBq, [srcq + 8] + mov srcRq, [srcq + 16] + + xor xq, xq + %%loop_x: + %if %4 + LOADF32 0, [srcRq + xq*4], %3, 1 + LOADF32 1, [srcGq + xq*4], %3, 1 + LOADF32 2, [srcBq + xq*4], %3, 1 + %elif %2 == 8 + LOAD8_RGB + %else + LOAD16 0, [srcRq + xq*2], %3 + LOAD16 1, [srcGq + xq*2], %3 + LOAD16 2, [srcBq + xq*2], %3 + %endif + + PMUL R, R, m10 ; r*ry + PMUL G, G, m11 ; g*gy + PMUL B, B, m12 ; b*by + paddd m0, m6 ; + OFFSET + paddd B, G + paddd m0, B + psrad m0, RSHIFT + STORE16 [dstq + 2*xq], 0, 1 + + %if cpuflag(avx2) || cpuflag(sse4) + add xq, mmsize/4 + %else + add xd, 2 + %endif + cmp xd, wd + jl %%loop_x +RET +%endmacro + +; 1 - name +; 2 - depth +; 3 - is big endian +; 4 - is float +; in sse2 mode only 2 values are done per loop, due to lack of pmulld instruction +%macro planar_rgb_to_uv_fn 4 +%if %2 == 8 + %define OFFSET (0x4001<<(RGB2YUV_SHIFT-7)) + %define RSHIFT (RGB2YUV_SHIFT-6) +%else + %if %2 < 16 + %define SHIFT %2 + %define BPC %2 + %else + %define SHIFT 14 + %define BPC 16 + %endif + %define OFFSET ((128 << (RGB2YUV_SHIFT + BPC - 8)) + (1 << (RGB2YUV_SHIFT + SHIFT - 15))) + %define RSHIFT (RGB2YUV_SHIFT + SHIFT - 14) +%endif +cglobal planar_%1_to_uv, 5, 12, 16, dstU, dstV, src, w, rgb2yuv, srcR, srcG, srcB, x, tmp1, tmp2, tmp3 + VBROADCASTSS m10, dword [rgb2yuvq + RU_IDX*4] ; ru + VBROADCASTSS m11, dword [rgb2yuvq + GU_IDX*4] ; gu + VBROADCASTSS m12, dword [rgb2yuvq + BU_IDX*4] ; bu + VBROADCASTSS m13, dword [rgb2yuvq + RV_IDX*4] ; rv + VBROADCASTSS m14, dword [rgb2yuvq + GV_IDX*4] ; gv + VBROADCASTSS m15, dword [rgb2yuvq + BV_IDX*4] ; bv + pxor m9, m9 + + %if %4 + movu m8, [pd_65535f] + %endif + + %if cpuflag(sse4) || mmsize > 16 + movu m7, [pb_pack_shuffle16le] + %if %3 && %2 > 8 && %2 <= 16 + movu m8, [pb_shuffle16be] + %endif + %endif + + mov xq, OFFSET + movq xm6, xq + VBROADCASTSS m6, xm6 + + mov srcGq, [srcq + 0] + mov srcBq, [srcq + 8] + mov srcRq, [srcq + 16] + + xor xq, xq + %%loop_x: + %if %4 + LOADF32 0, [srcRq + xq*4], %3, 1 + LOADF32 1, [srcGq + xq*4], %3, 1 + LOADF32 2, [srcBq + xq*4], %3, 1 + %elif %2 == 8 + LOAD8_RGB + %else + LOAD16 0, [srcRq + xq*2], %3 + LOAD16 1, [srcGq + xq*2], %3 + LOAD16 2, [srcBq + xq*2], %3 + %endif + + PMUL m5, R, m10 ; r*ru + PMUL m4, G, m11 ; b*gu + paddd m4, m5 + PMUL m5, B, m12 ; b*bu + paddd m4, m6 ; + OFFSET + paddd m4, m5 + psrad m4, RSHIFT + STORE16 [dstUq + 2*xq], 4, 1 + + PMUL R, R, m13 ; r*rv + PMUL G, G, m14 ; g*gv*g + PMUL B, B, m15 ; b*bv + paddd m0, m6 ; + OFFSET + paddd B, G + paddd m0, B + psrad m0, RSHIFT + STORE16 [dstVq + 2*xq], 0, 1 + + %if cpuflag(avx2) || cpuflag(sse4) + add xd, mmsize/4 + %else + add xd, 2 + %endif + cmp xd, wd + jl %%loop_x +RET +%endmacro + +; 1 - name +; 2 - depth +; 3 - is big endian +; 4 - is float +%macro planar_rgb_to_a_fn 4 +cglobal planar_%1_to_a, 4, 6, 10, dst, src, w, rgb2yuv, srcA, x + %if %4 && (cpuflag(sse4) || mmsize > 16) + movu m7, [pb_pack_shuffle16le] + %elif %3 && (cpuflag(sse4) || mmsize > 16) + movu m7, [pb_shuffle16be] + %endif + + %if %4 + movu m8, [pd_65535f] + %endif + + pxor m9, m9 + mov srcAq, [srcq + 24] + xor xq, xq + %%loop_x: + %if %4 ; float + LOADF32 0, [srcAq + xq*4], %3, 0 + STORE16 [dstq + xq*2], 0, 0 + add xq, mmsize/4 + %elif %2 == 8 + ; only need to convert 8bit value to 16bit + %if cpuflag(sse4) || mmsize > 16 + pmovzxbw m0, [srcAq + xq] + %else + movsd m0, [srcAq + xq] + punpcklbw m0, m9 ; interleave bytes with zero + %endif + psllw m0, 6 + movu [dstq + xq*2], m0 + add xq, mmsize/2 + %else + ; only need to convert 16bit format to 16le + movu m0, [srcAq + xq*2] + %if %3 ; bigendian + %if cpuflag(sse4) || mmsize > 16 + pshufb m0, m7 ; [pb_shuffle16be] + %else + psrlw m7, m0, 8 + psllw m0, 8 + por m0, m7 + %endif + %endif + %if %2 < 16 + psllw m0, (14 - %2) + %endif + movu [dstq + xq*2], m0 + add xq, mmsize/2 + %endif + cmp xd, wd + jl %%loop_x +RET +%endmacro + +; 1 - name +; 2 - depth +; 3 - is float +%macro planer_rgbxx_y_fn_decl 3 +planar_rgb_to_y_fn %1le, %2, 0, %3 +planar_rgb_to_y_fn %1be, %2, 1, %3 +%endmacro + +; 1 - name +; 2 - depth +; 3 - is float +%macro planer_rgbxx_uv_fn_decl 3 +planar_rgb_to_uv_fn %1le, %2, 0, %3 +planar_rgb_to_uv_fn %1be, %2, 1, %3 +%endmacro + +; 1 - name +; 2 - depth +; 3 - is float +%macro planer_rgbxx_a_fn_decl 3 +planar_rgb_to_a_fn %1le, %2, 0, %3 +planar_rgb_to_a_fn %1be, %2, 1, %3 +%endmacro + +%macro planar_rgb_y_all_fn_decl 0 +planar_rgb_to_y_fn rgb, 8, 0, 0 +planer_rgbxx_y_fn_decl rgb9, 9, 0 +planer_rgbxx_y_fn_decl rgb10, 10, 0 +planer_rgbxx_y_fn_decl rgb12, 12, 0 +planer_rgbxx_y_fn_decl rgb14, 14, 0 +planer_rgbxx_y_fn_decl rgb16, 16, 0 +planer_rgbxx_y_fn_decl rgbf32, 32, 1 +%endmacro + +%macro planar_rgb_uv_all_fn_decl 0 +planar_rgb_to_uv_fn rgb, 8, 0, 0 +planer_rgbxx_uv_fn_decl rgb9, 9, 0 +planer_rgbxx_uv_fn_decl rgb10, 10, 0 +planer_rgbxx_uv_fn_decl rgb12, 12, 0 +planer_rgbxx_uv_fn_decl rgb14, 14, 0 +planer_rgbxx_uv_fn_decl rgb16, 16, 0 +planer_rgbxx_uv_fn_decl rgbf32, 32, 1 +%endmacro + +%macro planar_rgb_a_all_fn_decl 0 +planar_rgb_to_a_fn rgb, 8, 0, 0 +planer_rgbxx_a_fn_decl rgb10, 10, 0 +planer_rgbxx_a_fn_decl rgb12, 12, 0 +planer_rgbxx_a_fn_decl rgb16, 16, 0 +planer_rgbxx_a_fn_decl rgbf32, 32, 1 +%endmacro + +; sse2 to_y only matches c speed with current implementation +; except on floating point formats +INIT_XMM sse2 +planer_rgbxx_y_fn_decl rgbf32, 32, 1 +planar_rgb_uv_all_fn_decl +planar_rgb_a_all_fn_decl + +; sse4 to_a conversions are just the sse2 ones +; except on floating point formats +INIT_XMM sse4 +planar_rgb_y_all_fn_decl +planar_rgb_uv_all_fn_decl +planer_rgbxx_a_fn_decl rgbf32, 32, 1 + +%if HAVE_AVX2_EXTERNAL +INIT_YMM avx2 +planar_rgb_y_all_fn_decl +planar_rgb_uv_all_fn_decl +planar_rgb_a_all_fn_decl +%endif + +%endif ; ARCH_X86_64 \ No newline at end of file diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index e8bc15b6ee..b377b398d1 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -387,6 +387,80 @@ YUV2GBRP_DECL(sse2); YUV2GBRP_DECL(sse4); YUV2GBRP_DECL(avx2); +#define INPUT_PLANAR_RGB_Y_FN_DECL(fmt, opt) \ +void ff_planar_##fmt##_to_y_##opt(uint8_t *dst, \ + const uint8_t *src[4], int w, int32_t *rgb2yuv) + +#define INPUT_PLANAR_RGB_UV_FN_DECL(fmt, opt) \ +void ff_planar_##fmt##_to_uv_##opt(uint8_t *dstU, uint8_t *dstV, \ + const uint8_t *src[4], int w, int32_t *rgb2yuv) + +#define INPUT_PLANAR_RGB_A_FN_DECL(fmt, opt) \ +void ff_planar_##fmt##_to_a_##opt(uint8_t *dst, \ + const uint8_t *src[4], int w, int32_t *rgb2yuv) + + +#define INPUT_PLANAR_RGBXX_A_DECL(fmt, opt) \ +INPUT_PLANAR_RGB_A_FN_DECL(fmt##le, opt); \ +INPUT_PLANAR_RGB_A_FN_DECL(fmt##be, opt); + +#define INPUT_PLANAR_RGBXX_Y_DECL(fmt, opt) \ +INPUT_PLANAR_RGB_Y_FN_DECL(fmt##le, opt); \ +INPUT_PLANAR_RGB_Y_FN_DECL(fmt##be, opt); + +#define INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt) \ +INPUT_PLANAR_RGB_UV_FN_DECL(fmt##le, opt); \ +INPUT_PLANAR_RGB_UV_FN_DECL(fmt##be, opt); + +#define INPUT_PLANAR_RGBXX_YUVA_DECL(fmt, opt) \ +INPUT_PLANAR_RGBXX_Y_DECL(fmt, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt); \ +INPUT_PLANAR_RGBXX_A_DECL(fmt, opt); + +#define INPUT_PLANAR_RGBXX_YUV_DECL(fmt, opt) \ +INPUT_PLANAR_RGBXX_Y_DECL(fmt, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt); + +#define INPUT_PLANAR_RGBXX_UVA_DECL(fmt, opt) \ +INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt); \ +INPUT_PLANAR_RGBXX_A_DECL(fmt, opt); + +#define INPUT_PLANAR_RGB_A_ALL_DECL(opt) \ +INPUT_PLANAR_RGB_A_FN_DECL(rgb, opt); \ +INPUT_PLANAR_RGBXX_A_DECL(rgb10, opt); \ +INPUT_PLANAR_RGBXX_A_DECL(rgb12, opt); \ +INPUT_PLANAR_RGBXX_A_DECL(rgb16, opt); \ +INPUT_PLANAR_RGBXX_A_DECL(rgbf32, opt); + +#define INPUT_PLANAR_RGB_Y_ALL_DECL(opt) \ +INPUT_PLANAR_RGB_Y_FN_DECL(rgb, opt); \ +INPUT_PLANAR_RGBXX_Y_DECL(rgb9, opt); \ +INPUT_PLANAR_RGBXX_Y_DECL(rgb10, opt); \ +INPUT_PLANAR_RGBXX_Y_DECL(rgb12, opt); \ +INPUT_PLANAR_RGBXX_Y_DECL(rgb14, opt); \ +INPUT_PLANAR_RGBXX_Y_DECL(rgb16, opt); \ +INPUT_PLANAR_RGBXX_Y_DECL(rgbf32, opt); + +#define INPUT_PLANAR_RGB_UV_ALL_DECL(opt) \ +INPUT_PLANAR_RGB_UV_FN_DECL(rgb, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(rgb9, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(rgb10, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(rgb12, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(rgb14, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(rgb16, opt); \ +INPUT_PLANAR_RGBXX_UV_DECL(rgbf32, opt); + +INPUT_PLANAR_RGBXX_Y_DECL(rgbf32, sse2); +INPUT_PLANAR_RGB_UV_ALL_DECL(sse2); +INPUT_PLANAR_RGB_A_ALL_DECL(sse2); + +INPUT_PLANAR_RGB_Y_ALL_DECL(sse4); +INPUT_PLANAR_RGB_UV_ALL_DECL(sse4); +INPUT_PLANAR_RGBXX_A_DECL(rgbf32, sse4); + +INPUT_PLANAR_RGB_Y_ALL_DECL(avx2); +INPUT_PLANAR_RGB_UV_ALL_DECL(avx2); +INPUT_PLANAR_RGB_A_ALL_DECL(avx2); #endif av_cold void ff_sws_init_swscale_x86(SwsContext *c) @@ -620,6 +694,102 @@ switch(c->dstBpc){ \ } } + +#define INPUT_PLANER_RGB_A_FUNC_CASE(fmt, name, opt) \ + case fmt: \ + c->readAlpPlanar = ff_planar_##name##_to_a_##opt; + +#define INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ + case rgba_fmt: \ + case rgb_fmt: \ + c->readLumPlanar = ff_planar_##name##_to_y_##opt; \ + c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \ + break; + +#define INPUT_PLANER_RGB_YUV_FUNC_CASE(fmt, name, opt) \ + case fmt: \ + c->readLumPlanar = ff_planar_##name##_to_y_##opt; \ + c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \ + break; + +#define INPUT_PLANER_RGB_UV_FUNC_CASE(fmt, name, opt) \ + case fmt: \ + c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \ + break; + +#define INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##BE, name##be, opt) \ + INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt) + +#define INPUT_PLANER_RGBAXX_UVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##BE, name##be, opt) \ + INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt) + +#define INPUT_PLANER_RGBAXX_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \ + INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt##LE, rgba_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt##BE, rgba_fmt##BE, name##be, opt) + +#define INPUT_PLANER_RGBXX_YUV_FUNC_CASE(rgb_fmt, name, opt) \ + INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt) + +#define INPUT_PLANER_RGBXX_UV_FUNC_CASE(rgb_fmt, name, opt) \ + INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \ + INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt) + +#define INPUT_PLANER_RGB_YUVA_ALL_CASES(opt) \ + INPUT_PLANER_RGB_A_FUNC_CASE( AV_PIX_FMT_GBRAP, rgb, opt) \ + INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, opt) \ + INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, opt) \ + INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, opt) \ + INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, opt) \ + INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, opt) \ + INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, opt) \ + INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, opt) + + + if (EXTERNAL_SSE2(cpu_flags)) { + switch (c->srcFormat) { + INPUT_PLANER_RGB_A_FUNC_CASE( AV_PIX_FMT_GBRAP, rgb, sse2); + INPUT_PLANER_RGB_UV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse2); + INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse2); + INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse2); + INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, sse2); + INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, sse2); + INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, sse2); + INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, sse2); + default: + break; + } + } + + if (EXTERNAL_SSE4(cpu_flags)) { + switch (c->srcFormat) { + case AV_PIX_FMT_GBRAP: + INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse4); + INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse4); + INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse4); + INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, sse4); + INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, sse4); + INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, sse4); + INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, sse4); + default: + break; + } + } + + if (EXTERNAL_AVX2_FAST(cpu_flags)) { + switch (c->srcFormat) { + INPUT_PLANER_RGB_YUVA_ALL_CASES(avx2) + default: + break; + } + } + if(c->flags & SWS_FULL_CHR_H_INT) { /* yuv2gbrp uses the SwsContext for yuv coefficients diff --git a/tests/checkasm/sw_gbrp.c b/tests/checkasm/sw_gbrp.c index 61b2b9d6a1..848e5366ad 100644 --- a/tests/checkasm/sw_gbrp.c +++ b/tests/checkasm/sw_gbrp.c @@ -190,9 +190,225 @@ static void check_output_yuv2gbrp(void) sws_freeContext(ctx); } +#undef LARGEST_INPUT_SIZE +#undef INPUT_SIZES + +static void check_input_planar_rgb_to_y(void) +{ + struct SwsContext *ctx; + const AVPixFmtDescriptor *desc; + int fmi, isi; + int dstW, byte_size; +#define LARGEST_INPUT_SIZE 512 +#define INPUT_SIZES 6 + static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; + uint8_t *src[4]; + int32_t rgb2yuv[9] = {0}; + + declare_func(void, uint8_t *dst, uint8_t *src[4], int w, int32_t *rgb2yuv); + + LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]); + + LOCAL_ALIGNED_8(uint8_t, dst0_y, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst1_y, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + + randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t)); + + src[0] = (uint8_t*)src_g; + src[1] = (uint8_t*)src_b; + src[2] = (uint8_t*)src_r; + src[3] = (uint8_t*)src_a; + + ctx = sws_alloc_context(); + if (sws_init_context(ctx, NULL, NULL) < 0) + fail(); + + for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { + for (isi = 0; isi < INPUT_SIZES; isi++ ) { + desc = av_pix_fmt_desc_get(planar_fmts[fmi]); + ctx->srcFormat = planar_fmts[fmi]; + ctx->dstFormat = AV_PIX_FMT_YUVA444P16; + byte_size = 2; + dstW = input_sizes[isi]; + + ff_sws_init_scale(ctx); + if(check_func(ctx->readLumPlanar, "planar_%s_to_y_%d", desc->name, dstW)) { + memset(dst0_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + memset(dst1_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + + call_ref(dst0_y, src, dstW, rgb2yuv); + call_new(dst1_y, src, dstW, rgb2yuv); + + if (memcmp(dst0_y, dst1_y, dstW * byte_size)) + fail(); + + bench_new(dst1_y, src, dstW, rgb2yuv); + + } + } + } + sws_freeContext(ctx); +} + +#undef LARGEST_INPUT_SIZE +#undef INPUT_SIZES + +static void check_input_planar_rgb_to_uv(void) +{ + struct SwsContext *ctx; + const AVPixFmtDescriptor *desc; + int fmi, isi; + int dstW, byte_size; +#define LARGEST_INPUT_SIZE 512 +#define INPUT_SIZES 6 + static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; + uint8_t *src[4]; + int32_t rgb2yuv[9] = {0}; + + declare_func(void, uint8_t *dstU, uint8_t *dstV, + uint8_t *src[4], int w, int32_t *rgb2yuv); + + LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]); + + LOCAL_ALIGNED_8(uint8_t, dst0_u, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst0_v, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + + LOCAL_ALIGNED_8(uint8_t, dst1_u, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst1_v, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + + randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t)); + + src[0] = (uint8_t*)src_g; + src[1] = (uint8_t*)src_b; + src[2] = (uint8_t*)src_r; + src[3] = (uint8_t*)src_a; + + ctx = sws_alloc_context(); + if (sws_init_context(ctx, NULL, NULL) < 0) + fail(); + + for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { + for (isi = 0; isi < INPUT_SIZES; isi++ ) { + desc = av_pix_fmt_desc_get(planar_fmts[fmi]); + ctx->srcFormat = planar_fmts[fmi]; + ctx->dstFormat = AV_PIX_FMT_YUVA444P16; + byte_size = 2; + dstW = input_sizes[isi]; + + ff_sws_init_scale(ctx); + if(check_func(ctx->readChrPlanar, "planar_%s_to_uv_%d", desc->name, dstW)) { + memset(dst0_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + memset(dst0_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + memset(dst1_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + memset(dst1_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); + + call_ref(dst0_u, dst0_v, src, dstW, rgb2yuv); + call_new(dst1_u, dst1_v, src, dstW, rgb2yuv); + + if (memcmp(dst0_u, dst1_u, dstW * byte_size) || + memcmp(dst0_v, dst1_v, dstW * byte_size)) + fail(); + + bench_new(dst1_u, dst1_v, src, dstW, rgb2yuv); + } + } + } + sws_freeContext(ctx); +} + +#undef LARGEST_INPUT_SIZE +#undef INPUT_SIZES + +static void check_input_planar_rgb_to_a(void) +{ + struct SwsContext *ctx; + const AVPixFmtDescriptor *desc; + int fmi, isi; + int dstW, byte_size; +#define LARGEST_INPUT_SIZE 512 +#define INPUT_SIZES 6 + static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; + uint8_t *src[4]; + int32_t rgb2yuv[9] = {0}; + + declare_func(void, uint8_t *dst, uint8_t *src[4], int w, int32_t *rgb2yuv); + + LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]); + + LOCAL_ALIGNED_8(uint8_t, dst0_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + LOCAL_ALIGNED_8(uint8_t, dst1_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]); + + randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t)); + randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t)); + + src[0] = (uint8_t*)src_g; + src[1] = (uint8_t*)src_b; + src[2] = (uint8_t*)src_r; + src[3] = (uint8_t*)src_a; + + ctx = sws_alloc_context(); + if (sws_init_context(ctx, NULL, NULL) < 0) + fail(); + + for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { + for (isi = 0; isi < INPUT_SIZES; isi++ ) { + desc = av_pix_fmt_desc_get(planar_fmts[fmi]); + if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) + continue; + + ctx->srcFormat = planar_fmts[fmi]; + ctx->dstFormat = AV_PIX_FMT_YUVA444P16; + byte_size = 2; + dstW = input_sizes[isi]; + + ff_sws_init_scale(ctx); + if(check_func(ctx->readAlpPlanar, "planar_%s_to_a_%d", desc->name, dstW)) { + memset(dst0_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t)); + memset(dst1_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t)); + + call_ref(dst0_a, src, dstW, rgb2yuv); + call_new(dst1_a, src, dstW, rgb2yuv); + + if (memcmp(dst0_a, dst1_a, dstW * byte_size)) + fail(); + bench_new(dst1_a, src, dstW, rgb2yuv); + } + } + } + sws_freeContext(ctx); +} void checkasm_check_sw_gbrp(void) { check_output_yuv2gbrp(); report("output_yuv2gbrp"); + + check_input_planar_rgb_to_y(); + report("input_planar_rgb_y"); + + check_input_planar_rgb_to_uv(); + report("input_planar_rgb_uv"); + + check_input_planar_rgb_to_a(); + report("input_planar_rgb_a"); }