swscale/aarch64: Add bgr24 to yuv
Test on Apple M1 with kperf : -O3 : -O3 -fno-vectorize bgr24_to_uv_8_c : 28.5 : 52.5 bgr24_to_uv_8_neon : 54.5 : 59.7 bgr24_to_uv_128_c : 294.0 : 830.7 bgr24_to_uv_128_neon : 99.7 : 112.0 bgr24_to_uv_1080_c : 965.0 : 6624.0 bgr24_to_uv_1080_neon : 751.5 : 754.7 bgr24_to_uv_1920_c : 1693.2 : 11554.5 bgr24_to_uv_1920_neon : 1292.5 : 1307.5 bgr24_to_uv_half_8_c : 54.2 : 37.0 bgr24_to_uv_half_8_neon : 27.2 : 22.5 bgr24_to_uv_half_128_c : 127.2 : 392.5 bgr24_to_uv_half_128_neon : 63.0 : 52.0 bgr24_to_uv_half_1080_c : 880.2 : 3329.0 bgr24_to_uv_half_1080_neon : 401.5 : 390.7 bgr24_to_uv_half_1920_c : 1585.7 : 6390.7 bgr24_to_uv_half_1920_neon : 694.7 : 698.7 bgr24_to_y_8_c : 21.7 : 22.5 bgr24_to_y_8_neon : 797.2 : 25.5 bgr24_to_y_128_c : 88.0 : 280.5 bgr24_to_y_128_neon : 63.7 : 55.0 bgr24_to_y_1080_c : 616.7 : 2208.7 bgr24_to_y_1080_neon : 900.0 : 452.0 bgr24_to_y_1920_c : 1093.2 : 3894.7 bgr24_to_y_1920_neon : 777.2 : 767.5 Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
This commit is contained in:
		
							parent
							
								
									bef77c6c9c
								
							
						
					
					
						commit
						b8b71be07a
					
				@ -20,7 +20,7 @@
 | 
			
		||||
 | 
			
		||||
#include "libavutil/aarch64/asm.S"
 | 
			
		||||
 | 
			
		||||
.macro rgb24_to_yuv_load_rgb, src
 | 
			
		||||
.macro rgb_to_yuv_load_rgb src
 | 
			
		||||
        ld3             { v16.16b, v17.16b, v18.16b }, [\src]
 | 
			
		||||
        uxtl            v19.8h, v16.8b             // v19: r
 | 
			
		||||
        uxtl            v20.8h, v17.8b             // v20: g
 | 
			
		||||
@ -30,7 +30,7 @@
 | 
			
		||||
        uxtl2           v24.8h, v18.16b            // v24: b
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
.macro rgb24_to_yuv_product, r, g, b, dst1, dst2, dst, coef0, coef1, coef2, right_shift
 | 
			
		||||
.macro rgb_to_yuv_product r, g, b, dst1, dst2, dst, coef0, coef1, coef2, right_shift
 | 
			
		||||
        mov             \dst1\().16b, v6.16b                    // dst1 = const_offset
 | 
			
		||||
        mov             \dst2\().16b, v6.16b                    // dst2 = const_offset
 | 
			
		||||
        smlal           \dst1\().4s, \coef0\().4h, \r\().4h     // dst1 += rx * r
 | 
			
		||||
