• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  **********************************************************************************
3  * Copyright (c) 2021 Loongson Technology Corporation Limited
4  * Contributed by Lu Wang <wanglu@loongson.cn>
5  *
6  * \copy
7  *     Copyright (c)  2013, Cisco Systems
8  *     All rights reserved.
9  *
10  *     Redistribution and use in source and binary forms, with or without
11  *     modification, are permitted provided that the following conditions
12  *     are met:
13  *
14  *        * Redistributions of source code must retain the above copyright
15  *          notice, this list of conditions and the following disclaimer.
16  *
17  *        * Redistributions in binary form must reproduce the above copyright
18  *          notice, this list of conditions and the following disclaimer in
19  *          the documentation and/or other materials provided with the
20  *          distribution.
21  *
22  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  *     POSSIBILITY OF SUCH DAMAGE.
34  *
35  * \file    mc_chroma_lsx.c
36  *
37  * \brief   Loongson optimization
38  *
39  * \date    12/23/2021 Created
40  *
41  **********************************************************************************
42  */
43 
44 #include "stdint.h"
45 #include "loongson_intrinsics.h"
46 
McCopyWidthEq4_lsx(const uint8_t * pSrc,int iSrcStride,uint8_t * pDst,int iDstStride,int iHeight)47 void McCopyWidthEq4_lsx(const uint8_t *pSrc, int iSrcStride,
48                          uint8_t *pDst, int iDstStride, int iHeight) {
49   __m128i src0, src1;
50   int iSrcStride_x2 = iSrcStride << 1;
51   int iDstStride_x2 = iDstStride << 1;
52   iHeight = iHeight >> 1;
53   for (int i = 0; i < iHeight; i++) {
54     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0, src1);
55     __lsx_vstelm_w(src0, pDst, 0, 0);
56     __lsx_vstelm_w(src1, pDst + iDstStride, 0, 0);
57     pSrc += iSrcStride_x2;
58     pDst += iDstStride_x2;
59   }
60 }
61 
McCopyWidthEq8_lsx(const uint8_t * pSrc,int iSrcStride,uint8_t * pDst,int iDstStride,int iHeight)62 void McCopyWidthEq8_lsx(const uint8_t *pSrc, int iSrcStride,
63                         uint8_t *pDst, int iDstStride, int iHeight) {
64   __m128i src0, src1;
65   int iSrcStride_x2 = iSrcStride << 1;
66   int iDstStride_x2 = iDstStride << 1;
67   iHeight = iHeight >> 1;
68   for (int i = 0; i < iHeight; i++) {
69     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0, src1);
70     __lsx_vstelm_d(src0, pDst, 0, 0);
71     __lsx_vstelm_d(src1, pDst + iDstStride, 0, 0);
72     pSrc += iSrcStride_x2;
73     pDst += iDstStride_x2;
74   }
75 }
76 
McCopyWidthEq16_lsx(const uint8_t * pSrc,int iSrcStride,uint8_t * pDst,int iDstStride,int iHeight)77 void McCopyWidthEq16_lsx(const uint8_t *pSrc, int iSrcStride,
78                          uint8_t *pDst, int iDstStride, int iHeight) {
79   __m128i src0, src1;
80   int iSrcStride_x2 = iSrcStride << 1;
81   int iDstStride_x2 = iDstStride << 1;
82   iHeight = iHeight >> 1;
83   for (int i = 0; i < iHeight; i++) {
84     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0, src1);
85     __lsx_vst(src0, pDst, 0);
86     __lsx_vstx(src1, pDst, iDstStride);
87     pSrc += iSrcStride_x2;
88     pDst += iDstStride_x2;
89   }
90 }
91 
McChromaWidthEq4_lsx(const uint8_t * pSrc,int32_t iSrcStride,uint8_t * pDst,int32_t iDstStride,const uint8_t * pABCD,int32_t iHeight)92 void McChromaWidthEq4_lsx(const uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst,
93                           int32_t iDstStride, const uint8_t *pABCD, int32_t iHeight) {
94   int32_t i;
95   int8_t iA, iB, iC, iD;
96   uint16_t iFillData;
97   int32_t iSrcStride_x2 = iSrcStride << 1;
98   int32_t iDstStride_x2 = iDstStride << 1;
99   __m128i paramAB, paramCD, paramConst;
100   __m128i src0, src1, src2, src0Even, src1Even, src2Even;
101   __m128i out0, outNext0, out1, outNext1;
102   __m128i shift;
103 
104   iA = pABCD[0];
105   iB = pABCD[1];
106   iC = pABCD[2];
107   iD = pABCD[3];
108 
109   iFillData = (iB << 8) | iA;
110   paramAB = __lsx_vreplgr2vr_h(iFillData);
111   iFillData = (iD << 8) | iC;
112   paramCD = __lsx_vreplgr2vr_h(iFillData);
113   paramConst = __lsx_vreplgr2vr_h(32);
114   shift = __lsx_vreplgr2vr_h(6);
115   iHeight = iHeight >> 1;
116 
117   for (i = 0; i < iHeight; i++) {
118     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0, src1);
119     src2 = __lsx_vld(pSrc + iSrcStride_x2, 0);
120     pSrc += 1;
121     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0Even, src1Even);
122     src2Even = __lsx_vld(pSrc + iSrcStride_x2, 0);
123     pSrc -= 1;
124 
125     DUP2_ARG2(__lsx_vilvl_w, src0Even, src0, src1Even, src1, src0, src1);
126     src2 = __lsx_vilvl_w(src2Even, src2);
127     DUP4_ARG2(__lsx_vdp2_h_bu, src0, paramAB, src1, paramCD, src1, paramAB, src2,
128               paramCD, out0, outNext0, out1, outNext1);
129     DUP4_ARG2(__lsx_vadd_h, out0, outNext0, out0, paramConst, out1, outNext1, out1,
130               paramConst, out0, out0, out1, out1);
131     DUP2_ARG2(__lsx_vsrl_h, out0, shift, out1, shift, out0, out1);
132     DUP2_ARG2(__lsx_vsrl_d, out0, paramConst, out1, paramConst, outNext0, outNext1);
133     DUP2_ARG2(__lsx_vpackev_b, outNext0, out0, outNext1, out1, out0, out1);
134     __lsx_vstelm_w(out0, pDst, 0, 0);
135     __lsx_vstelm_w(out1, pDst + iDstStride, 0, 0);
136 
137     pDst += iDstStride_x2;
138     pSrc += iSrcStride_x2;
139   }
140 }
141 
McChromaWidthEq8_lsx(const uint8_t * pSrc,int32_t iSrcStride,uint8_t * pDst,int32_t iDstStride,const uint8_t * pABCD,int32_t iHeight)142 void McChromaWidthEq8_lsx(const uint8_t *pSrc, int32_t iSrcStride, uint8_t *pDst,
143                           int32_t iDstStride, const uint8_t *pABCD, int32_t iHeight) {
144   int32_t i;
145   int8_t iA, iB, iC, iD;
146   uint16_t iFillData;
147   int32_t iSrcStride_x2 = iSrcStride << 1;
148   int32_t iDstStride_x2 = iDstStride << 1;
149   __m128i paramAB, paramCD, paramConst;
150   __m128i src0, src1, src2, src0Even, src1Even, src2Even;
151   __m128i out0, outNext0, out1, outNext1;
152   __m128i shift;
153 
154   iA = pABCD[0];
155   iB = pABCD[1];
156   iC = pABCD[2];
157   iD = pABCD[3];
158 
159   iFillData = (iB << 8) | iA;
160   paramAB = __lsx_vreplgr2vr_h(iFillData);
161   iFillData = (iD << 8) | iC;
162   paramCD = __lsx_vreplgr2vr_h(iFillData);
163   paramConst = __lsx_vreplgr2vr_h(32);
164   shift = __lsx_vreplgr2vr_h(6);
165   iHeight = iHeight >> 1;
166 
167   for (i = 0; i < iHeight; i++) {
168     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0, src1);
169     src2 = __lsx_vld(pSrc + iSrcStride_x2, 0);
170     pSrc += 1;
171     DUP2_ARG2(__lsx_vld, pSrc, 0, pSrc + iSrcStride, 0, src0Even, src1Even);
172     src2Even = __lsx_vld(pSrc + iSrcStride_x2, 0);
173     pSrc -= 1;
174 
175     DUP2_ARG2(__lsx_vilvl_d, src0Even, src0, src1Even, src1, src0, src1);
176     src2 = __lsx_vilvl_d(src2Even, src2);
177     DUP4_ARG2(__lsx_vdp2_h_bu, src0, paramAB, src1, paramCD, src1, paramAB, src2,
178               paramCD, out0, outNext0, out1, outNext1);
179     DUP4_ARG2(__lsx_vadd_h, out0, outNext0, out0, paramConst, out1, outNext1, out1,
180               paramConst, out0, out0, out1, out1);
181     DUP2_ARG2(__lsx_vsrl_h, out0, shift, out1, shift, out0, out1);
182 
183     DUP2_ARG2(__lsx_vilvh_d, out0, out0, out1, out1, outNext0, outNext1);
184     DUP2_ARG2(__lsx_vpackev_b, outNext0, out0, outNext1, out1, out0, out1);
185 
186     __lsx_vstelm_d(out0, pDst, 0, 0);
187     __lsx_vstelm_d(out1, pDst + iDstStride, 0, 0);
188 
189     pDst += iDstStride_x2;
190     pSrc += iSrcStride_x2;
191   }
192 }
193