Add MSA optimized colorspace conversion functions

We add the following MSA optimized colorspace conversion functions:
- ConvertBGRAToRGBA
- ConvertBGRAToBGR
- ConvertBGRAToRGB

Change-Id: I76db1c829d593a06d4975d54dbafa385c82b84fb
This commit is contained in:
Parag Salasakar 2016-06-27 14:36:28 +05:30 committed by Pascal Massimino
parent f918cb1013
commit 701c772eed
8 changed files with 300 additions and 22 deletions

View File

@ -50,6 +50,7 @@ dsp_dec_srcs := \
src/dsp/dec_mips32.c \
src/dsp/dec_mips_dsp_r2.c \
src/dsp/dec_msa.c \
src/dsp/lossless_msa.c \
src/dsp/dec_neon.$(NEON) \
src/dsp/dec_sse2.c \
src/dsp/dec_sse41.c \

View File

@ -195,6 +195,7 @@ DSP_DEC_OBJS = \
$(DIROBJ)\dsp\dec_mips32.obj \
$(DIROBJ)\dsp\dec_mips_dsp_r2.obj \
$(DIROBJ)\dsp\dec_msa.obj \
$(DIROBJ)\dsp\lossless_msa.obj \
$(DIROBJ)\dsp\dec_neon.obj \
$(DIROBJ)\dsp\dec_sse2.obj \
$(DIROBJ)\dsp\dec_sse41.obj \

View File

@ -128,6 +128,7 @@ model {
include "filters_sse2.c"
include "lossless.c"
include "lossless_mips_dsp_r2.c"
include "lossless_msa.c"
include "lossless_neon.$NEON"
include "lossless_sse2.c"
include "rescaler.c"

View File

@ -147,6 +147,7 @@ DSP_DEC_OBJS = \
src/dsp/filters_sse2.o \
src/dsp/lossless.o \
src/dsp/lossless_mips_dsp_r2.o \
src/dsp/lossless_msa.o \
src/dsp/lossless_neon.o \
src/dsp/lossless_sse2.o \
src/dsp/rescaler.o \

View File

@ -83,6 +83,7 @@ libwebpdspdecode_neon_la_CFLAGS = $(libwebpdsp_neon_la_CFLAGS)
libwebpdspdecode_msa_la_SOURCES =
libwebpdspdecode_msa_la_SOURCES += dec_msa.c
libwebpdspdecode_msa_la_SOURCES += lossless_msa.c
libwebpdspdecode_msa_la_SOURCES += msa_macro.h
libwebpdspdecode_msa_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
libwebpdspdecode_msa_la_CFLAGS = $(AM_CFLAGS)

View File

@ -572,6 +572,7 @@ VP8LMapAlphaFunc VP8LMapColor8b;
extern void VP8LDspInitSSE2(void);
extern void VP8LDspInitNEON(void);
extern void VP8LDspInitMIPSdspR2(void);
extern void VP8LDspInitMSA(void);
static volatile VP8CPUInfo lossless_last_cpuinfo_used =
(VP8CPUInfo)&lossless_last_cpuinfo_used;
@ -625,6 +626,11 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) {
if (VP8GetCPUInfo(kMIPSdspR2)) {
VP8LDspInitMIPSdspR2();
}
#endif
#if defined(WEBP_USE_MSA)
if (VP8GetCPUInfo(kMSA)) {
VP8LDspInitMSA();
}
#endif
}
lossless_last_cpuinfo_used = VP8GetCPUInfo;

231
src/dsp/lossless_msa.c Normal file
View File