@ -43,12 +43,20 @@
 | 
			
		||||
        sqshrn2         \dst\().8h, \dst2\().4s, \right_shift   // dst_higher_half = dst2 >> right_shift
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
function ff_bgr24ToY_neon, export=1
 | 
			
		||||
        cmp             w4, #0                  // check width > 0
 | 
			
		||||
        ldp             w12, w11, [x5]          // w12: ry, w11: gy
 | 
			
		||||
        ldr             w10, [x5, #8]           // w10: by
 | 
			
		||||
        b.gt            4f
 | 
			
		||||
        ret
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
function ff_rgb24ToY_neon, export=1
 | 
			
		||||
        cmp             w4, #0                  // check width > 0
 | 
			
		||||
        ldp             w10, w11, [x5]          // w10: ry, w11: gy
 | 
			
		||||
        ldr             w12, [x5, #8]           // w12: by
 | 
			
		||||
        b.le            3f
 | 
			
		||||
 | 
			
		||||
4:
 | 
			
		||||
        mov             w9, #256                // w9 = 1 << (RGB2YUV_SHIFT - 7)
 | 
			
		||||
        movk            w9, #8, lsl #16         // w9 += 32 << (RGB2YUV_SHIFT - 1)
 | 
			
		||||
        dup             v6.4s, w9               // w9: const_offset
 | 
			
		||||
@ -59,9 +67,9 @@ function ff_rgb24ToY_neon, export=1
 | 
			
		||||
        dup             v2.8h, w12
 | 
			
		||||
        b.lt            2f
 | 
			
		||||
1:
 | 
			
		||||
        rgb24_to_yuv_load_rgb x1
 | 
			
		||||
        rgb24_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9
 | 
			
		||||
        rgb24_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9
 | 
			
		||||
        rgb_to_yuv_load_rgb x1
 | 
			
		||||
        rgb_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9
 | 
			
		||||
        rgb_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9
 | 
			
		||||
        sub             w4, w4, #16             // width -= 16
 | 
			
		||||
        add             x1, x1, #48             // src += 48
 | 
			
		||||
        cmp             w4, #16                 // width >= 16 ?
 | 
			
		||||
@ -85,10 +93,7 @@ function ff_rgb24ToY_neon, export=1
 | 
			
		||||
        ret
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
.macro rgb24_load_uv_coeff half
 | 
			
		||||
        ldp             w10, w11, [x6, #12]     // w10: ru, w11: gu
 | 
			
		||||
        ldp             w12, w13, [x6, #20]     // w12: bu, w13: rv
 | 
			
		||||
        ldp             w14, w15, [x6, #28]     // w14: gv, w15: bv
 | 
			
		||||
.macro rgb_set_uv_coeff half
 | 
			
		||||
    .if \half
 | 
			
		||||
        mov             w9, #512
 | 
			
		||||
        movk            w9, #128, lsl #16       // w9: const_offset
 | 
			
		||||
@ -105,12 +110,26 @@ endfunc
 | 
			
		||||
        dup             v6.4s, w9
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
function ff_bgr24ToUV_half_neon, export=1
 | 
			
		||||
        cmp             w5, #0          // check width > 0
 | 
			
		||||
        b.le            3f
 | 
			
		||||
 | 
			
		||||
        ldp             w12, w11, [x6, #12]
 | 
			
		||||
        ldp             w10, w15, [x6, #20]
 | 
			
		||||
        ldp             w14, w13, [x6, #28]
 | 
			
		||||
        b               4f
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
function ff_rgb24ToUV_half_neon, export=1
 | 
			
		||||
        cmp             w5, #0          // check width > 0
 | 
			
		||||
        b.le            3f
 | 
			
		||||
 | 
			
		||||
        ldp             w10, w11, [x6, #12]     // w10: ru, w11: gu
 | 
			
		||||
        ldp             w12, w13, [x6, #20]     // w12: bu, w13: rv
 | 
			
		||||
        ldp             w14, w15, [x6, #28]     // w14: gv, w15: bv
 | 
			
		||||
4:
 | 
			
		||||
        cmp             w5, #8
 | 
			
		||||
        rgb24_load_uv_coeff half=1
 | 
			
		||||
        rgb_set_uv_coeff half=1
 | 
			
		||||
        b.lt            2f
 | 
			
		||||
1:
 | 
			
		||||
        ld3             { v16.16b, v17.16b, v18.16b }, [x3]
 | 
			
		||||
@ -118,8 +137,8 @@ function ff_rgb24ToUV_half_neon, export=1
 | 
			
		||||
        uaddlp          v20.8h, v17.16b         // v20: g
 | 
			
		||||
        uaddlp          v21.8h, v18.16b         // v21: b
 | 
			
		||||
 | 
			
		||||
        rgb24_to_yuv_product v19, v20, v21, v22, v23, v16, v0, v1, v2, #10
 | 
			
		||||
        rgb24_to_yuv_product v19, v20, v21, v24, v25, v17, v3, v4, v5, #10
 | 
			
		||||
        rgb_to_yuv_product v19, v20, v21, v22, v23, v16, v0, v1, v2, #10
 | 
			
		||||
        rgb_to_yuv_product v19, v20, v21, v24, v25, v17, v3, v4, v5, #10
 | 
			
		||||
        sub             w5, w5, #8              // width -= 8
 | 
			
		||||
        add             x3, x3, #48             // src += 48
 | 
			
		||||
        cmp             w5, #8                  // width >= 8 ?
 | 
			
		||||
@ -158,19 +177,33 @@ function ff_rgb24ToUV_half_neon, export=1
 | 
			
		||||
        ret
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
function ff_bgr24ToUV_neon, export=1
 | 
			
		||||
        cmp             w5, #0                  // check width > 0
 | 
			
		||||
        b.le            3f
 | 
			
		||||
 | 
			
		||||
        ldp             w12, w11, [x6, #12]
 | 
			
		||||
        ldp             w10, w15, [x6, #20]
 | 
			
		||||
        ldp             w14, w13, [x6, #28]
 | 
			
		||||
        b               4f
 | 
			
		||||
endfunc
 | 
			
		||||
 | 
			
		||||
function ff_rgb24ToUV_neon, export=1
 | 
			
		||||
        cmp             w5, #0                  // check width > 0
 | 
			
		||||
        b.le            3f
 | 
			
		||||
 | 
			
		||||
        ldp             w10, w11, [x6, #12]     // w10: ru, w11: gu
 | 
			
		||||
        ldp             w12, w13, [x6, #20]     // w12: bu, w13: rv
 | 
			
		||||
        ldp             w14, w15, [x6, #28]     // w14: gv, w15: bv
 | 
			
		||||
4:
 | 
			
		||||
        cmp             w5, #16
 | 
			
		||||
        rgb24_load_uv_coeff half=0
 | 
			
		||||
        rgb_set_uv_coeff half=0
 | 
			
		||||
        b.lt            2f
 | 
			
		||||
1:
 | 
			
		||||
        rgb24_to_yuv_load_rgb x3
 | 
			
		||||
        rgb24_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9
 | 
			
		||||
        rgb24_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9
 | 
			
		||||
        rgb24_to_yuv_product v19, v20, v21, v25, v26, v18, v3, v4, v5, #9
 | 
			
		||||
        rgb24_to_yuv_product v22, v23, v24, v27, v28, v19, v3, v4, v5, #9
 | 
			
		||||
        rgb_to_yuv_load_rgb x3
 | 
			
		||||
        rgb_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9
 | 
			
		||||
        rgb_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9
 | 
			
		||||
        rgb_to_yuv_product v19, v20, v21, v25, v26, v18, v3, v4, v5, #9
 | 
			
		||||
        rgb_to_yuv_product v22, v23, v24, v27, v28, v19, v3, v4, v5, #9
 | 
			
		||||
        sub             w5, w5, #16
 | 
			
		||||
        add             x3, x3, #48             // src += 48
 | 
			
		||||
        cmp             w5, #16
 | 
			
		||||
 | 
			
		||||
@ -201,19 +201,18 @@ void ff_yuv2plane1_8_neon(
 | 
			
		||||
    default: break;                                                     \
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
void ff_rgb24ToY_neon(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1,
 | 
			
		||||
                      const uint8_t *unused2, int width,
 | 
			
		||||
                      uint32_t *rgb2yuv, void *opq);
 | 
			
		||||
#define NEON_INPUT(name) \
 | 
			
		||||
void ff_##name##ToY_neon(uint8_t *dst, const uint8_t *src, const uint8_t *, \
 | 
			
		||||
                        const uint8_t *, int w, uint32_t *coeffs, void *); \
 | 
			
		||||
void ff_##name##ToUV_neon(uint8_t *, uint8_t *, const uint8_t *, \
 | 
			
		||||
                         const uint8_t *, const uint8_t *, int w, \
 | 
			
		||||
                         uint32_t *coeffs, void *); \
 | 
			
		||||
void ff_##name##ToUV_half_neon(uint8_t *, uint8_t *, const uint8_t *, \
 | 
			
		||||
                              const uint8_t *, const uint8_t *, int w, \
 | 
			
		||||
                              uint32_t *coeffs, void *)
 | 
			
		||||
 | 
			
		||||
void ff_rgb24ToUV_neon(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0,
 | 
			
		||||
                       const uint8_t *src1,
 | 
			
		||||
                       const uint8_t *src2, int width, uint32_t *rgb2yuv,
 | 
			
		||||
                       void *opq);
 | 
			
		||||
 | 
			
		||||
void ff_rgb24ToUV_half_neon(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0,
 | 
			
		||||
                       const uint8_t *src1,
 | 
			
		||||
                       const uint8_t *src2, int width, uint32_t *rgb2yuv,
 | 
			
		||||
                       void *opq);
 | 
			
		||||
NEON_INPUT(bgr24);
 | 
			
		||||
NEON_INPUT(rgb24);
 | 
			
		||||
 | 
			
		||||
void ff_lumRangeFromJpeg_neon(int16_t *dst, int width);
 | 
			
		||||
void ff_chrRangeFromJpeg_neon(int16_t *dstU, int16_t *dstV, int width);
 | 
			
		||||
@ -247,6 +246,13 @@ av_cold void ff_sws_init_swscale_aarch64(SwsContext *c)
 | 
			
		||||
            c->yuv2planeX = ff_yuv2planeX_8_neon;
 | 
			
		||||
        }
 | 
			
		||||
        switch (c->srcFormat) {
 | 
			
		||||
        case AV_PIX_FMT_BGR24:
 | 
			
		||||
            c->lumToYV12 = ff_bgr24ToY_neon;
 | 
			
		||||
            if (c->chrSrcHSubSample)
 | 
			
		||||
                c->chrToYV12 = ff_bgr24ToUV_half_neon;
 | 
			
		||||
            else
 | 
			
		||||
                c->chrToYV12 = ff_bgr24ToUV_neon;
 | 
			
		||||
            break;
 | 
			
		||||
        case AV_PIX_FMT_RGB24:
 | 
			
		||||
            c->lumToYV12 = ff_rgb24ToY_neon;
 | 
			
		||||
            if (c->chrSrcHSubSample)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user