[FFmpeg-devel] [PATCH v2 1/3] swscale/la: Optimize hscale functions with lasx.

Hao Chen chenhao at loongson.cn
Tue Sep 6 11:06:33 EEST 2022


在 2022/9/3 下午8:31, Andreas Rheinhardt 写道:
> Hao Chen:
>> ffmpeg -i 1_h264_1080p_30fps_3Mbps.mp4 -f rawvideo -s 640x480 -y /dev/null -an
>> before: 101fps
>> after:  138fps
>>
>> Signed-off-by: Hao Chen <chenhao at loongson.cn>
>> ---
>>   libswscale/loongarch/Makefile                 |   3 +
>>   libswscale/loongarch/input_lasx.c             | 202 ++++
>>   libswscale/loongarch/swscale_init_loongarch.c |  50 +
>>   libswscale/loongarch/swscale_lasx.c           | 972 ++++++++++++++++++
>>   libswscale/loongarch/swscale_loongarch.h      |  50 +
>>   libswscale/swscale.c                          |   2 +
>>   libswscale/swscale_internal.h                 |   2 +
>>   libswscale/utils.c                            |  13 +-
>>   8 files changed, 1293 insertions(+), 1 deletion(-)
>>   create mode 100644 libswscale/loongarch/Makefile
>>   create mode 100644 libswscale/loongarch/input_lasx.c
>>   create mode 100644 libswscale/loongarch/swscale_init_loongarch.c
>>   create mode 100644 libswscale/loongarch/swscale_lasx.c
>>   create mode 100644 libswscale/loongarch/swscale_loongarch.h
>>
>> diff --git a/libswscale/loongarch/Makefile b/libswscale/loongarch/Makefile
>> new file mode 100644
>> index 0000000000..586a1717b6
>> --- /dev/null
>> +++ b/libswscale/loongarch/Makefile
>> @@ -0,0 +1,3 @@
>> +OBJS-$(CONFIG_SWSCALE)      += loongarch/swscale_init_loongarch.o
>> +LASX-OBJS-$(CONFIG_SWSCALE) += loongarch/swscale_lasx.o \
>> +                               loongarch/input_lasx.o   \
>> diff --git a/libswscale/loongarch/input_lasx.c b/libswscale/loongarch/input_lasx.c
>> new file mode 100644
>> index 0000000000..c3060ea6a3
>> --- /dev/null
>> +++ b/libswscale/loongarch/input_lasx.c
>> @@ -0,0 +1,202 @@
>> +/*
>> + * Copyright (C) 2022 Loongson Technology Corporation Limited
>> + * Contributed by Hao Chen(chenhao at loongson.cn)
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 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
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser 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 "swscale_loongarch.h"
>> +#include "libavutil/loongarch/loongson_intrinsics.h"
>> +
>> +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;
>> +
>> +        _g  = __lasx_xvldx(src0, i);
> According to
> https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7366 this
> patchset creates new warnings and as I have explained in
> https://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/300682.html this
> is (most likely) due to lasxintrin.h and lsxintrin.h not accepting
> pointers to void in the load-functions. The above __lasx_xvldx() is
> affected by this. Could you please fix this issue and provide an updated
> toolchain able to compile lsx and lasx?
>
Thanks for your attention to loongson. The __lasx_xvldx() is defined in 
lasxintrin.h as following:

extern __inline __attribute__((__gnu_inline__, __always_inline__, 
__artificial__))
__m256i __lasx_xvldx(void * _1, long int _2)

{
     return (void)__builtin_lasx_xvstx((v32i8)_1, (void *)_2, (long int)_3);
}

A warning appears when the parameter passed is a pointer to a const.

Now, I have fed it back to my colleagues in the compiler group to 
discuss how to solve it.

I believe it will be solved soon.



More information about the ffmpeg-devel mailing list