summaryrefslogtreecommitdiffstats
path: root/encoder/x86/ih264e_half_pel_ssse3.c
blob: 8da73b7c9136b609354a2451b7eaa60ca63b493a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
/**
 *******************************************************************************
 * @file
 *  ih264e_half_pel_ssse3.c
 *
 * @brief
 *  Contains the x86 intrinsic function definitions for 6-tap vertical filter
 *  and cascaded 2D filter used in motion estimation in H264 encoder.
 *
 * @author
 *  Ittiam
 *
 * @par List of Functions:
 *  ih264e_sixtapfilter_horz_ssse3
 *  ih264e_sixtap_filter_2dvh_vert_ssse3
 *
 * @remarks
 *  None
 *
 *******************************************************************************
 */

/*****************************************************************************/
/* File Includes                                                             */
/*****************************************************************************/

/* System include files */
#include <stdio.h>
#include <assert.h>
#include <limits.h>

/* User include files */
#include "ih264_typedefs.h"
#include "ithread.h"
#include "ih264_platform_macros.h"
#include "ih264_defs.h"
#include "ih264e_half_pel.h"
#include "ih264_macros.h"
#include "ih264e_debug.h"
#include "ih264_inter_pred_filters.h"
#include "ih264_mem_fns.h"
#include "ih264_padding.h"
#include "ih264_intra_pred_filters.h"
#include "ih264_deblk_edge_filters.h"


/*****************************************************************************/
/* Function Definitions                                                      */
/*****************************************************************************/
/*
*******************************************************************************
*
* @brief
*  Interprediction luma filter for horizontal input(Filter run for width = 17
*  and height =16)
*
* @par Description:
*  Applies a 6 tap horizontal filter .The output is  clipped to 8 bits sec.
*  8.4.2.2.1 titled "Luma sample interpolation process"
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[out] pu1_dst
*  UWORD8 pointer to the destination
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] dst_strd
*  integer destination stride
*
* @returns
*  None
*
* @remarks
*  None
*
*******************************************************************************
*/
void ih264e_sixtapfilter_horz_ssse3(UWORD8 *pu1_src,
                                    UWORD8 *pu1_dst,
                                    WORD32 src_strd,
                                    WORD32 dst_strd)
{
    WORD32 ht;
    WORD32 tmp;

    __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
    __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;

    __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
    __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;

    __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
    __m128i const_val16_8x16b;

    ht = 16;
    pu1_src -= 2; // the filter input starts from x[-2] (till x[3])

    coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01); //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
    coeff2_3_16x8b = _mm_set1_epi32(0x14141414); //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
    coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB); //c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5
                                                 //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
    const_val16_8x16b = _mm_set1_epi16(16);

    //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
    //Row0 :                         b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
    //b0 is same a8. Similarly other bn pixels are same as a(n+8) pixels.

    do
    {
        src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                     //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
        src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));               //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15

        src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                      //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
        src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                      //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0

        src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
        src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8

        res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
                                                                                 //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
        res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
                                                                                 //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1

        src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
        src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0

        src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
        src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0

        src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
        src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10

        res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
                                                                                 //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
        res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);    //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
                                                                                 //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3

        src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
        src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b4 b5 b6 b7 b8 b9....b15 0  0  0  0

        src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a5 a6 a7 a8 a9....a15 0  0  0  0  0
        src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b5 b6 b7 b8 b9....b15 0  0  0  0  0

        src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
        src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12

        res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5  a6*c4+a7*c5   a7*c4+a8*c5
                                                                                 //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
        res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);    //b4*c4+b5*c5 b5*c4+b6*c5  b6*c4+b7*c5   b7*c4+b8*c5
                                                                                 //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
        res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
        res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
        res_r0_t3_8x16b = _mm_add_epi16(res_r0_t3_8x16b, const_val16_8x16b);
        res_r1_t3_8x16b = _mm_add_epi16(res_r1_t3_8x16b, const_val16_8x16b);
        res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
        res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);

        tmp = ((pu1_src[18] + pu1_src[19]) << 2) - pu1_src[17] - pu1_src[20];
        tmp = pu1_src[16] + pu1_src[21] + (tmp << 2) + tmp;

        res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);                    //shifting right by 5 bits.
        res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);
        tmp = (tmp + 16) >> 5;

        src_r0_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r1_t1_8x16b);
        pu1_dst[16] = CLIP_U8(tmp);

        _mm_storeu_si128((__m128i *)pu1_dst, src_r0_16x8b);

        ht--;
        pu1_src += src_strd;
        pu1_dst += dst_strd;
    }
    while(ht > 0);
}

