Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Shiyou Yin <yinshiyou-hf@loongson.cn>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v1 1/3] swscale/la: Optimize hscale functions with lasx.
Date: Wed, 31 Aug 2022 16:42:11 +0800
Message-ID: <39DE5C82-29D1-47FD-887C-C970D6BB77A6@loongson.cn> (raw)
In-Reply-To: <20220829115144.10422-2-chenhao@loongson.cn>


> +
> +void planar_rgb_to_uv_lasx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4],
> +                           int width, int32_t *rgb2yuv)
> +{
> +    int i;
> +    uint16_t *dstU   = (uint16_t *)_dstU;
> +    uint16_t *dstV   = (uint16_t *)_dstV;
> +    int set          = 0x4001 << (RGB2YUV_SHIFT - 7);
> +    int len          = width - 15;
> +    int32_t tem_ru   = rgb2yuv[RU_IDX], tem_gu = rgb2yuv[GU_IDX];
> +    int32_t tem_bu = rgb2yuv[BU_IDX], tem_rv   = rgb2yuv[RV_IDX];
> +    int32_t tem_gv = rgb2yuv[GV_IDX], tem_bv = rgb2yuv[BV_IDX];
> +    int shift        = RGB2YUV_SHIFT - 6;
> +    const uint8_t *src0 = src[0], *src1 = src[1], *src2 = src[2];
> +    __m256i ru, gu, bu, rv, gv, bv;
> +    __m256i mask = {0x0D0C090805040100, 0x1D1C191815141110,
> +                    0x0D0C090805040100, 0x1D1C191815141110};
> +    __m256i temp = __lasx_xvreplgr2vr_w(set);
> +    __m256i sra  = __lasx_xvreplgr2vr_w(shift);
> +
> +    ru = __lasx_xvreplgr2vr_w(tem_ru);
> +    gu = __lasx_xvreplgr2vr_w(tem_gu);
> +    bu = __lasx_xvreplgr2vr_w(tem_bu);
> +    rv = __lasx_xvreplgr2vr_w(tem_rv);
> +    gv = __lasx_xvreplgr2vr_w(tem_gv);
> +    bv = __lasx_xvreplgr2vr_w(tem_bv);
> +    for (i = 0; i < len; i += 16) {
> +        __m256i _g, _b, _r;
> +        __m256i g_l, g_h, b_l, b_h, r_l, r_h;
> +        __m256i v_l, v_h, u_l, u_h, u_lh, v_lh;
> +
> +        DUP2_ARG2(__lasx_xvld, src0 + i, 0, src1 + i, 0, _g, _b);
> +        _r   = __lasx_xvld(src2 + i, 0);

In this case, it’s more readable not to use DUP2.
The following extensions of r,g,b are the same.

> +        g_l = __lasx_vext2xv_wu_bu(_g);
> +        DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_l, r_l);
> +        _g   = __lasx_xvpermi_d(_g, 0x01);
> +        _b   = __lasx_xvpermi_d(_b, 0x01);
> +        _r   = __lasx_xvpermi_d(_r, 0x01);
> +        g_h = __lasx_vext2xv_wu_bu(_g);
> +        DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_h, r_h);
> +        u_l  = __lasx_xvmadd_w(temp, ru, r_l);
> +        u_h  = __lasx_xvmadd_w(temp, ru, r_h);
> +        v_l  = __lasx_xvmadd_w(temp, rv, r_l);
> +        v_h  = __lasx_xvmadd_w(temp, rv, r_h);
> +        u_l  = __lasx_xvmadd_w(u_l, gu, g_l);
> +        u_l  = __lasx_xvmadd_w(u_l, bu, b_l);
> +        u_h  = __lasx_xvmadd_w(u_h, gu, g_h);
> +        u_h  = __lasx_xvmadd_w(u_h, bu, b_h);
> +        v_l  = __lasx_xvmadd_w(v_l, gv, g_l);
> +        v_l  = __lasx_xvmadd_w(v_l, bv, b_l);
> +        v_h  = __lasx_xvmadd_w(v_h, gv, g_h);
> +        v_h  = __lasx_xvmadd_w(v_h, bv, b_h);
> +        u_l  = __lasx_xvsra_w(u_l, sra);
> +        u_h  = __lasx_xvsra_w(u_h, sra);
> +        v_l  = __lasx_xvsra_w(v_l, sra);
> +        v_h  = __lasx_xvsra_w(v_h, sra);
> +        DUP2_ARG3(__lasx_xvshuf_b, u_h, u_l, mask, v_h, v_l, mask, u_lh, v_lh);
> +        u_lh = __lasx_xvpermi_d(u_lh, 0xD8);
> +        v_lh = __lasx_xvpermi_d(v_lh, 0xD8);
> +        __lasx_xvst(u_lh, (dstU + i), 0);
> +        __lasx_xvst(v_lh, (dstV + i), 0);
> +    }
> +    if (width - i >= 8) {
> +        __m256i _g, _b, _r;
> +        __m256i g_l, b_l, r_l;
> +        __m256i v_l, u_l, u, v;
> +
> +        _g  = __lasx_xvldrepl_d((src0 + i), 0);
> +        _b  = __lasx_xvldrepl_d((src1 + i), 0);
> +        _r  = __lasx_xvldrepl_d((src2 + i), 0);
> +        g_l = __lasx_vext2xv_wu_bu(_g);
> +        DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_l, r_l);
> +        u_l = __lasx_xvmadd_w(temp, ru, r_l);
> +        v_l = __lasx_xvmadd_w(temp, rv, r_l);
> +        u_l = __lasx_xvmadd_w(u_l, gu, g_l);
> +        u_l = __lasx_xvmadd_w(u_l, bu, b_l);
> +        v_l = __lasx_xvmadd_w(v_l, gv, g_l);
> +        v_l = __lasx_xvmadd_w(v_l, bv, b_l);
> +        u_l = __lasx_xvsra_w(u_l, sra);
> +        v_l = __lasx_xvsra_w(v_l, sra);
> +        DUP2_ARG3(__lasx_xvshuf_b, u_l, u_l, mask, v_l, v_l, mask, u, v);
> +        __lasx_xvstelm_d(u, (dstU + i), 0, 0);
> +        __lasx_xvstelm_d(u, (dstU + i), 8, 2);
> +        __lasx_xvstelm_d(v, (dstV + i), 0, 0);
> +        __lasx_xvstelm_d(v, (dstV + i), 8, 2);
> +        i += 8;
> +    }
> +    for (; i < width; i++) {
> +        int g = src[0][i];
> +        int b = src[1][i];
> +        int r = src[2][i];
> +
> +        dstU[i] = (tem_ru * r + tem_gu * g + tem_bu * b + set) >> shift;
> +        dstV[i] = (tem_rv * r + tem_gv * g + tem_bv * b + set) >> shift;
> +    }