@ -0,0 +1,231 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
// MSA variant of methods for lossless decoder
//
// Author: Prashant Patil (prashant.patil@imgtec.com)
#include "./dsp.h"
#if defined(WEBP_USE_MSA)
#include "./lossless.h"
#include "./msa_macro.h"
//------------------------------------------------------------------------------
// Colorspace conversion functions
#define CONVERT16_BGRA_XXX(psrc, pdst, m0, m1, m2) do { \
v16u8 src0, src1, src2, src3, dst0, dst1, dst2; \
LD_UB4(psrc, 16, src0, src1, src2, src3); \
VSHF_B2_UB(src0, src1, src1, src2, m0, m1, dst0, dst1); \
dst2 = VSHF_UB(src2, src3, m2); \
ST_UB2(dst0, dst1, pdst, 16); \
ST_UB(dst2, pdst + 32); \
} while (0)
#define CONVERT12_BGRA_XXX(psrc, pdst, m0, m1, m2) do { \
uint32_t pix_w; \
v16u8 src0, src1, src2, dst0, dst1, dst2; \
LD_UB3(psrc, 16, src0, src1, src2); \
VSHF_B2_UB(src0, src1, src1, src2, m0, m1, dst0, dst1); \
dst2 = VSHF_UB(src2, src2, m2); \
ST_UB2(dst0, dst1, pdst, 16); \
pix_w = __msa_copy_s_w((v4i32)dst2, 0); \
SW(pix_w, pdst + 32); \
} while (0)
#define CONVERT8_BGRA_XXX(psrc, pdst, m0, m1) do { \
uint64_t pix_d; \
v16u8 src0, src1, src2, dst0, dst1; \
LD_UB2(psrc, 16, src0, src1); \
VSHF_B2_UB(src0, src1, src1, src2, m0, m1, dst0, dst1); \
ST_UB(dst0, pdst); \
pix_d = __msa_copy_s_d((v2i64)dst1, 0); \
SD(pix_d, pdst + 16); \
} while (0)
#define CONVERT4_BGRA_XXX(psrc, pdst, m) do { \
const v16u8 src0 = LD_UB(psrc); \
const v16u8 dst0 = VSHF_UB(src0, src0, m); \
uint64_t pix_d = __msa_copy_s_d((v2i64)dst0, 0); \
uint32_t pix_w = __msa_copy_s_w((v4i32)dst0, 2); \
SD(pix_d, pdst + 0); \
SW(pix_w, pdst + 8); \
} while (0)
#define CONVERT1_BGRA_BGR(psrc, pdst) do { \
const int32_t b = (psrc)[0]; \
const int32_t g = (psrc)[1]; \
const int32_t r = (psrc)[2]; \
(pdst)[0] = b; \
(pdst)[1] = g; \
(pdst)[2] = r; \
} while (0)
#define CONVERT1_BGRA_RGB(psrc, pdst) do { \
const int32_t b = (psrc)[0]; \
const int32_t g = (psrc)[1]; \
const int32_t r = (psrc)[2]; \
(pdst)[0] = r; \
(pdst)[1] = g; \
(pdst)[2] = b; \
} while (0)
static void ConvertBGRAToRGBA(const uint32_t* src,
int num_pixels, uint8_t* dst) {
int i;
const uint8_t* ptemp_src = (const uint8_t*)src;
uint8_t* ptemp_dst = (uint8_t*)dst;
v16u8 src0, dst0;
const v16u8 mask = { 2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15 };
while (num_pixels >= 8) {
v16u8 src1, dst1;
LD_UB2(ptemp_src, 16, src0, src1);
VSHF_B2_UB(src0, src0, src1, src1, mask, mask, dst0, dst1);
ST_UB2(dst0, dst1, ptemp_dst, 16);
ptemp_src += 32;
ptemp_dst += 32;
num_pixels -= 8;
}
if (num_pixels > 0) {
if (num_pixels >= 4) {
src0 = LD_UB(ptemp_src);
dst0 = VSHF_UB(src0, src0, mask);
ST_UB(dst0, ptemp_dst);
ptemp_src += 16;
ptemp_dst += 16;
num_pixels -= 4;
}
for (i = 0; i < num_pixels; i++) {
const uint8_t b = ptemp_src[2];
const uint8_t g = ptemp_src[1];
const uint8_t r = ptemp_src[0];
const uint8_t a = ptemp_src[3];
ptemp_dst[0] = b;
ptemp_dst[1] = g;
ptemp_dst[2] = r;
ptemp_dst[3] = a;
ptemp_src += 4;
ptemp_dst += 4;
}
}
}
static void ConvertBGRAToBGR(const uint32_t* src,
int num_pixels, uint8_t* dst) {
const uint8_t* ptemp_src = (const uint8_t*)src;
uint8_t* ptemp_dst = (uint8_t*)dst;
const v16u8 mask0 = { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14,
16, 17, 18, 20 };
const v16u8 mask1 = { 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20,
21, 22, 24, 25 };
const v16u8 mask2 = { 10, 12, 13, 14, 16, 17, 18, 20, 21, 22, 24, 25,
26, 28, 29, 30 };
while (num_pixels >= 16) {
CONVERT16_BGRA_XXX(ptemp_src, ptemp_dst, mask0, mask1, mask2);
ptemp_src += 64;
ptemp_dst += 48;
num_pixels -= 16;
}
if (num_pixels > 0) {
if (num_pixels >= 12) {
CONVERT12_BGRA_XXX(ptemp_src, ptemp_dst, mask0, mask1, mask2);
ptemp_src += 48;
ptemp_dst += 36;
num_pixels -= 12;
} else if (num_pixels >= 8) {
CONVERT8_BGRA_XXX(ptemp_src, ptemp_dst, mask0, mask1);
ptemp_src += 32;
ptemp_dst += 24;
num_pixels -= 8;
} else if (num_pixels >= 4) {
CONVERT4_BGRA_XXX(ptemp_src, ptemp_dst, mask0);
ptemp_src += 16;
ptemp_dst += 12;
num_pixels -= 4;
}
if (num_pixels == 3) {
CONVERT1_BGRA_BGR(ptemp_src + 0, ptemp_dst + 0);
CONVERT1_BGRA_BGR(ptemp_src + 4, ptemp_dst + 3);
CONVERT1_BGRA_BGR(ptemp_src + 8, ptemp_dst + 6);
} else if (num_pixels == 2) {
CONVERT1_BGRA_BGR(ptemp_src + 0, ptemp_dst + 0);
CONVERT1_BGRA_BGR(ptemp_src + 4, ptemp_dst + 3);
} else if (num_pixels == 1) {
CONVERT1_BGRA_BGR(ptemp_src, ptemp_dst);
}
}
}
static void ConvertBGRAToRGB(const uint32_t* src,
int num_pixels, uint8_t* dst) {
const uint8_t* ptemp_src = (const uint8_t*)src;
uint8_t* ptemp_dst = (uint8_t*)dst;
const v16u8 mask0 = { 2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12,
18, 17, 16, 22 };
const v16u8 mask1 = { 5, 4, 10, 9, 8, 14, 13, 12, 18, 17, 16, 22,
21, 20, 26, 25 };
const v16u8 mask2 = { 8, 14, 13, 12, 18, 17, 16, 22, 21, 20, 26, 25,
24, 30, 29, 28 };
while (num_pixels >= 16) {
CONVERT16_BGRA_XXX(ptemp_src, ptemp_dst, mask0, mask1, mask2);
ptemp_src += 64;
ptemp_dst += 48;
num_pixels -= 16;
}
if (num_pixels) {
if (num_pixels >= 12) {
CONVERT12_BGRA_XXX(ptemp_src, ptemp_dst, mask0, mask1, mask2);
ptemp_src += 48;
ptemp_dst += 36;
num_pixels -= 12;
} else if (num_pixels >= 8) {
CONVERT8_BGRA_XXX(ptemp_src, ptemp_dst, mask0, mask1);
ptemp_src += 32;
ptemp_dst += 24;
num_pixels -= 8;
} else if (num_pixels >= 4) {
CONVERT4_BGRA_XXX(ptemp_src, ptemp_dst, mask0);
ptemp_src += 16;
ptemp_dst += 12;
num_pixels -= 4;
}
if (num_pixels == 3) {
CONVERT1_BGRA_RGB(ptemp_src + 0, ptemp_dst + 0);
CONVERT1_BGRA_RGB(ptemp_src + 4, ptemp_dst + 3);
CONVERT1_BGRA_RGB(ptemp_src + 8, ptemp_dst + 6);
} else if (num_pixels == 2) {
CONVERT1_BGRA_RGB(ptemp_src + 0, ptemp_dst + 0);
CONVERT1_BGRA_RGB(ptemp_src + 4, ptemp_dst + 3);
} else if (num_pixels == 1) {
CONVERT1_BGRA_RGB(ptemp_src, ptemp_dst);
}
}
}
//------------------------------------------------------------------------------
// Entry point
extern void VP8LDspInitMSA(void);
WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInitMSA(void) {
VP8LConvertBGRAToRGBA = ConvertBGRAToRGBA;
VP8LConvertBGRAToBGR = ConvertBGRAToBGR;
VP8LConvertBGRAToRGB = ConvertBGRAToRGB;
}
#else // !WEBP_USE_MSA
WEBP_DSP_INIT_STUB(VP8LDspInitMSA)
#endif // WEBP_USE_MSA