/*
*******************************************************************************
*
* @brief
*   This function implements a two stage cascaded six tap filter. It
*    applies the six tap filter in the vertical direction on the
*    predictor values, followed by applying the same filter in the
*    horizontal direction on the output of the first stage. The six tap
*    filtering operation is described in sec 8.4.2.2.1 titled "Luma sample
*    interpolation process" (Filter run for width = 17 and height =17)
*
* @par Description:
*    The function interpolates the predictors first in the vertical direction
*    and then in the horizontal direction to output the (1/2,1/2). The output
*    of the first stage of the filter is stored in the buffer pointed to by
*    pi16_pred1(only in C) in 16 bit precision.
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[out] pu1_dst1
*  UWORD8 pointer to the destination(Vertical filtered output)
*
* @param[out] pu1_dst2
*  UWORD8 pointer to the destination(out put after applying horizontal filter
*  to the intermediate vertical output)
*
* @param[in] src_strd
*  integer source stride

* @param[in] dst_strd
*  integer destination stride of pu1_dst
*
* @param[in]pi16_pred1
*  Pointer to 16bit intermediate buffer(used only in c)
*
* @param[in] pi16_pred1_strd
*  integer destination stride of pi16_pred1
*
* @returns
*  None
*
* @remarks
*  None
*
*******************************************************************************
*/
void ih264e_sixtap_filter_2dvh_vert_ssse3(UWORD8 *pu1_src,
                                          UWORD8 *pu1_dst1,
                                          UWORD8 *pu1_dst2,
                                          WORD32 src_strd,
                                          WORD32 dst_strd,
                                          WORD32 *pi4_pred1,
                                          WORD32 pred1_strd)
{
    WORD32 ht;
    WORD16 *pi2_pred1;

    ht = 17;
    pi2_pred1 = (WORD16 *)pi4_pred1;
    pred1_strd = pred1_strd << 1;

    // Vertical 6-tap filter
    {
        __m128i src1_r0_16x8b, src1_r1_16x8b, src1_r2_16x8b;
        __m128i src1_r3_16x8b, src1_r4_16x8b, src1_r5_16x8b;
        __m128i src2_r0_16x8b, src2_r1_16x8b, src2_r2_16x8b;
        __m128i src2_r3_16x8b, src2_r4_16x8b, src2_r5_16x8b;

        __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;

        __m128i res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
        __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;

        coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01); //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
        coeff2_3_16x8b = _mm_set1_epi32(0x14141414); //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
        coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB); //c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5
                                                     //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20

        pu1_src -= 2;
        pu1_src -= src_strd << 1; // the filter input starts from x[-2] (till x[3])

        // Loading first five rows to start first row processing.
        // 22 values loaded in each row.
        src1_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
        src2_r0_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + 14));
        pu1_src += src_strd;

        src1_r1_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
        src2_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + 14));
        pu1_src += src_strd;

        src1_r2_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
        src2_r2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + 14));
        pu1_src += src_strd;

        src1_r3_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
        src2_r3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + 14));
        pu1_src += src_strd;

        src1_r4_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
        src2_r4_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + 14));
        pu1_src += src_strd;

        do
        {
            src1_r5_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
            src2_r5_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + 14));

            src_r0r1_16x8b = _mm_unpacklo_epi8(src1_r0_16x8b, src1_r1_16x8b);
            src_r2r3_16x8b = _mm_unpacklo_epi8(src1_r2_16x8b, src1_r3_16x8b);
            src_r4r5_16x8b = _mm_unpacklo_epi8(src1_r4_16x8b, src1_r5_16x8b);

            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);

            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
            res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);

            _mm_storeu_si128((__m128i *)pi2_pred1, res_t1_8x16b);

            src_r0r1_16x8b = _mm_unpackhi_epi8(src1_r0_16x8b, src1_r1_16x8b);
            src_r2r3_16x8b = _mm_unpackhi_epi8(src1_r2_16x8b, src1_r3_16x8b);
            src_r4r5_16x8b = _mm_unpackhi_epi8(src1_r4_16x8b, src1_r5_16x8b);

            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);

            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
            res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);

            _mm_storeu_si128((__m128i *)(pi2_pred1 + 8), res_t1_8x16b);

            src_r0r1_16x8b = _mm_unpacklo_epi8(src2_r0_16x8b, src2_r1_16x8b);
            src_r2r3_16x8b = _mm_unpacklo_epi8(src2_r2_16x8b, src2_r3_16x8b);
            src_r4r5_16x8b = _mm_unpacklo_epi8(src2_r4_16x8b, src2_r5_16x8b);

            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);

            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
            res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);

            _mm_storeu_si128((__m128i *)(pi2_pred1 + 14), res_t1_8x16b);

            src1_r0_16x8b = src1_r1_16x8b;
            src1_r1_16x8b = src1_r2_16x8b;
            src1_r2_16x8b = src1_r3_16x8b;
            src1_r3_16x8b = src1_r4_16x8b;
            src1_r4_16x8b = src1_r5_16x8b;

            src2_r0_16x8b = src2_r1_16x8b;
            src2_r1_16x8b = src2_r2_16x8b;
            src2_r2_16x8b = src2_r3_16x8b;
            src2_r3_16x8b = src2_r4_16x8b;
            src2_r4_16x8b = src2_r5_16x8b;

            ht--;
            pu1_src += src_strd;
            pi2_pred1 += pred1_strd;
        }
        while(ht > 0);
    }

    ht = 17;
    pi2_pred1 = (WORD16 *)pi4_pred1;

    // Horizontal 6-tap filter
    {
        WORD32 temp;

        __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b;
        __m128i src_r4_8x16b, src_r5_8x16b;
        __m128i src_r0r1_8x16b, src_r2r3_8x16b, src_r4r5_8x16b;
        __m128i res_vert1_8x16b, res_vert2_8x16b, res_16x8b;

        __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
        __m128i res_c0_8x16b, res_c1_8x16b;

        __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
        __m128i const_val512_4x32b, const_val16_8x16b;

        coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001); //c0 c1 c0 c1 c0 c1 c0 c1
        coeff2_3_8x16b = _mm_set1_epi32(0x00140014); //c2 c3 c2 c3 c2 c3 c2 c3
        coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB); //c4 c5 c4 c5 c4 c5 c4 c5
                                                     //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
        const_val512_4x32b = _mm_set1_epi32(512);
        const_val16_8x16b = _mm_set1_epi16(16);

        do
        {
            src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1));
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 1));
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 2));
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 3));
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 4));
            src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 5));

            res_vert1_8x16b = _mm_add_epi16(src_r2_8x16b, const_val16_8x16b);
            res_vert1_8x16b = _mm_srai_epi16(res_vert1_8x16b, 5); //shifting right by 5 bits.

            src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
            src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
            src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);

            res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
            res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
            res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);

            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
            res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
            res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);

            src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
            src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
            src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);

            res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
            res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
            res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);

            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
            res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
            res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);

            res_c0_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);

            src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 8));
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 8 + 1));
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 8 + 2));
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 8 + 3));
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 8 + 4));
            src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_pred1 + 8 + 5));

            res_vert2_8x16b = _mm_add_epi16(src_r2_8x16b, const_val16_8x16b);
            res_vert2_8x16b = _mm_srai_epi16(res_vert2_8x16b, 5); //shifting right by 5 bits.

            src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
            src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
            src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);

            res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
            res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
            res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);

            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
            res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
            res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b ,10);

            src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
            src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
            src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);

            res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
            res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
            res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);

            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
            res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
            res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
            res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);

            res_c1_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);

            res_16x8b = _mm_packus_epi16(res_vert1_8x16b, res_vert2_8x16b);
            _mm_storeu_si128((__m128i *)pu1_dst1, res_16x8b);
            pu1_dst1[16] = CLIP_U8((pi2_pred1[18] + 16) >> 5);

            res_16x8b = _mm_packus_epi16(res_c0_8x16b, res_c1_8x16b);
            _mm_storeu_si128((__m128i *)pu1_dst2, res_16x8b);
            temp = ((pi2_pred1[18] + pi2_pred1[19]) << 2) - pi2_pred1[17] - pi2_pred1[20];
            temp = pi2_pred1[16] + pi2_pred1[21] + (temp << 2) + temp;
            pu1_dst2[16] = CLIP_U8((temp + 512) >> 10);

            ht--;
            pi2_pred1 += pred1_strd;
            pu1_dst1 += dst_strd;
            pu1_dst2 += dst_strd;
        }
        while(ht > 0);
    }
}