Suggest to use following condition controls instead.
While(i=width; i>=16; i-=16) {}
if(i>=8) {}
while(I--){}

_______________________________________________
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:[~2022-08-31  8:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29 11:51 [FFmpeg-devel] Add LoongArch SIMD optimization in swscale lib Hao Chen
2022-08-29 11:51 ` [FFmpeg-devel] [PATCH v1 1/3] swscale/la: Optimize hscale functions with lasx Hao Chen
2022-08-31  8:42   ` Shiyou Yin [this message]
2022-08-29 11:51 ` [FFmpeg-devel] [PATCH v1 2/3] swscale/la: Add yuv2rgb_lasx.c and rgb2rgb_lasx.c files Hao Chen
2022-08-31  9:56   ` Shiyou Yin
2022-08-29 11:51 ` [FFmpeg-devel] [PATCH v1 3/3] swscale/la: Add output_lasx.c file Hao Chen
  -- strict thread matches above, loose matches on Subject: below --
2022-08-29 11:26 [FFmpeg-devel] Add loongarch SIMD optimization in swscale lib Hao Chen
2022-08-29 11:26 ` [FFmpeg-devel] [PATCH v1 1/3] swscale/la: Optimize hscale functions with lasx Hao Chen

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=39DE5C82-29D1-47FD-887C-C970D6BB77A6@loongson.cn \
    --to=yinshiyou-hf@loongson.cn \
    --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