View File

@ -196,6 +196,13 @@
#define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)
#define LD_SB2(...) LD_B2(v16i8, __VA_ARGS__)
#define LD_B3(RTYPE, psrc, stride, out0, out1, out2) { \
LD_B2(RTYPE, psrc, stride, out0, out1); \
out2 = LD_B(RTYPE, psrc + 2 * stride); \
}
#define LD_UB3(...) LD_B3(v16u8, __VA_ARGS__)
#define LD_SB3(...) LD_B3(v16i8, __VA_ARGS__)
#define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) { \
LD_B2(RTYPE, psrc, stride, out0, out1); \
LD_B2(RTYPE, psrc + 2 * stride , stride, out2, out3); \
@ -316,6 +323,31 @@
#define SLDI_SB(...) SLDI_B(v16i8, __VA_ARGS__)
#define SLDI_SH(...) SLDI_B(v8i16, __VA_ARGS__)
/* Description : Shuffle byte vector elements as per mask vector
* Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
* Outputs - out0, out1
* Return Type - as per RTYPE
* Details : Byte elements from 'in0' & 'in1' are copied selectively to
* 'out0' as per control vector 'mask0'
*/
#define VSHF_B(RTYPE, in0, in1, mask) \
(RTYPE)__msa_vshf_b((v16i8)mask, (v16i8)in1, (v16i8)in0)
#define VSHF_UB(...) VSHF_B(v16u8, __VA_ARGS__)
#define VSHF_SB(...) VSHF_B(v16i8, __VA_ARGS__)
#define VSHF_UH(...) VSHF_B(v8u16, __VA_ARGS__)
#define VSHF_SH(...) VSHF_B(v8i16, __VA_ARGS__)
#define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) do { \
out0 = VSHF_B(RTYPE, in0, in1, mask0); \
out1 = VSHF_B(RTYPE, in2, in3, mask1); \
} while (0)
#define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
#define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
#define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
#define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)
/* Description : Shuffle halfword vector elements as per mask vector
* Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
* Outputs - out0, out1
@ -323,10 +355,11 @@
* Details : halfword elements from 'in0' & 'in1' are copied selectively to
* 'out0' as per control vector 'mask0'
*/
#define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) { \
out0 = (RTYPE)__msa_vshf_h((v8i16)mask0, (v8i16)in1, (v8i16)in0); \
out1 = (RTYPE)__msa_vshf_h((v8i16)mask1, (v8i16)in3, (v8i16)in2); \
}
#define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) do { \
out0 = (RTYPE)__msa_vshf_h((v8i16)mask0, (v8i16)in1, (v8i16)in0); \
out1 = (RTYPE)__msa_vshf_h((v8i16)mask1, (v8i16)in3, (v8i16)in2); \
} while (0)
#define VSHF_H2_UH(...) VSHF_H2(v8u16, __VA_ARGS__)
#define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)
@ -335,36 +368,39 @@
* Arguments : Input/output - val
* Return Type - signed halfword
*/
#define CLIP_SH_0_255(val) { \
#define CLIP_SH_0_255(val) do { \
const v8i16 max_m = __msa_ldi_h(255); \
val = __msa_maxi_s_h((v8i16)val, 0); \
val = __msa_min_s_h(max_m, (v8i16)val); \
}
#define CLIP_SH2_0_255(in0, in1) { \
CLIP_SH_0_255(in0); \
CLIP_SH_0_255(in1); \
}
#define CLIP_SH4_0_255(in0, in1, in2, in3) { \
CLIP_SH2_0_255(in0, in1); \
CLIP_SH2_0_255(in2, in3); \
}
} while (0)
#define CLIP_SH2_0_255(in0, in1) do { \
CLIP_SH_0_255(in0); \
CLIP_SH_0_255(in1); \
} while (0)
#define CLIP_SH4_0_255(in0, in1, in2, in3) do { \
CLIP_SH2_0_255(in0, in1); \
CLIP_SH2_0_255(in2, in3); \
} while (0)
/* Description : Clips all signed word elements of input vector
* between 0 & 255
* Arguments : Input/output - val
* Return Type - signed word
*/
#define CLIP_SW_0_255(val) { \
#define CLIP_SW_0_255(val) do { \
const v4i32 max_m = __msa_ldi_w(255); \
val = __msa_maxi_s_w((v4i32)val, 0); \
val = __msa_min_s_w(max_m, (v4i32)val); \
}
#define CLIP_SW4_0_255(in0, in1, in2, in3) { \
CLIP_SW_0_255(in0); \
CLIP_SW_0_255(in1); \
CLIP_SW_0_255(in2); \
CLIP_SW_0_255(in3); \
}
} while (0)
#define CLIP_SW4_0_255(in0, in1, in2, in3) do { \
CLIP_SW_0_255(in0); \
CLIP_SW_0_255(in1); \
CLIP_SW_0_255(in2); \
CLIP_SW_0_255(in3); \
} while (0)
/* Description : Horizontal addition of 8 unsigned halfword elements
* Arguments : Input - in (unsigned halfword vector)