Path: blob/master/3rdparty/libwebp/src/dsp/msa_macro.h
16348 views
// Copyright 2016 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// MSA common macros10//11// Author(s): Prashant Patil ([email protected])1213#ifndef WEBP_DSP_MSA_MACRO_H_14#define WEBP_DSP_MSA_MACRO_H_1516#include <stdint.h>17#include <msa.h>1819#if defined(__clang__)20#define CLANG_BUILD21#endif2223#ifdef CLANG_BUILD24#define ALPHAVAL (-1)25#define ADDVI_H(a, b) __msa_addvi_h((v8i16)a, b)26#define ADDVI_W(a, b) __msa_addvi_w((v4i32)a, b)27#define SRAI_B(a, b) __msa_srai_b((v16i8)a, b)28#define SRAI_H(a, b) __msa_srai_h((v8i16)a, b)29#define SRAI_W(a, b) __msa_srai_w((v4i32)a, b)30#define SRLI_H(a, b) __msa_srli_h((v8i16)a, b)31#define SLLI_B(a, b) __msa_slli_b((v4i32)a, b)32#define ANDI_B(a, b) __msa_andi_b((v16u8)a, b)33#define ORI_B(a, b) __msa_ori_b((v16u8)a, b)34#else35#define ALPHAVAL (0xff)36#define ADDVI_H(a, b) (a + b)37#define ADDVI_W(a, b) (a + b)38#define SRAI_B(a, b) (a >> b)39#define SRAI_H(a, b) (a >> b)40#define SRAI_W(a, b) (a >> b)41#define SRLI_H(a, b) (a << b)42#define SLLI_B(a, b) (a << b)43#define ANDI_B(a, b) (a & b)44#define ORI_B(a, b) (a | b)45#endif4647#define LD_B(RTYPE, psrc) *((RTYPE*)(psrc))48#define LD_UB(...) LD_B(v16u8, __VA_ARGS__)49#define LD_SB(...) LD_B(v16i8, __VA_ARGS__)5051#define LD_H(RTYPE, psrc) *((RTYPE*)(psrc))52#define LD_UH(...) LD_H(v8u16, __VA_ARGS__)53#define LD_SH(...) LD_H(v8i16, __VA_ARGS__)5455#define LD_W(RTYPE, psrc) *((RTYPE*)(psrc))56#define LD_UW(...) LD_W(v4u32, __VA_ARGS__)57#define LD_SW(...) LD_W(v4i32, __VA_ARGS__)5859#define ST_B(RTYPE, in, pdst) *((RTYPE*)(pdst)) = in60#define ST_UB(...) ST_B(v16u8, __VA_ARGS__)61#define ST_SB(...) ST_B(v16i8, __VA_ARGS__)6263#define ST_H(RTYPE, in, pdst) *((RTYPE*)(pdst)) = in64#define ST_UH(...) ST_H(v8u16, __VA_ARGS__)65#define ST_SH(...) ST_H(v8i16, __VA_ARGS__)6667#define ST_W(RTYPE, in, pdst) *((RTYPE*)(pdst)) = in68#define ST_UW(...) ST_W(v4u32, __VA_ARGS__)69#define ST_SW(...) ST_W(v4i32, __VA_ARGS__)7071#define MSA_LOAD_FUNC(TYPE, INSTR, FUNC_NAME) \72static inline TYPE FUNC_NAME(const void* const psrc) { \73const uint8_t* const psrc_m = (const uint8_t*)psrc; \74TYPE val_m; \75asm volatile ( \76"" #INSTR " %[val_m], %[psrc_m] \n\t" \77: [val_m] "=r" (val_m) \78: [psrc_m] "m" (*psrc_m)); \79return val_m; \80}8182#define MSA_LOAD(psrc, FUNC_NAME) FUNC_NAME(psrc)8384#define MSA_STORE_FUNC(TYPE, INSTR, FUNC_NAME) \85static inline void FUNC_NAME(TYPE val, void* const pdst) { \86uint8_t* const pdst_m = (uint8_t*)pdst; \87TYPE val_m = val; \88asm volatile ( \89" " #INSTR " %[val_m], %[pdst_m] \n\t" \90: [pdst_m] "=m" (*pdst_m) \91: [val_m] "r" (val_m)); \92}9394#define MSA_STORE(val, pdst, FUNC_NAME) FUNC_NAME(val, pdst)9596#if (__mips_isa_rev >= 6)97MSA_LOAD_FUNC(uint16_t, lh, msa_lh);98#define LH(psrc) MSA_LOAD(psrc, msa_lh)99MSA_LOAD_FUNC(uint32_t, lw, msa_lw);100#define LW(psrc) MSA_LOAD(psrc, msa_lw)101#if (__mips == 64)102MSA_LOAD_FUNC(uint64_t, ld, msa_ld);103#define LD(psrc) MSA_LOAD(psrc, msa_ld)104#else // !(__mips == 64)105#define LD(psrc) ((((uint64_t)MSA_LOAD(psrc + 4, msa_lw)) << 32) | \106MSA_LOAD(psrc, msa_lw))107#endif // (__mips == 64)108109MSA_STORE_FUNC(uint16_t, sh, msa_sh);110#define SH(val, pdst) MSA_STORE(val, pdst, msa_sh)111MSA_STORE_FUNC(uint32_t, sw, msa_sw);112#define SW(val, pdst) MSA_STORE(val, pdst, msa_sw)113MSA_STORE_FUNC(uint64_t, sd, msa_sd);114#define SD(val, pdst) MSA_STORE(val, pdst, msa_sd)115#else // !(__mips_isa_rev >= 6)116MSA_LOAD_FUNC(uint16_t, ulh, msa_ulh);117#define LH(psrc) MSA_LOAD(psrc, msa_ulh)118MSA_LOAD_FUNC(uint32_t, ulw, msa_ulw);119#define LW(psrc) MSA_LOAD(psrc, msa_ulw)120#if (__mips == 64)121MSA_LOAD_FUNC(uint64_t, uld, msa_uld);122#define LD(psrc) MSA_LOAD(psrc, msa_uld)123#else // !(__mips == 64)124#define LD(psrc) ((((uint64_t)MSA_LOAD(psrc + 4, msa_ulw)) << 32) | \125MSA_LOAD(psrc, msa_ulw))126#endif // (__mips == 64)127128MSA_STORE_FUNC(uint16_t, ush, msa_ush);129#define SH(val, pdst) MSA_STORE(val, pdst, msa_ush)130MSA_STORE_FUNC(uint32_t, usw, msa_usw);131#define SW(val, pdst) MSA_STORE(val, pdst, msa_usw)132#define SD(val, pdst) do { \133uint8_t* const pdst_sd_m = (uint8_t*)(pdst); \134const uint32_t val0_m = (uint32_t)(val & 0x00000000FFFFFFFF); \135const uint32_t val1_m = (uint32_t)((val >> 32) & 0x00000000FFFFFFFF); \136SW(val0_m, pdst_sd_m); \137SW(val1_m, pdst_sd_m + 4); \138} while (0)139#endif // (__mips_isa_rev >= 6)140141/* Description : Load 4 words with stride142* Arguments : Inputs - psrc, stride143* Outputs - out0, out1, out2, out3144* Details : Load word in 'out0' from (psrc)145* Load word in 'out1' from (psrc + stride)146* Load word in 'out2' from (psrc + 2 * stride)147* Load word in 'out3' from (psrc + 3 * stride)148*/149#define LW4(psrc, stride, out0, out1, out2, out3) do { \150const uint8_t* ptmp = (const uint8_t*)psrc; \151out0 = LW(ptmp); \152ptmp += stride; \153out1 = LW(ptmp); \154ptmp += stride; \155out2 = LW(ptmp); \156ptmp += stride; \157out3 = LW(ptmp); \158} while (0)159160/* Description : Store words with stride161* Arguments : Inputs - in0, in1, in2, in3, pdst, stride162* Details : Store word from 'in0' to (pdst)163* Store word from 'in1' to (pdst + stride)164* Store word from 'in2' to (pdst + 2 * stride)165* Store word from 'in3' to (pdst + 3 * stride)166*/167#define SW4(in0, in1, in2, in3, pdst, stride) do { \168uint8_t* ptmp = (uint8_t*)pdst; \169SW(in0, ptmp); \170ptmp += stride; \171SW(in1, ptmp); \172ptmp += stride; \173SW(in2, ptmp); \174ptmp += stride; \175SW(in3, ptmp); \176} while (0)177178#define SW3(in0, in1, in2, pdst, stride) do { \179uint8_t* ptmp = (uint8_t*)pdst; \180SW(in0, ptmp); \181ptmp += stride; \182SW(in1, ptmp); \183ptmp += stride; \184SW(in2, ptmp); \185} while (0)186187#define SW2(in0, in1, pdst, stride) do { \188uint8_t* ptmp = (uint8_t*)pdst; \189SW(in0, ptmp); \190ptmp += stride; \191SW(in1, ptmp); \192} while (0)193194/* Description : Store 4 double words with stride195* Arguments : Inputs - in0, in1, in2, in3, pdst, stride196* Details : Store double word from 'in0' to (pdst)197* Store double word from 'in1' to (pdst + stride)198* Store double word from 'in2' to (pdst + 2 * stride)199* Store double word from 'in3' to (pdst + 3 * stride)200*/201#define SD4(in0, in1, in2, in3, pdst, stride) do { \202uint8_t* ptmp = (uint8_t*)pdst; \203SD(in0, ptmp); \204ptmp += stride; \205SD(in1, ptmp); \206ptmp += stride; \207SD(in2, ptmp); \208ptmp += stride; \209SD(in3, ptmp); \210} while (0)211212/* Description : Load vectors with 16 byte elements with stride213* Arguments : Inputs - psrc, stride214* Outputs - out0, out1215* Return Type - as per RTYPE216* Details : Load 16 byte elements in 'out0' from (psrc)217* Load 16 byte elements in 'out1' from (psrc + stride)218*/219#define LD_B2(RTYPE, psrc, stride, out0, out1) do { \220out0 = LD_B(RTYPE, psrc); \221out1 = LD_B(RTYPE, psrc + stride); \222} while (0)223#define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)224#define LD_SB2(...) LD_B2(v16i8, __VA_ARGS__)225226#define LD_B3(RTYPE, psrc, stride, out0, out1, out2) do { \227LD_B2(RTYPE, psrc, stride, out0, out1); \228out2 = LD_B(RTYPE, psrc + 2 * stride); \229} while (0)230#define LD_UB3(...) LD_B3(v16u8, __VA_ARGS__)231#define LD_SB3(...) LD_B3(v16i8, __VA_ARGS__)232233#define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) do { \234LD_B2(RTYPE, psrc, stride, out0, out1); \235LD_B2(RTYPE, psrc + 2 * stride , stride, out2, out3); \236} while (0)237#define LD_UB4(...) LD_B4(v16u8, __VA_ARGS__)238#define LD_SB4(...) LD_B4(v16i8, __VA_ARGS__)239240#define LD_B8(RTYPE, psrc, stride, \241out0, out1, out2, out3, out4, out5, out6, out7) do { \242LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3); \243LD_B4(RTYPE, psrc + 4 * stride, stride, out4, out5, out6, out7); \244} while (0)245#define LD_UB8(...) LD_B8(v16u8, __VA_ARGS__)246#define LD_SB8(...) LD_B8(v16i8, __VA_ARGS__)247248/* Description : Load vectors with 8 halfword elements with stride249* Arguments : Inputs - psrc, stride250* Outputs - out0, out1251* Details : Load 8 halfword elements in 'out0' from (psrc)252* Load 8 halfword elements in 'out1' from (psrc + stride)253*/254#define LD_H2(RTYPE, psrc, stride, out0, out1) do { \255out0 = LD_H(RTYPE, psrc); \256out1 = LD_H(RTYPE, psrc + stride); \257} while (0)258#define LD_UH2(...) LD_H2(v8u16, __VA_ARGS__)259#define LD_SH2(...) LD_H2(v8i16, __VA_ARGS__)260261/* Description : Load vectors with 4 word elements with stride262* Arguments : Inputs - psrc, stride263* Outputs - out0, out1, out2, out3264* Details : Load 4 word elements in 'out0' from (psrc + 0 * stride)265* Load 4 word elements in 'out1' from (psrc + 1 * stride)266* Load 4 word elements in 'out2' from (psrc + 2 * stride)267* Load 4 word elements in 'out3' from (psrc + 3 * stride)268*/269#define LD_W2(RTYPE, psrc, stride, out0, out1) do { \270out0 = LD_W(RTYPE, psrc); \271out1 = LD_W(RTYPE, psrc + stride); \272} while (0)273#define LD_UW2(...) LD_W2(v4u32, __VA_ARGS__)274#define LD_SW2(...) LD_W2(v4i32, __VA_ARGS__)275276#define LD_W3(RTYPE, psrc, stride, out0, out1, out2) do { \277LD_W2(RTYPE, psrc, stride, out0, out1); \278out2 = LD_W(RTYPE, psrc + 2 * stride); \279} while (0)280#define LD_UW3(...) LD_W3(v4u32, __VA_ARGS__)281#define LD_SW3(...) LD_W3(v4i32, __VA_ARGS__)282283#define LD_W4(RTYPE, psrc, stride, out0, out1, out2, out3) do { \284LD_W2(RTYPE, psrc, stride, out0, out1); \285LD_W2(RTYPE, psrc + 2 * stride, stride, out2, out3); \286} while (0)287#define LD_UW4(...) LD_W4(v4u32, __VA_ARGS__)288#define LD_SW4(...) LD_W4(v4i32, __VA_ARGS__)289290/* Description : Store vectors of 16 byte elements with stride291* Arguments : Inputs - in0, in1, pdst, stride292* Details : Store 16 byte elements from 'in0' to (pdst)293* Store 16 byte elements from 'in1' to (pdst + stride)294*/295#define ST_B2(RTYPE, in0, in1, pdst, stride) do { \296ST_B(RTYPE, in0, pdst); \297ST_B(RTYPE, in1, pdst + stride); \298} while (0)299#define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)300#define ST_SB2(...) ST_B2(v16i8, __VA_ARGS__)301302#define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride) do { \303ST_B2(RTYPE, in0, in1, pdst, stride); \304ST_B2(RTYPE, in2, in3, pdst + 2 * stride, stride); \305} while (0)306#define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)307#define ST_SB4(...) ST_B4(v16i8, __VA_ARGS__)308309#define ST_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \310pdst, stride) do { \311ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride); \312ST_B4(RTYPE, in4, in5, in6, in7, pdst + 4 * stride, stride); \313} while (0)314#define ST_UB8(...) ST_B8(v16u8, __VA_ARGS__)315316/* Description : Store vectors of 4 word elements with stride317* Arguments : Inputs - in0, in1, in2, in3, pdst, stride318* Details : Store 4 word elements from 'in0' to (pdst + 0 * stride)319* Store 4 word elements from 'in1' to (pdst + 1 * stride)320* Store 4 word elements from 'in2' to (pdst + 2 * stride)321* Store 4 word elements from 'in3' to (pdst + 3 * stride)322*/323#define ST_W2(RTYPE, in0, in1, pdst, stride) do { \324ST_W(RTYPE, in0, pdst); \325ST_W(RTYPE, in1, pdst + stride); \326} while (0)327#define ST_UW2(...) ST_W2(v4u32, __VA_ARGS__)328#define ST_SW2(...) ST_W2(v4i32, __VA_ARGS__)329330#define ST_W3(RTYPE, in0, in1, in2, pdst, stride) do { \331ST_W2(RTYPE, in0, in1, pdst, stride); \332ST_W(RTYPE, in2, pdst + 2 * stride); \333} while (0)334#define ST_UW3(...) ST_W3(v4u32, __VA_ARGS__)335#define ST_SW3(...) ST_W3(v4i32, __VA_ARGS__)336337#define ST_W4(RTYPE, in0, in1, in2, in3, pdst, stride) do { \338ST_W2(RTYPE, in0, in1, pdst, stride); \339ST_W2(RTYPE, in2, in3, pdst + 2 * stride, stride); \340} while (0)341#define ST_UW4(...) ST_W4(v4u32, __VA_ARGS__)342#define ST_SW4(...) ST_W4(v4i32, __VA_ARGS__)343344/* Description : Store vectors of 8 halfword elements with stride345* Arguments : Inputs - in0, in1, pdst, stride346* Details : Store 8 halfword elements from 'in0' to (pdst)347* Store 8 halfword elements from 'in1' to (pdst + stride)348*/349#define ST_H2(RTYPE, in0, in1, pdst, stride) do { \350ST_H(RTYPE, in0, pdst); \351ST_H(RTYPE, in1, pdst + stride); \352} while (0)353#define ST_UH2(...) ST_H2(v8u16, __VA_ARGS__)354#define ST_SH2(...) ST_H2(v8i16, __VA_ARGS__)355356/* Description : Store 2x4 byte block to destination memory from input vector357* Arguments : Inputs - in, stidx, pdst, stride358* Details : Index 'stidx' halfword element from 'in' vector is copied to359* the GP register and stored to (pdst)360* Index 'stidx+1' halfword element from 'in' vector is copied to361* the GP register and stored to (pdst + stride)362* Index 'stidx+2' halfword element from 'in' vector is copied to363* the GP register and stored to (pdst + 2 * stride)364* Index 'stidx+3' halfword element from 'in' vector is copied to365* the GP register and stored to (pdst + 3 * stride)366*/367#define ST2x4_UB(in, stidx, pdst, stride) do { \368uint8_t* pblk_2x4_m = (uint8_t*)pdst; \369const uint16_t out0_m = __msa_copy_s_h((v8i16)in, stidx); \370const uint16_t out1_m = __msa_copy_s_h((v8i16)in, stidx + 1); \371const uint16_t out2_m = __msa_copy_s_h((v8i16)in, stidx + 2); \372const uint16_t out3_m = __msa_copy_s_h((v8i16)in, stidx + 3); \373SH(out0_m, pblk_2x4_m); \374pblk_2x4_m += stride; \375SH(out1_m, pblk_2x4_m); \376pblk_2x4_m += stride; \377SH(out2_m, pblk_2x4_m); \378pblk_2x4_m += stride; \379SH(out3_m, pblk_2x4_m); \380} while (0)381382/* Description : Store 4x4 byte block to destination memory from input vector383* Arguments : Inputs - in0, in1, pdst, stride384* Details : 'Idx0' word element from input vector 'in0' is copied to the385* GP register and stored to (pdst)386* 'Idx1' word element from input vector 'in0' is copied to the387* GP register and stored to (pdst + stride)388* 'Idx2' word element from input vector 'in0' is copied to the389* GP register and stored to (pdst + 2 * stride)390* 'Idx3' word element from input vector 'in0' is copied to the391* GP register and stored to (pdst + 3 * stride)392*/393#define ST4x4_UB(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) do { \394uint8_t* const pblk_4x4_m = (uint8_t*)pdst; \395const uint32_t out0_m = __msa_copy_s_w((v4i32)in0, idx0); \396const uint32_t out1_m = __msa_copy_s_w((v4i32)in0, idx1); \397const uint32_t out2_m = __msa_copy_s_w((v4i32)in1, idx2); \398const uint32_t out3_m = __msa_copy_s_w((v4i32)in1, idx3); \399SW4(out0_m, out1_m, out2_m, out3_m, pblk_4x4_m, stride); \400} while (0)401402#define ST4x8_UB(in0, in1, pdst, stride) do { \403uint8_t* const pblk_4x8 = (uint8_t*)pdst; \404ST4x4_UB(in0, in0, 0, 1, 2, 3, pblk_4x8, stride); \405ST4x4_UB(in1, in1, 0, 1, 2, 3, pblk_4x8 + 4 * stride, stride); \406} while (0)407408/* Description : Immediate number of elements to slide409* Arguments : Inputs - in0, in1, slide_val410* Outputs - out411* Return Type - as per RTYPE412* Details : Byte elements from 'in1' vector are slid into 'in0' by413* value specified in the 'slide_val'414*/415#define SLDI_B(RTYPE, in0, in1, slide_val) \416(RTYPE)__msa_sldi_b((v16i8)in0, (v16i8)in1, slide_val) \417418#define SLDI_UB(...) SLDI_B(v16u8, __VA_ARGS__)419#define SLDI_SB(...) SLDI_B(v16i8, __VA_ARGS__)420#define SLDI_SH(...) SLDI_B(v8i16, __VA_ARGS__)421422/* Description : Shuffle byte vector elements as per mask vector423* Arguments : Inputs - in0, in1, in2, in3, mask0, mask1424* Outputs - out0, out1425* Return Type - as per RTYPE426* Details : Byte elements from 'in0' & 'in1' are copied selectively to427* 'out0' as per control vector 'mask0'428*/429#define VSHF_B(RTYPE, in0, in1, mask) \430(RTYPE)__msa_vshf_b((v16i8)mask, (v16i8)in1, (v16i8)in0)431432#define VSHF_UB(...) VSHF_B(v16u8, __VA_ARGS__)433#define VSHF_SB(...) VSHF_B(v16i8, __VA_ARGS__)434#define VSHF_UH(...) VSHF_B(v8u16, __VA_ARGS__)435#define VSHF_SH(...) VSHF_B(v8i16, __VA_ARGS__)436437#define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) do { \438out0 = VSHF_B(RTYPE, in0, in1, mask0); \439out1 = VSHF_B(RTYPE, in2, in3, mask1); \440} while (0)441#define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)442#define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)443#define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)444#define VSHF_B2_SH(...) VSHF_B2(v8i16, __VA_ARGS__)445446/* Description : Shuffle halfword vector elements as per mask vector447* Arguments : Inputs - in0, in1, in2, in3, mask0, mask1448* Outputs - out0, out1449* Return Type - as per RTYPE450* Details : halfword elements from 'in0' & 'in1' are copied selectively to451* 'out0' as per control vector 'mask0'452*/453#define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) do { \454out0 = (RTYPE)__msa_vshf_h((v8i16)mask0, (v8i16)in1, (v8i16)in0); \455out1 = (RTYPE)__msa_vshf_h((v8i16)mask1, (v8i16)in3, (v8i16)in2); \456} while (0)457#define VSHF_H2_UH(...) VSHF_H2(v8u16, __VA_ARGS__)458#define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)459460/* Description : Dot product of byte vector elements461* Arguments : Inputs - mult0, mult1, cnst0, cnst1462* Outputs - out0, out1463* Return Type - as per RTYPE464* Details : Signed byte elements from 'mult0' are multiplied with465* signed byte elements from 'cnst0' producing a result466* twice the size of input i.e. signed halfword.467* The multiplication result of adjacent odd-even elements468* are added together and written to the 'out0' vector469*/470#define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) do { \471out0 = (RTYPE)__msa_dotp_s_h((v16i8)mult0, (v16i8)cnst0); \472out1 = (RTYPE)__msa_dotp_s_h((v16i8)mult1, (v16i8)cnst1); \473} while (0)474#define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)475476/* Description : Dot product of halfword vector elements477* Arguments : Inputs - mult0, mult1, cnst0, cnst1478* Outputs - out0, out1479* Return Type - as per RTYPE480* Details : Signed halfword elements from 'mult0' are multiplied with481* signed halfword elements from 'cnst0' producing a result482* twice the size of input i.e. signed word.483* The multiplication result of adjacent odd-even elements484* are added together and written to the 'out0' vector485*/486#define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) do { \487out0 = (RTYPE)__msa_dotp_s_w((v8i16)mult0, (v8i16)cnst0); \488out1 = (RTYPE)__msa_dotp_s_w((v8i16)mult1, (v8i16)cnst1); \489} while (0)490#define DOTP_SH2_SW(...) DOTP_SH2(v4i32, __VA_ARGS__)491492/* Description : Dot product of unsigned word vector elements493* Arguments : Inputs - mult0, mult1, cnst0, cnst1494* Outputs - out0, out1495* Return Type - as per RTYPE496* Details : Unsigned word elements from 'mult0' are multiplied with497* unsigned word elements from 'cnst0' producing a result498* twice the size of input i.e. unsigned double word.499* The multiplication result of adjacent odd-even elements500* are added together and written to the 'out0' vector501*/502#define DOTP_UW2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) do { \503out0 = (RTYPE)__msa_dotp_u_d((v4u32)mult0, (v4u32)cnst0); \504out1 = (RTYPE)__msa_dotp_u_d((v4u32)mult1, (v4u32)cnst1); \505} while (0)506#define DOTP_UW2_UD(...) DOTP_UW2(v2u64, __VA_ARGS__)507508/* Description : Dot product & addition of halfword vector elements509* Arguments : Inputs - mult0, mult1, cnst0, cnst1510* Outputs - out0, out1511* Return Type - as per RTYPE512* Details : Signed halfword elements from 'mult0' are multiplied with513* signed halfword elements from 'cnst0' producing a result514* twice the size of input i.e. signed word.515* The multiplication result of adjacent odd-even elements516* are added to the 'out0' vector517*/518#define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1) do { \519out0 = (RTYPE)__msa_dpadd_s_w((v4i32)out0, (v8i16)mult0, (v8i16)cnst0); \520out1 = (RTYPE)__msa_dpadd_s_w((v4i32)out1, (v8i16)mult1, (v8i16)cnst1); \521} while (0)522#define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)523524/* Description : Clips all signed halfword elements of input vector525* between 0 & 255526* Arguments : Input/output - val527* Return Type - signed halfword528*/529#define CLIP_SH_0_255(val) do { \530const v8i16 max_m = __msa_ldi_h(255); \531val = __msa_maxi_s_h((v8i16)val, 0); \532val = __msa_min_s_h(max_m, (v8i16)val); \533} while (0)534535#define CLIP_SH2_0_255(in0, in1) do { \536CLIP_SH_0_255(in0); \537CLIP_SH_0_255(in1); \538} while (0)539540#define CLIP_SH4_0_255(in0, in1, in2, in3) do { \541CLIP_SH2_0_255(in0, in1); \542CLIP_SH2_0_255(in2, in3); \543} while (0)544545/* Description : Clips all unsigned halfword elements of input vector546* between 0 & 255547* Arguments : Input - in548* Output - out_m549* Return Type - unsigned halfword550*/551#define CLIP_UH_0_255(in) do { \552const v8u16 max_m = (v8u16)__msa_ldi_h(255); \553in = __msa_maxi_u_h((v8u16) in, 0); \554in = __msa_min_u_h((v8u16) max_m, (v8u16) in); \555} while (0)556557#define CLIP_UH2_0_255(in0, in1) do { \558CLIP_UH_0_255(in0); \559CLIP_UH_0_255(in1); \560} while (0)561562/* Description : Clips all signed word elements of input vector563* between 0 & 255564* Arguments : Input/output - val565* Return Type - signed word566*/567#define CLIP_SW_0_255(val) do { \568const v4i32 max_m = __msa_ldi_w(255); \569val = __msa_maxi_s_w((v4i32)val, 0); \570val = __msa_min_s_w(max_m, (v4i32)val); \571} while (0)572573#define CLIP_SW4_0_255(in0, in1, in2, in3) do { \574CLIP_SW_0_255(in0); \575CLIP_SW_0_255(in1); \576CLIP_SW_0_255(in2); \577CLIP_SW_0_255(in3); \578} while (0)579580/* Description : Horizontal addition of 4 signed word elements of input vector581* Arguments : Input - in (signed word vector)582* Output - sum_m (i32 sum)583* Return Type - signed word (GP)584* Details : 4 signed word elements of 'in' vector are added together and585* the resulting integer sum is returned586*/587static WEBP_INLINE int32_t func_hadd_sw_s32(v4i32 in) {588const v2i64 res0_m = __msa_hadd_s_d((v4i32)in, (v4i32)in);589const v2i64 res1_m = __msa_splati_d(res0_m, 1);590const v2i64 out = res0_m + res1_m;591int32_t sum_m = __msa_copy_s_w((v4i32)out, 0);592return sum_m;593}594#define HADD_SW_S32(in) func_hadd_sw_s32(in)595596/* Description : Horizontal addition of 8 signed halfword elements597* Arguments : Input - in (signed halfword vector)598* Output - sum_m (s32 sum)599* Return Type - signed word600* Details : 8 signed halfword elements of input vector are added601* together and the resulting integer sum is returned602*/603static WEBP_INLINE int32_t func_hadd_sh_s32(v8i16 in) {604const v4i32 res = __msa_hadd_s_w(in, in);605const v2i64 res0 = __msa_hadd_s_d(res, res);606const v2i64 res1 = __msa_splati_d(res0, 1);607const v2i64 res2 = res0 + res1;608const int32_t sum_m = __msa_copy_s_w((v4i32)res2, 0);609return sum_m;610}611#define HADD_SH_S32(in) func_hadd_sh_s32(in)612613/* Description : Horizontal addition of 8 unsigned halfword elements614* Arguments : Input - in (unsigned halfword vector)615* Output - sum_m (u32 sum)616* Return Type - unsigned word617* Details : 8 unsigned halfword elements of input vector are added618* together and the resulting integer sum is returned619*/620static WEBP_INLINE uint32_t func_hadd_uh_u32(v8u16 in) {621uint32_t sum_m;622const v4u32 res_m = __msa_hadd_u_w(in, in);623v2u64 res0_m = __msa_hadd_u_d(res_m, res_m);624v2u64 res1_m = (v2u64)__msa_splati_d((v2i64)res0_m, 1);625res0_m = res0_m + res1_m;626sum_m = __msa_copy_s_w((v4i32)res0_m, 0);627return sum_m;628}629#define HADD_UH_U32(in) func_hadd_uh_u32(in)630631/* Description : Horizontal addition of signed half word vector elements632Arguments : Inputs - in0, in1633Outputs - out0, out1634Return Type - as per RTYPE635Details : Each signed odd half word element from 'in0' is added to636even signed half word element from 'in0' (pairwise) and the637halfword result is written in 'out0'638*/639#define HADD_SH2(RTYPE, in0, in1, out0, out1) do { \640out0 = (RTYPE)__msa_hadd_s_w((v8i16)in0, (v8i16)in0); \641out1 = (RTYPE)__msa_hadd_s_w((v8i16)in1, (v8i16)in1); \642} while (0)643#define HADD_SH2_SW(...) HADD_SH2(v4i32, __VA_ARGS__)644645#define HADD_SH4(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) do { \646HADD_SH2(RTYPE, in0, in1, out0, out1); \647HADD_SH2(RTYPE, in2, in3, out2, out3); \648} while (0)649#define HADD_SH4_SW(...) HADD_SH4(v4i32, __VA_ARGS__)650651/* Description : Horizontal subtraction of unsigned byte vector elements652* Arguments : Inputs - in0, in1653* Outputs - out0, out1654* Return Type - as per RTYPE655* Details : Each unsigned odd byte element from 'in0' is subtracted from656* even unsigned byte element from 'in0' (pairwise) and the657* halfword result is written to 'out0'658*/659#define HSUB_UB2(RTYPE, in0, in1, out0, out1) do { \660out0 = (RTYPE)__msa_hsub_u_h((v16u8)in0, (v16u8)in0); \661out1 = (RTYPE)__msa_hsub_u_h((v16u8)in1, (v16u8)in1); \662} while (0)663#define HSUB_UB2_UH(...) HSUB_UB2(v8u16, __VA_ARGS__)664#define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)665#define HSUB_UB2_SW(...) HSUB_UB2(v4i32, __VA_ARGS__)666667/* Description : Set element n input vector to GPR value668* Arguments : Inputs - in0, in1, in2, in3669* Output - out670* Return Type - as per RTYPE671* Details : Set element 0 in vector 'out' to value specified in 'in0'672*/673#define INSERT_W2(RTYPE, in0, in1, out) do { \674out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \675out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \676} while (0)677#define INSERT_W2_UB(...) INSERT_W2(v16u8, __VA_ARGS__)678#define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)679680#define INSERT_W4(RTYPE, in0, in1, in2, in3, out) do { \681out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \682out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \683out = (RTYPE)__msa_insert_w((v4i32)out, 2, in2); \684out = (RTYPE)__msa_insert_w((v4i32)out, 3, in3); \685} while (0)686#define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)687#define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)688#define INSERT_W4_SW(...) INSERT_W4(v4i32, __VA_ARGS__)689690/* Description : Set element n of double word input vector to GPR value691* Arguments : Inputs - in0, in1692* Output - out693* Return Type - as per RTYPE694* Details : Set element 0 in vector 'out' to GPR value specified in 'in0'695* Set element 1 in vector 'out' to GPR value specified in 'in1'696*/697#define INSERT_D2(RTYPE, in0, in1, out) do { \698out = (RTYPE)__msa_insert_d((v2i64)out, 0, in0); \699out = (RTYPE)__msa_insert_d((v2i64)out, 1, in1); \700} while (0)701#define INSERT_D2_UB(...) INSERT_D2(v16u8, __VA_ARGS__)702#define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)703704/* Description : Interleave even byte elements from vectors705* Arguments : Inputs - in0, in1, in2, in3706* Outputs - out0, out1707* Return Type - as per RTYPE708* Details : Even byte elements of 'in0' and 'in1' are interleaved709* and written to 'out0'710*/711#define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) do { \712out0 = (RTYPE)__msa_ilvev_b((v16i8)in1, (v16i8)in0); \713out1 = (RTYPE)__msa_ilvev_b((v16i8)in3, (v16i8)in2); \714} while (0)715#define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)716#define ILVEV_B2_SB(...) ILVEV_B2(v16i8, __VA_ARGS__)717#define ILVEV_B2_UH(...) ILVEV_B2(v8u16, __VA_ARGS__)718#define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)719#define ILVEV_B2_SD(...) ILVEV_B2(v2i64, __VA_ARGS__)720721/* Description : Interleave odd byte elements from vectors722* Arguments : Inputs - in0, in1, in2, in3723* Outputs - out0, out1724* Return Type - as per RTYPE725* Details : Odd byte elements of 'in0' and 'in1' are interleaved726* and written to 'out0'727*/728#define ILVOD_B2(RTYPE, in0, in1, in2, in3, out0, out1) do { \729out0 = (RTYPE)__msa_ilvod_b((v16i8)in1, (v16i8)in0); \730out1 = (RTYPE)__msa_ilvod_b((v16i8)in3, (v16i8)in2); \731} while (0)732#define ILVOD_B2_UB(...) ILVOD_B2(v16u8, __VA_ARGS__)733#define ILVOD_B2_SB(...) ILVOD_B2(v16i8, __VA_ARGS__)734#define ILVOD_B2_UH(...) ILVOD_B2(v8u16, __VA_ARGS__)735#define ILVOD_B2_SH(...) ILVOD_B2(v8i16, __VA_ARGS__)736#define ILVOD_B2_SD(...) ILVOD_B2(v2i64, __VA_ARGS__)737738/* Description : Interleave even halfword elements from vectors739* Arguments : Inputs - in0, in1, in2, in3740* Outputs - out0, out1741* Return Type - as per RTYPE742* Details : Even halfword elements of 'in0' and 'in1' are interleaved743* and written to 'out0'744*/745#define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \746out0 = (RTYPE)__msa_ilvev_h((v8i16)in1, (v8i16)in0); \747out1 = (RTYPE)__msa_ilvev_h((v8i16)in3, (v8i16)in2); \748} while (0)749#define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)750#define ILVEV_H2_UH(...) ILVEV_H2(v8u16, __VA_ARGS__)751#define ILVEV_H2_SH(...) ILVEV_H2(v8i16, __VA_ARGS__)752#define ILVEV_H2_SW(...) ILVEV_H2(v4i32, __VA_ARGS__)753754/* Description : Interleave odd halfword elements from vectors755* Arguments : Inputs - in0, in1, in2, in3756* Outputs - out0, out1757* Return Type - as per RTYPE758* Details : Odd halfword elements of 'in0' and 'in1' are interleaved759* and written to 'out0'760*/761#define ILVOD_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \762out0 = (RTYPE)__msa_ilvod_h((v8i16)in1, (v8i16)in0); \763out1 = (RTYPE)__msa_ilvod_h((v8i16)in3, (v8i16)in2); \764} while (0)765#define ILVOD_H2_UB(...) ILVOD_H2(v16u8, __VA_ARGS__)766#define ILVOD_H2_UH(...) ILVOD_H2(v8u16, __VA_ARGS__)767#define ILVOD_H2_SH(...) ILVOD_H2(v8i16, __VA_ARGS__)768#define ILVOD_H2_SW(...) ILVOD_H2(v4i32, __VA_ARGS__)769770/* Description : Interleave even word elements from vectors771* Arguments : Inputs - in0, in1, in2, in3772* Outputs - out0, out1773* Return Type - as per RTYPE774* Details : Even word elements of 'in0' and 'in1' are interleaved775* and written to 'out0'776*/777#define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) do { \778out0 = (RTYPE)__msa_ilvev_w((v4i32)in1, (v4i32)in0); \779out1 = (RTYPE)__msa_ilvev_w((v4i32)in3, (v4i32)in2); \780} while (0)781#define ILVEV_W2_UB(...) ILVEV_W2(v16u8, __VA_ARGS__)782#define ILVEV_W2_SB(...) ILVEV_W2(v16i8, __VA_ARGS__)783#define ILVEV_W2_UH(...) ILVEV_W2(v8u16, __VA_ARGS__)784#define ILVEV_W2_SD(...) ILVEV_W2(v2i64, __VA_ARGS__)785786/* Description : Interleave even-odd word elements from vectors787* Arguments : Inputs - in0, in1, in2, in3788* Outputs - out0, out1789* Return Type - as per RTYPE790* Details : Even word elements of 'in0' and 'in1' are interleaved791* and written to 'out0'792* Odd word elements of 'in2' and 'in3' are interleaved793* and written to 'out1'794*/795#define ILVEVOD_W2(RTYPE, in0, in1, in2, in3, out0, out1) do { \796out0 = (RTYPE)__msa_ilvev_w((v4i32)in1, (v4i32)in0); \797out1 = (RTYPE)__msa_ilvod_w((v4i32)in3, (v4i32)in2); \798} while (0)799#define ILVEVOD_W2_UB(...) ILVEVOD_W2(v16u8, __VA_ARGS__)800#define ILVEVOD_W2_UH(...) ILVEVOD_W2(v8u16, __VA_ARGS__)801#define ILVEVOD_W2_SH(...) ILVEVOD_W2(v8i16, __VA_ARGS__)802#define ILVEVOD_W2_SW(...) ILVEVOD_W2(v4i32, __VA_ARGS__)803804/* Description : Interleave even-odd half-word elements from vectors805* Arguments : Inputs - in0, in1, in2, in3806* Outputs - out0, out1807* Return Type - as per RTYPE808* Details : Even half-word elements of 'in0' and 'in1' are interleaved809* and written to 'out0'810* Odd half-word elements of 'in2' and 'in3' are interleaved811* and written to 'out1'812*/813#define ILVEVOD_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \814out0 = (RTYPE)__msa_ilvev_h((v8i16)in1, (v8i16)in0); \815out1 = (RTYPE)__msa_ilvod_h((v8i16)in3, (v8i16)in2); \816} while (0)817#define ILVEVOD_H2_UB(...) ILVEVOD_H2(v16u8, __VA_ARGS__)818#define ILVEVOD_H2_UH(...) ILVEVOD_H2(v8u16, __VA_ARGS__)819#define ILVEVOD_H2_SH(...) ILVEVOD_H2(v8i16, __VA_ARGS__)820#define ILVEVOD_H2_SW(...) ILVEVOD_H2(v4i32, __VA_ARGS__)821822/* Description : Interleave even double word elements from vectors823* Arguments : Inputs - in0, in1, in2, in3824* Outputs - out0, out1825* Return Type - as per RTYPE826* Details : Even double word elements of 'in0' and 'in1' are interleaved827* and written to 'out0'828*/829#define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1) do { \830out0 = (RTYPE)__msa_ilvev_d((v2i64)in1, (v2i64)in0); \831out1 = (RTYPE)__msa_ilvev_d((v2i64)in3, (v2i64)in2); \832} while (0)833#define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)834#define ILVEV_D2_SB(...) ILVEV_D2(v16i8, __VA_ARGS__)835#define ILVEV_D2_SW(...) ILVEV_D2(v4i32, __VA_ARGS__)836#define ILVEV_D2_SD(...) ILVEV_D2(v2i64, __VA_ARGS__)837838/* Description : Interleave left half of byte elements from vectors839* Arguments : Inputs - in0, in1, in2, in3840* Outputs - out0, out1841* Return Type - as per RTYPE842* Details : Left half of byte elements of 'in0' and 'in1' are interleaved843* and written to 'out0'.844*/845#define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1) do { \846out0 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \847out1 = (RTYPE)__msa_ilvl_b((v16i8)in2, (v16i8)in3); \848} while (0)849#define ILVL_B2_UB(...) ILVL_B2(v16u8, __VA_ARGS__)850#define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)851#define ILVL_B2_UH(...) ILVL_B2(v8u16, __VA_ARGS__)852#define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)853#define ILVL_B2_SW(...) ILVL_B2(v4i32, __VA_ARGS__)854855/* Description : Interleave right half of byte elements from vectors856* Arguments : Inputs - in0, in1, in2, in3857* Outputs - out0, out1858* Return Type - as per RTYPE859* Details : Right half of byte elements of 'in0' and 'in1' are interleaved860* and written to out0.861*/862#define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) do { \863out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \864out1 = (RTYPE)__msa_ilvr_b((v16i8)in2, (v16i8)in3); \865} while (0)866#define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)867#define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)868#define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)869#define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)870#define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)871872#define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \873out0, out1, out2, out3) do { \874ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \875ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \876} while (0)877#define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)878#define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)879#define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)880#define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)881#define ILVR_B4_SW(...) ILVR_B4(v4i32, __VA_ARGS__)882883/* Description : Interleave right half of halfword elements from vectors884* Arguments : Inputs - in0, in1, in2, in3885* Outputs - out0, out1886* Return Type - as per RTYPE887* Details : Right half of halfword elements of 'in0' and 'in1' are888* interleaved and written to 'out0'.889*/890#define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \891out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \892out1 = (RTYPE)__msa_ilvr_h((v8i16)in2, (v8i16)in3); \893} while (0)894#define ILVR_H2_UB(...) ILVR_H2(v16u8, __VA_ARGS__)895#define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)896#define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)897898#define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \899out0, out1, out2, out3) do { \900ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \901ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \902} while (0)903#define ILVR_H4_UB(...) ILVR_H4(v16u8, __VA_ARGS__)904#define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)905#define ILVR_H4_SW(...) ILVR_H4(v4i32, __VA_ARGS__)906907/* Description : Interleave right half of double word elements from vectors908* Arguments : Inputs - in0, in1, in2, in3909* Outputs - out0, out1910* Return Type - as per RTYPE911* Details : Right half of double word elements of 'in0' and 'in1' are912* interleaved and written to 'out0'.913*/914#define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) do { \915out0 = (RTYPE)__msa_ilvr_d((v2i64)in0, (v2i64)in1); \916out1 = (RTYPE)__msa_ilvr_d((v2i64)in2, (v2i64)in3); \917} while (0)918#define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)919#define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)920#define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)921922#define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \923out0, out1, out2, out3) do { \924ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1); \925ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3); \926} while (0)927#define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)928#define ILVR_D4_UB(...) ILVR_D4(v16u8, __VA_ARGS__)929930/* Description : Interleave both left and right half of input vectors931* Arguments : Inputs - in0, in1932* Outputs - out0, out1933* Return Type - as per RTYPE934* Details : Right half of byte elements from 'in0' and 'in1' are935* interleaved and written to 'out0'936*/937#define ILVRL_B2(RTYPE, in0, in1, out0, out1) do { \938out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \939out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \940} while (0)941#define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)942#define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)943#define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)944#define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)945#define ILVRL_B2_SW(...) ILVRL_B2(v4i32, __VA_ARGS__)946947#define ILVRL_H2(RTYPE, in0, in1, out0, out1) do { \948out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \949out1 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1); \950} while (0)951#define ILVRL_H2_UB(...) ILVRL_H2(v16u8, __VA_ARGS__)952#define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)953#define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)954#define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)955#define ILVRL_H2_UW(...) ILVRL_H2(v4u32, __VA_ARGS__)956957#define ILVRL_W2(RTYPE, in0, in1, out0, out1) do { \958out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1); \959out1 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1); \960} while (0)961#define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)962#define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)963#define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)964#define ILVRL_W2_UW(...) ILVRL_W2(v4u32, __VA_ARGS__)965966/* Description : Pack even byte elements of vector pairs967* Arguments : Inputs - in0, in1, in2, in3968* Outputs - out0, out1969* Return Type - as per RTYPE970* Details : Even byte elements of 'in0' are copied to the left half of971* 'out0' & even byte elements of 'in1' are copied to the right972* half of 'out0'.973*/974#define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) do { \975out0 = (RTYPE)__msa_pckev_b((v16i8)in0, (v16i8)in1); \976out1 = (RTYPE)__msa_pckev_b((v16i8)in2, (v16i8)in3); \977} while (0)978#define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)979#define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)980#define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)981#define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)982983#define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \984out0, out1, out2, out3) do { \985PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1); \986PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3); \987} while (0)988#define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)989#define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)990#define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)991#define PCKEV_B4_SW(...) PCKEV_B4(v4i32, __VA_ARGS__)992993/* Description : Pack even halfword elements of vector pairs994* Arguments : Inputs - in0, in1, in2, in3995* Outputs - out0, out1996* Return Type - as per RTYPE997* Details : Even halfword elements of 'in0' are copied to the left half of998* 'out0' & even halfword elements of 'in1' are copied to the999* right half of 'out0'.1000*/1001#define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \1002out0 = (RTYPE)__msa_pckev_h((v8i16)in0, (v8i16)in1); \1003out1 = (RTYPE)__msa_pckev_h((v8i16)in2, (v8i16)in3); \1004} while (0)1005#define PCKEV_H2_UH(...) PCKEV_H2(v8u16, __VA_ARGS__)1006#define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)1007#define PCKEV_H2_SW(...) PCKEV_H2(v4i32, __VA_ARGS__)1008#define PCKEV_H2_UW(...) PCKEV_H2(v4u32, __VA_ARGS__)10091010/* Description : Pack even word elements of vector pairs1011* Arguments : Inputs - in0, in1, in2, in31012* Outputs - out0, out11013* Return Type - as per RTYPE1014* Details : Even word elements of 'in0' are copied to the left half of1015* 'out0' & even word elements of 'in1' are copied to the1016* right half of 'out0'.1017*/1018#define PCKEV_W2(RTYPE, in0, in1, in2, in3, out0, out1) do { \1019out0 = (RTYPE)__msa_pckev_w((v4i32)in0, (v4i32)in1); \1020out1 = (RTYPE)__msa_pckev_w((v4i32)in2, (v4i32)in3); \1021} while (0)1022#define PCKEV_W2_UH(...) PCKEV_W2(v8u16, __VA_ARGS__)1023#define PCKEV_W2_SH(...) PCKEV_W2(v8i16, __VA_ARGS__)1024#define PCKEV_W2_SW(...) PCKEV_W2(v4i32, __VA_ARGS__)1025#define PCKEV_W2_UW(...) PCKEV_W2(v4u32, __VA_ARGS__)10261027/* Description : Pack odd halfword elements of vector pairs1028* Arguments : Inputs - in0, in1, in2, in31029* Outputs - out0, out11030* Return Type - as per RTYPE1031* Details : Odd halfword elements of 'in0' are copied to the left half of1032* 'out0' & odd halfword elements of 'in1' are copied to the1033* right half of 'out0'.1034*/1035#define PCKOD_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \1036out0 = (RTYPE)__msa_pckod_h((v8i16)in0, (v8i16)in1); \1037out1 = (RTYPE)__msa_pckod_h((v8i16)in2, (v8i16)in3); \1038} while (0)1039#define PCKOD_H2_UH(...) PCKOD_H2(v8u16, __VA_ARGS__)1040#define PCKOD_H2_SH(...) PCKOD_H2(v8i16, __VA_ARGS__)1041#define PCKOD_H2_SW(...) PCKOD_H2(v4i32, __VA_ARGS__)1042#define PCKOD_H2_UW(...) PCKOD_H2(v4u32, __VA_ARGS__)10431044/* Description : Arithmetic immediate shift right all elements of word vector1045* Arguments : Inputs - in0, in1, shift1046* Outputs - in place operation1047* Return Type - as per input vector RTYPE1048* Details : Each element of vector 'in0' is right shifted by 'shift' and1049* the result is written in-place. 'shift' is a GP variable.1050*/1051#define SRAI_W2(RTYPE, in0, in1, shift_val) do { \1052in0 = (RTYPE)SRAI_W(in0, shift_val); \1053in1 = (RTYPE)SRAI_W(in1, shift_val); \1054} while (0)1055#define SRAI_W2_SW(...) SRAI_W2(v4i32, __VA_ARGS__)1056#define SRAI_W2_UW(...) SRAI_W2(v4u32, __VA_ARGS__)10571058#define SRAI_W4(RTYPE, in0, in1, in2, in3, shift_val) do { \1059SRAI_W2(RTYPE, in0, in1, shift_val); \1060SRAI_W2(RTYPE, in2, in3, shift_val); \1061} while (0)1062#define SRAI_W4_SW(...) SRAI_W4(v4i32, __VA_ARGS__)1063#define SRAI_W4_UW(...) SRAI_W4(v4u32, __VA_ARGS__)10641065/* Description : Arithmetic shift right all elements of half-word vector1066* Arguments : Inputs - in0, in1, shift1067* Outputs - in place operation1068* Return Type - as per input vector RTYPE1069* Details : Each element of vector 'in0' is right shifted by 'shift' and1070* the result is written in-place. 'shift' is a GP variable.1071*/1072#define SRAI_H2(RTYPE, in0, in1, shift_val) do { \1073in0 = (RTYPE)SRAI_H(in0, shift_val); \1074in1 = (RTYPE)SRAI_H(in1, shift_val); \1075} while (0)1076#define SRAI_H2_SH(...) SRAI_H2(v8i16, __VA_ARGS__)1077#define SRAI_H2_UH(...) SRAI_H2(v8u16, __VA_ARGS__)10781079/* Description : Arithmetic rounded shift right all elements of word vector1080* Arguments : Inputs - in0, in1, shift1081* Outputs - in place operation1082* Return Type - as per input vector RTYPE1083* Details : Each element of vector 'in0' is right shifted by 'shift' and1084* the result is written in-place. 'shift' is a GP variable.1085*/1086#define SRARI_W2(RTYPE, in0, in1, shift) do { \1087in0 = (RTYPE)__msa_srari_w((v4i32)in0, shift); \1088in1 = (RTYPE)__msa_srari_w((v4i32)in1, shift); \1089} while (0)1090#define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)10911092#define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) do { \1093SRARI_W2(RTYPE, in0, in1, shift); \1094SRARI_W2(RTYPE, in2, in3, shift); \1095} while (0)1096#define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)1097#define SRARI_W4_UW(...) SRARI_W4(v4u32, __VA_ARGS__)1098#define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)10991100/* Description : Shift right arithmetic rounded double words1101* Arguments : Inputs - in0, in1, shift1102* Outputs - in place operation1103* Return Type - as per RTYPE1104* Details : Each element of vector 'in0' is shifted right arithmetically by1105* the number of bits in the corresponding element in the vector1106* 'shift'. The last discarded bit is added to shifted value for1107* rounding and the result is written in-place.1108* 'shift' is a vector.1109*/1110#define SRAR_D2(RTYPE, in0, in1, shift) do { \1111in0 = (RTYPE)__msa_srar_d((v2i64)in0, (v2i64)shift); \1112in1 = (RTYPE)__msa_srar_d((v2i64)in1, (v2i64)shift); \1113} while (0)1114#define SRAR_D2_SW(...) SRAR_D2(v4i32, __VA_ARGS__)1115#define SRAR_D2_SD(...) SRAR_D2(v2i64, __VA_ARGS__)1116#define SRAR_D2_UD(...) SRAR_D2(v2u64, __VA_ARGS__)11171118#define SRAR_D4(RTYPE, in0, in1, in2, in3, shift) do { \1119SRAR_D2(RTYPE, in0, in1, shift); \1120SRAR_D2(RTYPE, in2, in3, shift); \1121} while (0)1122#define SRAR_D4_SD(...) SRAR_D4(v2i64, __VA_ARGS__)1123#define SRAR_D4_UD(...) SRAR_D4(v2u64, __VA_ARGS__)11241125/* Description : Addition of 2 pairs of half-word vectors1126* Arguments : Inputs - in0, in1, in2, in31127* Outputs - out0, out11128* Details : Each element in 'in0' is added to 'in1' and result is written1129* to 'out0'.1130*/1131#define ADDVI_H2(RTYPE, in0, in1, in2, in3, out0, out1) do { \1132out0 = (RTYPE)ADDVI_H(in0, in1); \1133out1 = (RTYPE)ADDVI_H(in2, in3); \1134} while (0)1135#define ADDVI_H2_SH(...) ADDVI_H2(v8i16, __VA_ARGS__)1136#define ADDVI_H2_UH(...) ADDVI_H2(v8u16, __VA_ARGS__)11371138/* Description : Addition of 2 pairs of word vectors1139* Arguments : Inputs - in0, in1, in2, in31140* Outputs - out0, out11141* Details : Each element in 'in0' is added to 'in1' and result is written1142* to 'out0'.1143*/1144#define ADDVI_W2(RTYPE, in0, in1, in2, in3, out0, out1) do { \1145out0 = (RTYPE)ADDVI_W(in0, in1); \1146out1 = (RTYPE)ADDVI_W(in2, in3); \1147} while (0)1148#define ADDVI_W2_SW(...) ADDVI_W2(v4i32, __VA_ARGS__)11491150/* Description : Fill 2 pairs of word vectors with GP registers1151* Arguments : Inputs - in0, in11152* Outputs - out0, out11153* Details : GP register in0 is replicated in each word element of out01154* GP register in1 is replicated in each word element of out11155*/1156#define FILL_W2(RTYPE, in0, in1, out0, out1) do { \1157out0 = (RTYPE)__msa_fill_w(in0); \1158out1 = (RTYPE)__msa_fill_w(in1); \1159} while (0)1160#define FILL_W2_SW(...) FILL_W2(v4i32, __VA_ARGS__)11611162/* Description : Addition of 2 pairs of vectors1163* Arguments : Inputs - in0, in1, in2, in31164* Outputs - out0, out11165* Details : Each element in 'in0' is added to 'in1' and result is written1166* to 'out0'.1167*/1168#define ADD2(in0, in1, in2, in3, out0, out1) do { \1169out0 = in0 + in1; \1170out1 = in2 + in3; \1171} while (0)11721173#define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, \1174out0, out1, out2, out3) do { \1175ADD2(in0, in1, in2, in3, out0, out1); \1176ADD2(in4, in5, in6, in7, out2, out3); \1177} while (0)11781179/* Description : Subtraction of 2 pairs of vectors1180* Arguments : Inputs - in0, in1, in2, in31181* Outputs - out0, out11182* Details : Each element in 'in1' is subtracted from 'in0' and result is1183* written to 'out0'.1184*/1185#define SUB2(in0, in1, in2, in3, out0, out1) do { \1186out0 = in0 - in1; \1187out1 = in2 - in3; \1188} while (0)11891190#define SUB3(in0, in1, in2, in3, in4, in5, out0, out1, out2) do { \1191out0 = in0 - in1; \1192out1 = in2 - in3; \1193out2 = in4 - in5; \1194} while (0)11951196#define SUB4(in0, in1, in2, in3, in4, in5, in6, in7, \1197out0, out1, out2, out3) do { \1198out0 = in0 - in1; \1199out1 = in2 - in3; \1200out2 = in4 - in5; \1201out3 = in6 - in7; \1202} while (0)12031204/* Description : Addition - Subtraction of input vectors1205* Arguments : Inputs - in0, in11206* Outputs - out0, out11207* Details : Each element in 'in1' is added to 'in0' and result is1208* written to 'out0'.1209* Each element in 'in1' is subtracted from 'in0' and result is1210* written to 'out1'.1211*/1212#define ADDSUB2(in0, in1, out0, out1) do { \1213out0 = in0 + in1; \1214out1 = in0 - in1; \1215} while (0)12161217/* Description : Multiplication of pairs of vectors1218* Arguments : Inputs - in0, in1, in2, in31219* Outputs - out0, out11220* Details : Each element from 'in0' is multiplied with elements from 'in1'1221* and the result is written to 'out0'1222*/1223#define MUL2(in0, in1, in2, in3, out0, out1) do { \1224out0 = in0 * in1; \1225out1 = in2 * in3; \1226} while (0)12271228#define MUL4(in0, in1, in2, in3, in4, in5, in6, in7, \1229out0, out1, out2, out3) do { \1230MUL2(in0, in1, in2, in3, out0, out1); \1231MUL2(in4, in5, in6, in7, out2, out3); \1232} while (0)12331234/* Description : Sign extend halfword elements from right half of the vector1235* Arguments : Input - in (halfword vector)1236* Output - out (sign extended word vector)1237* Return Type - signed word1238* Details : Sign bit of halfword elements from input vector 'in' is1239* extracted and interleaved with same vector 'in0' to generate1240* 4 word elements keeping sign intact1241*/1242#define UNPCK_R_SH_SW(in, out) do { \1243const v8i16 sign_m = __msa_clti_s_h((v8i16)in, 0); \1244out = (v4i32)__msa_ilvr_h(sign_m, (v8i16)in); \1245} while (0)12461247/* Description : Sign extend halfword elements from input vector and return1248* the result in pair of vectors1249* Arguments : Input - in (halfword vector)1250* Outputs - out0, out1 (sign extended word vectors)1251* Return Type - signed word1252* Details : Sign bit of halfword elements from input vector 'in' is1253* extracted and interleaved right with same vector 'in0' to1254* generate 4 signed word elements in 'out0'1255* Then interleaved left with same vector 'in0' to1256* generate 4 signed word elements in 'out1'1257*/1258#define UNPCK_SH_SW(in, out0, out1) do { \1259const v8i16 tmp_m = __msa_clti_s_h((v8i16)in, 0); \1260ILVRL_H2_SW(tmp_m, in, out0, out1); \1261} while (0)12621263/* Description : Butterfly of 4 input vectors1264* Arguments : Inputs - in0, in1, in2, in31265* Outputs - out0, out1, out2, out31266* Details : Butterfly operation1267*/1268#define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) do { \1269out0 = in0 + in3; \1270out1 = in1 + in2; \1271out2 = in1 - in2; \1272out3 = in0 - in3; \1273} while (0)12741275/* Description : Transpose 16x4 block into 4x16 with byte elements in vectors1276* Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,1277* in8, in9, in10, in11, in12, in13, in14, in151278* Outputs - out0, out1, out2, out31279* Return Type - unsigned byte1280*/1281#define TRANSPOSE16x4_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \1282in8, in9, in10, in11, in12, in13, in14, in15, \1283out0, out1, out2, out3) do { \1284v2i64 tmp0_m, tmp1_m, tmp2_m, tmp3_m, tmp4_m, tmp5_m; \1285ILVEV_W2_SD(in0, in4, in8, in12, tmp2_m, tmp3_m); \1286ILVEV_W2_SD(in1, in5, in9, in13, tmp0_m, tmp1_m); \1287ILVEV_D2_UB(tmp2_m, tmp3_m, tmp0_m, tmp1_m, out1, out3); \1288ILVEV_W2_SD(in2, in6, in10, in14, tmp4_m, tmp5_m); \1289ILVEV_W2_SD(in3, in7, in11, in15, tmp0_m, tmp1_m); \1290ILVEV_D2_SD(tmp4_m, tmp5_m, tmp0_m, tmp1_m, tmp2_m, tmp3_m); \1291ILVEV_B2_SD(out1, out3, tmp2_m, tmp3_m, tmp0_m, tmp1_m); \1292ILVEVOD_H2_UB(tmp0_m, tmp1_m, tmp0_m, tmp1_m, out0, out2); \1293ILVOD_B2_SD(out1, out3, tmp2_m, tmp3_m, tmp0_m, tmp1_m); \1294ILVEVOD_H2_UB(tmp0_m, tmp1_m, tmp0_m, tmp1_m, out1, out3); \1295} while (0)12961297/* Description : Transpose 16x8 block into 8x16 with byte elements in vectors1298* Arguments : Inputs - in0, in1, in2, in3, in4, in5, in6, in7,1299* in8, in9, in10, in11, in12, in13, in14, in151300* Outputs - out0, out1, out2, out3, out4, out5, out6, out71301* Return Type - unsigned byte1302*/1303#define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7, \1304in8, in9, in10, in11, in12, in13, in14, in15, \1305out0, out1, out2, out3, out4, out5, \1306out6, out7) do { \1307v8i16 tmp0_m, tmp1_m, tmp4_m, tmp5_m, tmp6_m, tmp7_m; \1308v4i32 tmp2_m, tmp3_m; \1309ILVEV_D2_UB(in0, in8, in1, in9, out7, out6); \1310ILVEV_D2_UB(in2, in10, in3, in11, out5, out4); \1311ILVEV_D2_UB(in4, in12, in5, in13, out3, out2); \1312ILVEV_D2_UB(in6, in14, in7, in15, out1, out0); \1313ILVEV_B2_SH(out7, out6, out5, out4, tmp0_m, tmp1_m); \1314ILVOD_B2_SH(out7, out6, out5, out4, tmp4_m, tmp5_m); \1315ILVEV_B2_UB(out3, out2, out1, out0, out5, out7); \1316ILVOD_B2_SH(out3, out2, out1, out0, tmp6_m, tmp7_m); \1317ILVEV_H2_SW(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \1318ILVEVOD_W2_UB(tmp2_m, tmp3_m, tmp2_m, tmp3_m, out0, out4); \1319ILVOD_H2_SW(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m); \1320ILVEVOD_W2_UB(tmp2_m, tmp3_m, tmp2_m, tmp3_m, out2, out6); \1321ILVEV_H2_SW(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \1322ILVEVOD_W2_UB(tmp2_m, tmp3_m, tmp2_m, tmp3_m, out1, out5); \1323ILVOD_H2_SW(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m); \1324ILVEVOD_W2_UB(tmp2_m, tmp3_m, tmp2_m, tmp3_m, out3, out7); \1325} while (0)13261327/* Description : Transpose 4x4 block with word elements in vectors1328* Arguments : Inputs - in0, in1, in2, in31329* Outputs - out0, out1, out2, out31330* Return Type - as per RTYPE1331*/1332#define TRANSPOSE4x4_W(RTYPE, in0, in1, in2, in3, \1333out0, out1, out2, out3) do { \1334v4i32 s0_m, s1_m, s2_m, s3_m; \1335ILVRL_W2_SW(in1, in0, s0_m, s1_m); \1336ILVRL_W2_SW(in3, in2, s2_m, s3_m); \1337out0 = (RTYPE)__msa_ilvr_d((v2i64)s2_m, (v2i64)s0_m); \1338out1 = (RTYPE)__msa_ilvl_d((v2i64)s2_m, (v2i64)s0_m); \1339out2 = (RTYPE)__msa_ilvr_d((v2i64)s3_m, (v2i64)s1_m); \1340out3 = (RTYPE)__msa_ilvl_d((v2i64)s3_m, (v2i64)s1_m); \1341} while (0)1342#define TRANSPOSE4x4_SW_SW(...) TRANSPOSE4x4_W(v4i32, __VA_ARGS__)13431344/* Description : Add block 4x41345* Arguments : Inputs - in0, in1, in2, in3, pdst, stride1346* Details : Least significant 4 bytes from each input vector are added to1347* the destination bytes, clipped between 0-255 and stored.1348*/1349#define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) do { \1350uint32_t src0_m, src1_m, src2_m, src3_m; \1351v8i16 inp0_m, inp1_m, res0_m, res1_m; \1352v16i8 dst0_m = { 0 }; \1353v16i8 dst1_m = { 0 }; \1354const v16i8 zero_m = { 0 }; \1355ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m); \1356LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \1357INSERT_W2_SB(src0_m, src1_m, dst0_m); \1358INSERT_W2_SB(src2_m, src3_m, dst1_m); \1359ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \1360ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \1361CLIP_SH2_0_255(res0_m, res1_m); \1362PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \1363ST4x4_UB(dst0_m, dst1_m, 0, 1, 0, 1, pdst, stride); \1364} while (0)13651366/* Description : Pack even byte elements, extract 0 & 2 index words from pair1367* of results and store 4 words in destination memory as per1368* stride1369* Arguments : Inputs - in0, in1, in2, in3, pdst, stride1370*/1371#define PCKEV_ST4x4_UB(in0, in1, in2, in3, pdst, stride) do { \1372v16i8 tmp0_m, tmp1_m; \1373PCKEV_B2_SB(in1, in0, in3, in2, tmp0_m, tmp1_m); \1374ST4x4_UB(tmp0_m, tmp1_m, 0, 2, 0, 2, pdst, stride); \1375} while (0)13761377/* Description : average with rounding (in0 + in1 + 1) / 2.1378* Arguments : Inputs - in0, in1, in2, in3,1379* Outputs - out0, out11380* Return Type - as per RTYPE1381* Details : Each unsigned byte element from 'in0' vector is added with1382* each unsigned byte element from 'in1' vector. Then the average1383* with rounding is calculated and written to 'out0'1384*/1385#define AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) do { \1386out0 = (RTYPE)__msa_aver_u_b((v16u8)in0, (v16u8)in1); \1387out1 = (RTYPE)__msa_aver_u_b((v16u8)in2, (v16u8)in3); \1388} while (0)1389#define AVER_UB2_UB(...) AVER_UB2(v16u8, __VA_ARGS__)13901391#endif /* WEBP_DSP_MSA_MACRO_H_ */139213931394