summaryrefslogtreecommitdiffstats
path: root/common/armv8/ih264_weighted_bi_pred_av8.s
blob: 96ef50a09e4240405b2e6853571c28de0f59fac2 (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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
//******************************************************************************
//*
//* 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
//*  ih264_weighted_bi_pred_av8.s
//*
//* @brief
//*  Contains function definitions for weighted biprediction.
//*
//* @author
//*  Kaushik Senthoor R
//*
//* @par List of Functions:
//*
//*  - ih264_weighted_bi_pred_luma_av8()
//*  - ih264_weighted_bi_pred_chroma_av8()
//*
//* @remarks
//*  None
//*
//*******************************************************************************
//*/
//*******************************************************************************
//* @function
//*  ih264_weighted_bi_pred_luma_av8()
//*
//* @brief
//*  This routine performs the default weighted prediction as described in sec
//* 8.4.2.3.2 titled "Weighted sample prediction process" for luma.
//*
//* @par Description:
//*  This function gets two ht x wd blocks, calculates the weighted samples,
//* rounds off, adds offset and stores it in the destination block.
//*
//* @param[in] puc_src1
//*  UWORD8 Pointer to the buffer containing the input block 1.
//*
//* @param[in] puc_src2
//*  UWORD8 Pointer to the buffer containing the input block 2.
//*
//* @param[out] puc_dst
//*  UWORD8 pointer to the destination where the output block is stored.
//*
//* @param[in] src_strd1
//*  Stride of the input buffer 1
//*
//* @param[in] src_strd2
//*  Stride of the input buffer 2
//*
//* @param[in] dst_strd
//*  Stride of the destination buffer
//*
//* @param[in] log_WD
//*  number of bits to be rounded off
//*
//* @param[in] wt1
//*  weight for the weighted prediction
//*
//* @param[in] wt2
//*  weight for the weighted prediction
//*
//* @param[in] ofst1
//*  offset 1 used after rounding off
//*
//* @param[in] ofst2
//*  offset 2 used after rounding off
//*
//* @param[in] ht
//*  integer height of the array
//*
//* @param[in] wd
//*  integer width of the array
//*
//* @returns
//*  None
//*
//* @remarks
//*  (ht,wd) can be (4,4), (4,8), (8,4), (8,8), (8,16), (16,8) or (16,16).
//*
//*******************************************************************************
//*/
//void ih264_weighted_bi_pred_luma_av8(UWORD8 *puc_src1,
//                                     UWORD8 *puc_src2,
//                                     UWORD8 *puc_dst,
//                                     WORD32 src_strd1,
//                                     WORD32 src_strd2,
//                                     WORD32 dst_strd,
//                                     UWORD16 log_WD,
//                                     UWORD32 wt1,
//                                     UWORD32 wt2,
//                                     UWORD16 ofst1,
//                                     UWORD16 ofst2,
//                                     UWORD8 ht,
//                                     UWORD8 wd)
//
//**************Variables Vs Registers*****************************************
//    x0      => puc_src1
//    x1      => puc_src2
//    x2      => puc_dst
//    x3      => src_strd1
//    [sp]    => src_strd2 (x4)
//    [sp+4]  => dst_strd  (x5)
//    [sp+8]  => log_WD    (x6)
//    [sp+12] => wt1       (x7)
//   [sp+16] => wt2       (x8)
//   [sp+20] => ofst1     (x9)
//   [sp+24] => ofst2     (x10)
//    [sp+28] => ht        (x11)
//    [sp+32] => wd        (x12)
//
.text
.p2align 2
.include "ih264_neon_macros.s"



    .global ih264_weighted_bi_pred_luma_av8

ih264_weighted_bi_pred_luma_av8:

    // STMFD sp!, {x4-x12,x14}                //stack stores the values of the arguments
    push_v_regs
    stp       x19, x20, [sp, #-16]!
    ldr       x8, [sp, #80]             //Load wt2 in x8
    ldr       x9, [sp, #88]             //Load ofst1 in x9
    add       x6, x6, #1                //x6  = log_WD + 1
    sub       x20, x6, #0               //x13 = -(log_WD + 1)
    neg       x10, x20
    dup       v0.8h, w10                //Q0  = -(log_WD + 1) (32-bit)
    ldr       x10, [sp, #96]            //Load ofst2 in x10
    ldr       x11, [sp, #104]           //Load ht in x11
    ldr       x12, [sp, #112]           //Load wd in x12
    add       x9, x9, #1                //x9 = ofst1 + 1
    add       x9, x9, x10               //x9 = ofst1 + ofst2 + 1
    mov       v2.s[0], w7
    mov       v2.s[1], w8               //D2 = {wt1(32-bit), wt2(32-bit)}
    asr       x9, x9, #1                //x9 = ofst = (ofst1 + ofst2 + 1) >> 1
    dup       v3.8b, w9                 //D3 = ofst (8-bit)
    cmp       w12, #16
    beq       loop_16                   //branch if wd is 16
    cmp       w12, #8                   //check if wd is 8
    beq       loop_8                    //branch if wd is 8

loop_4:                                 //each iteration processes four rows

    ld1       {v4.s}[0], [x0], x3       //load row 1 in source 1
    ld1       {v4.s}[1], [x0], x3       //load row 2 in source 1
    ld1       {v6.s}[0], [x1], x4       //load row 1 in source 2
    ld1       {v6.s}[1], [x1], x4       //load row 2 in source 2
    uxtl      v4.8h, v4.8b              //converting rows 1,2 in source 1 to 16-bit
    ld1       {v8.s}[0], [x0], x3       //load row 3 in source 1
    ld1       {v8.s}[1], [x0], x3       //load row 4 in source 1
    uxtl      v6.8h, v6.8b              //converting rows 1,2 in source 2 to 16-bit
    ld1       {v10.s}[0], [x1], x4      //load row 3 in source 2
    ld1       {v10.s}[1], [x1], x4      //load row 4 in source 2
    uxtl      v8.8h, v8.8b              //converting rows 3,4 in source 1 to 16-bit
    uxtl      v10.8h, v10.8b            //converting rows 3,4 in source 2 to 16-bit
    mul       v4.8h, v4.8h , v2.4h[0]   //weight 1 mult. for rows 1,2
    mla       v4.8h, v6.8h , v2.4h[2]   //weight 2 mult. for rows 1,2
    mul       v8.8h, v8.8h , v2.4h[0]   //weight 1 mult. for rows 3,4
    mla       v8.8h, v10.8h , v2.4h[2]  //weight 2 mult. for rows 3,4
    subs      w11, w11, #4              //decrement ht by 4
    srshl     v4.8h, v4.8h , v0.8h      //rounds off the weighted samples from rows 1,2
    srshl     v8.8h, v8.8h , v0.8h      //rounds off the weighted samples from rows 3,4
    saddw     v4.8h, v4.8h , v3.8b      //adding offset for rows 1,2
    saddw     v8.8h, v8.8h , v3.8b      //adding offset for rows 3,4
    sqxtun    v4.8b, v4.8h              //saturating rows 1,2 to unsigned 8-bit
    sqxtun    v8.8b, v8.8h              //saturating rows 3,4 to unsigned 8-bit
    st1       {v4.s}[0], [x2], x5       //store row 1 in destination
    st1       {v4.s}[1], [x2], x5       //store row 2 in destination
    st1       {v8.s}[0], [x2], x5       //store row 3 in destination
    st1       {v8.s}[1], [x2], x5       //store row 4 in destination
    bgt       loop_4                    //if greater than 0 repeat the loop again
    b         end_loops

loop_8:                                 //each iteration processes four rows

    ld1       {v4.8b}, [x0], x3         //load row 1 in source 1
    ld1       {v6.8b}, [x1], x4         //load row 1 in source 2
    ld1       {v8.8b}, [x0], x3         //load row 2 in source 1
    ld1       {v10.8b}, [x1], x4        //load row 2 in source 2
    uxtl      v4.8h, v4.8b              //converting row 1 in source 1 to 16-bit
    ld1       {v12.8b}, [x0], x3        //load row 3 in source 1
    ld1       {v14.8b}, [x1], x4        //load row 3 in source 2
    uxtl      v6.8h, v6.8b              //converting row 1 in source 2 to 16-bit
    ld1       {v16.8b}, [x0], x3        //load row 4 in source 1
    ld1       {v18.8b}, [x1], x4        //load row 4 in source 2
    uxtl      v8.8h, v8.8b              //converting row 2 in source 1 to 16-bit
    uxtl      v10.8h, v10.8b            //converting row 2 in source 2 to 16-bit
    mul       v4.8h, v4.8h , v2.4h[0]   //weight 1 mult. for row 1
    mla       v4.8h, v6.8h , v2.4h[2]   //weight 2 mult. for row 1
    uxtl      v12.8h, v12.8b            //converting row 3 in source 1 to 16-bit
    uxtl      v14.8h, v14.8b            //converting row 3 in source 2 to 16-bit
    mul       v8.8h, v8.8h , v2.4h[0]   //weight 1 mult. for row 2
    mla       v8.8h, v10.8h , v2.4h[2]  //weight 2 mult. for row 2
    uxtl      v16.8h, v16.8b            //converting row 4 in source 1 to 16-bit
    uxtl      v18.8h, v18.8b            //converting row 4 in source 2 to 16-bit
    mul       v12.8h, v12.8h , v2.4h[0] //weight 1 mult. for row 3
    mla       v12.8h, v14.8h , v2.4h[2] //weight 2 mult. for row 3
    mul       v16.8h, v16.8h , v2.4h[0] //weight 1 mult. for row 4
    mla       v16.8h, v18.8h , v2.4h[2] //weight 2 mult. for row 4
    srshl     v4.8h, v4.8h , v0.8h      //rounds off the weighted samples from row 1
    srshl     v8.8h, v8.8h , v0.8h      //rounds off the weighted samples from row 2
    srshl     v12.8h, v12.8h , v0.8h    //rounds off the weighted samples from row 3
    saddw     v4.8h, v4.8h , v3.8b      //adding offset for row 1
    srshl     v16.8h, v16.8h , v0.8h    //rounds off the weighted samples from row 4
    saddw     v8.8h, v8.8h , v3.8b      //adding offset for row 2
    saddw     v12.8h, v12.8h , v3.8b    //adding offset for row 3
    sqxtun    v4.8b, v4.8h              //saturating row 1 to unsigned 8-bit
    saddw     v16.8h, v16.8h , v3.8b    //adding offset for row 4
    sqxtun    v8.8b, v8.8h              //saturating row 2 to unsigned 8-bit
    sqxtun    v12.8b, v12.8h            //saturating row 3 to unsigned 8-bit
    sqxtun    v16.8b, v16.8h            //saturating row 4 to unsigned 8-bit
    st1       {v4.8b}, [x2], x5         //store row 1 in destination
    st1       {v8.8b}, [x2], x5         //store row 2 in destination
    subs      w11, w11, #4              //decrement ht by 4
    st1       {v12.8b}, [x2], x5        //store row 3 in destination
    st1       {v16.8b}, [x2], x5        //store row 4 in destination
    bgt       loop_8                    //if greater than 0 repeat the loop again
    b         end_loops

loop_16:                                //each iteration processes two rows

    ld1       {v4.8b, v5.8b}, [x0], x3  //load row 1 in source 1
    ld1       {v6.8b, v7.8b}, [x1], x4  //load row 1 in source 2
    ld1       {v8.8b, v9.8b}, [x0], x3  //load row 2 in source 1
    ld1       {v10.8b, v11.8b}, [x1], x4 //load row 2 in source 2
    uxtl      v20.8h, v4.8b             //converting row 1L in source 1 to 16-bit
    ld1       {v12.8b, v13.8b}, [x0], x3 //load row 3 in source 1
    ld1       {v14.8b, v15.8b}, [x1], x4 //load row 3 in source 2
    uxtl      v22.8h, v6.8b             //converting row 1L in source 2 to 16-bit
    ld1       {v16.8b, v17.8b}, [x0], x3 //load row 4 in source 1
    ld1       {v18.8b, v19.8b}, [x1], x4 //load row 4 in source 2
    uxtl      v4.8h, v5.8b              //converting row 1H in source 1 to 16-bit
    uxtl      v6.8h, v7.8b              //converting row 1H in source 2 to 16-bit
    mul       v20.8h, v20.8h , v2.4h[0] //weight 1 mult. for row 1L
    mla       v20.8h, v22.8h , v2.4h[2] //weight 2 mult. for row 1L
    uxtl      v24.8h, v8.8b             //converting row 2L in source 1 to 16-bit
    uxtl      v26.8h, v10.8b            //converting row 2L in source 2 to 16-bit
    mul       v4.8h, v4.8h , v2.4h[0]   //weight 1 mult. for row 1H
    mla       v4.8h, v6.8h , v2.4h[2]   //weight 2 mult. for row 1H
    uxtl      v8.8h, v9.8b              //converting row 2H in source 1 to 16-bit
    uxtl      v10.8h, v11.8b            //converting row 2H in source 2 to 16-bit
    mul       v24.8h, v24.8h , v2.4h[0] //weight 1 mult. for row 2L
    mla       v24.8h, v26.8h , v2.4h[2] //weight 2 mult. for row 2L
    uxtl      v28.8h, v12.8b            //converting row 3L in source 1 to 16-bit
    uxtl      v30.8h, v14.8b            //converting row 3L in source 2 to 16-bit
    mul       v8.8h, v8.8h , v2.4h[0]   //weight 1 mult. for row 2H
    mla       v8.8h, v10.8h , v2.4h[2]  //weight 2 mult. for row 2H
    uxtl      v12.8h, v13.8b            //converting row 3H in source 1 to 16-bit
    uxtl      v14.8h, v15.8b            //converting row 3H in source 2 to 16-bit
    mul       v28.8h, v28.8h , v2.4h[0] //weight 1 mult. for row 3L
    mla       v28.8h, v30.8h , v2.4h[2] //weight 2 mult. for row 3L
    uxtl      v22.8h, v16.8b            //converting row 4L in source 1 to 16-bit
    uxtl      v6.8h, v18.8b             //converting row 4L in source 2 to 16-bit
    mul       v12.8h, v12.8h , v2.4h[0] //weight 1 mult. for row 3H
    mla       v12.8h, v14.8h , v2.4h[2] //weight 2 mult. for row 3H
    uxtl      v16.8h, v17.8b            //converting row 4H in source 1 to 16-bit
    uxtl      v18.8h, v19.8b            //converting row 4H in source 2 to 16-bit
    mul       v22.8h, v22.8h , v2.4h[0] //weight 1 mult. for row 4L
    mla       v22.8h, v6.8h , v2.4h[2]  //weight 2 mult. for row 4L
    srshl     v20.8h, v20.8h , v0.8h    //rounds off the weighted samples from row 1L
    mul       v16.8h, v16.8h , v2.4h[0] //weight 1 mult. for row 4H
    mla       v16.8h, v18.8h , v2.4h[2] //weight 2 mult. for row 4H
    srshl     v4.8h, v4.8h , v0.8h      //rounds off the weighted samples from row 1H
    srshl     v24.8h, v24.8h , v0.8h    //rounds off the weighted samples from row 2L
    saddw     v20.8h, v20.8h , v3.8b    //adding offset for row 1L
    srshl     v8.8h, v8.8h , v0.8h      //rounds off the weighted samples from row 2H
    saddw     v4.8h, v4.8h , v3.8b      //adding offset for row 1H
    srshl     v28.8h, v28.8h , v0.8h    //rounds off the weighted samples from row 3L
    saddw     v24.8h, v24.8h , v3.8b    //adding offset for row 2L
    srshl     v12.8h, v12.8h , v0.8h    //rounds off the weighted samples from row 3H
    saddw     v8.8h, v8.8h , v3.8b      //adding offset for row 2H
    srshl     v22.8h, v22.8h , v0.8h    //rounds off the weighted samples from row 4L
    saddw     v28.8h, v28.8h , v3.8b    //adding offset for row 3L
    srshl     v16.8h, v16.8h , v0.8h    //rounds off the weighted samples from row 4H
    saddw     v12.8h, v12.8h , v3.8b    //adding offset for row 3H
    sqxtun    v26.8b, v20.8h            //saturating row 1L to unsigned 8-bit
    saddw     v22.8h, v22.8h , v3.8b    //adding offset for row 4L
    sqxtun    v27.8b, v4.8h             //saturating row 1H to unsigned 8-bit
    saddw     v16.8h, v16.8h , v3.8b    //adding offset for row 4H
    sqxtun    v10.8b, v24.8h            //saturating row 2L to unsigned 8-bit
    sqxtun    v11.8b, v8.8h             //saturating row 2H to unsigned 8-bit
    sqxtun    v30.8b, v28.8h            //saturating row 3L to unsigned 8-bit
    sqxtun    v31.8b, v12.8h            //saturating row 3H to unsigned 8-bit
    st1       {v26.8b, v27.8b}, [x2], x5 //store row 1 in destination
    sqxtun    v14.8b, v22.8h            //saturating row 4L to unsigned 8-bit
    sqxtun    v15.8b, v16.8h            //saturating row 4H to unsigned 8-bit
    st1       {v10.8b, v11.8b}, [x2], x5 //store row 2 in destination
    subs      w11, w11, #4              //decrement ht by 4
    st1       {v30.8b, v31.8b}, [x2], x5 //store row 3 in destination
    st1       {v14.8b, v15.8b}, [x2], x5 //store row 4 in destination
    bgt       loop_16                   //if greater than 0 repeat the loop again

end_loops:

    // LDMFD sp!,{x4-x12,x15}                //Reload the registers from sp
    ldp       x19, x20, [sp], #16
    pop_v_regs
    ret


//*******************************************************************************
//* @function
//*  ih264_weighted_bi_pred_chroma_av8()
//*
//* @brief
//*  This routine performs the default weighted prediction as described in sec
//* 8.4.2.3.2 titled "Weighted sample prediction process" for chroma.
//*
//* @par Description:
//*  This function gets two ht x wd blocks, calculates the weighted samples,
//* rounds off, adds offset and stores it in the destination block for U and V.
//*
//* @param[in] puc_src1
//*  UWORD8 Pointer to the buffer containing the input block 1.
//*
//* @param[in] puc_src2
//*  UWORD8 Pointer to the buffer containing the input block 2.
//*
//* @param[out] puc_dst
//*  UWORD8 pointer to the destination where the output block is stored.
//*
//* @param[in] src_strd1
//*  Stride of the input buffer 1
//*
//* @param[in] src_strd2
//*  Stride of the input buffer 2
//*
//* @param[in] dst_strd
//*  Stride of the destination buffer
//*
//* @param[in] log_WD
//*  number of bits to be rounded off
//*
//* @param[in] wt1
//*  weights for the weighted prediction in U and V
//*
//* @param[in] wt2
//*  weights for the weighted prediction in U and V
//*
//* @param[in] ofst1
//*  offset 1 used after rounding off for U an dV
//*
//* @param[in] ofst2
//*  offset 2 used after rounding off for U and V
//*
//* @param[in] ht
//*  integer height of the array
//*
//* @param[in] wd
//*  integer width of the array
//*
//* @returns
//*  None
//*
//* @remarks
//*  (ht,wd) can be (2,2), (2,4), (4,2), (4,4), (4,8), (8,4) or (8,8).
//*
//*******************************************************************************
//*/
//void ih264_weighted_bi_pred_chroma_av8(UWORD8 *puc_src1,
//                                       UWORD8 *puc_src2,
//                                       UWORD8 *puc_dst,
//                                       WORD32 src_strd1,
//                                       WORD32 src_strd2,
//                                       WORD32 dst_strd,
//                                       UWORD16 log_WD,
//                                       UWORD32 wt1,
//                                       UWORD32 wt2,
//                                       UWORD16 ofst1,
//                                       UWORD16 ofst2,
//                                       UWORD8 ht,
//                                       UWORD8 wd)
//
//**************Variables Vs Registers*****************************************
//    x0      => puc_src1
//    x1      => puc_src2
//    x2      => puc_dst
//    x3      => src_strd1
//    [sp]    => src_strd2 (x4)
//    [sp+4]  => dst_strd  (x5)
//    [sp+8]  => log_WD    (x6)
//    [sp+12] => wt1       (x7)
//   [sp+16] => wt2       (x8)
//   [sp+20] => ofst1     (x9)
//   [sp+24] => ofst2     (x10)
//    [sp+28] => ht        (x11)
//    [sp+32] => wd        (x12)
//





    .global ih264_weighted_bi_pred_chroma_av8

ih264_weighted_bi_pred_chroma_av8:

    // STMFD sp!, {x4-x12,x14}                //stack stores the values of the arguments
    push_v_regs
    stp       x19, x20, [sp, #-16]!


    ldr       x8, [sp, #80]             //Load wt2 in x8
    dup       v4.4s, w8                 //Q2 = (wt2_u, wt2_v) (32-bit)
    dup       v2.4s, w7                 //Q1 = (wt1_u, wt1_v) (32-bit)
    add       x6, x6, #1                //x6  = log_WD + 1
    ldr       w9, [sp, #88]             //Load ofst1 in x9
    sxtw      x9, w9
    ldr       w10, [sp, #96]            //Load ofst2 in x10
    sxtw      x10, w10
    sub       x20, x6, #0               //x12 = -(log_WD + 1)
    neg       x20, x20
    dup       v0.8h, w20                //Q0  = -(log_WD + 1) (16-bit)
    ldr       w11, [sp, #104]           //Load ht in x11
    ldr       w12, [sp, #112]           //Load wd in x12
    sxtw      x11, w11
    sxtw      x12, w12
    dup       v20.8h, w9                //0ffset1
    dup       v21.8h, w10               //0ffset2
    srhadd    v6.8b, v20.8b, v21.8b
    sxtl      v6.8h, v6.8b
    cmp       w12, #8                   //check if wd is 8
    beq       loop_8_uv                 //branch if wd is 8
    cmp       w12, #4                   //check if wd is 4
    beq       loop_4_uv                 //branch if wd is 4

loop_2_uv:                              //each iteration processes two rows

    ld1       {v8.s}[0], [x0], x3       //load row 1 in source 1
    ld1       {v8.s}[1], [x0], x3       //load row 2 in source 1
    ld1       {v10.s}[0], [x1], x4      //load row 1 in source 2
    ld1       {v10.s}[1], [x1], x4      //load row 2 in source 2
    uxtl      v8.8h, v8.8b              //converting rows 1,2 in source 1 to 16-bit
    uxtl      v10.8h, v10.8b            //converting rows 1,2 in source 2 to 16-bit
    mul       v8.8h, v8.8h , v2.8h      //weight 1 mult. for rows 1,2
    mla       v8.8h, v10.8h , v4.8h     //weight 2 mult. for rows 1,2
    srshl     v8.8h, v8.8h , v0.8h      //rounds off the weighted samples from rows 1,2
    add       v8.8h, v8.8h , v6.8h      //adding offset for rows 1,2
    sqxtun    v8.8b, v8.8h              //saturating rows 1,2 to unsigned 8-bit/
    st1       {v8.s}[0], [x2], x5       //store row 1 in destination
    st1       {v8.s}[1], [x2], x5       //store row 2 in destination
    subs      w11, w11, #2              //decrement ht by 2
    bgt       loop_2_uv                 //if greater than 0 repeat the loop again
    b         end_loops_uv

loop_4_uv:                              //each iteration processes two rows

    ld1       {v8.8b}, [x0], x3         //load row 1 in source 1
    ld1       {v10.8b}, [x1], x4        //load row 1 in source 2
    uxtl      v8.8h, v8.8b              //converting row 1 in source 1 to 16-bit
    ld1       {v12.8b}, [x0], x3        //load row 2 in source 1
    uxtl      v10.8h, v10.8b            //converting row 1 in source 2 to 16-bit
    ld1       {v14.8b}, [x1], x4        //load row 2 in source 2
    uxtl      v12.8h, v12.8b            //converting row 2 in source 1 to 16-bit
    mul       v8.8h, v8.8h , v2.8h      //weight 1 mult. for row 1
    mla       v8.8h, v10.8h , v4.8h     //weight 2 mult. for row 1
    uxtl      v14.8h, v14.8b            //converting row 2 in source 2 to 16-bit
    mul       v12.8h, v12.8h , v2.8h    //weight 1 mult. for row 2
    mla       v12.8h, v14.8h , v4.8h    //weight 2 mult. for row 2
    subs      w11, w11, #2              //decrement ht by 2
    srshl     v8.8h, v8.8h , v0.8h      //rounds off the weighted samples from row 1
    srshl     v12.8h, v12.8h , v0.8h    //rounds off the weighted samples from row 2
    add       v8.8h, v8.8h , v6.8h      //adding offset for row 1
    add       v12.8h, v12.8h , v6.8h    //adding offset for row 2
    sqxtun    v8.8b, v8.8h              //saturating row 1 to unsigned 8-bit
    sqxtun    v12.8b, v12.8h            //saturating row 2 to unsigned 8-bit
    st1       {v8.8b}, [x2], x5         //store row 1 in destination
    st1       {v12.8b}, [x2], x5        //store row 2 in destination
    bgt       loop_4_uv                 //if greater than 0 repeat the loop again
    b         end_loops_uv

loop_8_uv:                              //each iteration processes two rows

    ld1       {v8.8b, v9.8b}, [x0], x3  //load row 1 in source 1
    ld1       {v10.8b, v11.8b}, [x1], x4 //load row 1 in source 2
    ld1       {v12.8b, v13.8b}, [x0], x3 //load row 2 in source 1
    ld1       {v14.8b, v15.8b}, [x1], x4 //load row 2 in source 2
    uxtl      v24.8h, v8.8b             //converting row 1L in source 1 to 16-bit
    ld1       {v16.8b, v17.8b}, [x0], x3 //load row 3 in source 1
    ld1       {v18.8b, v19.8b}, [x1], x4 //load row 3 in source 2
    uxtl      v26.8h, v10.8b            //converting row 1L in source 2 to 16-bit
    ld1       {v20.8b, v21.8b}, [x0], x3 //load row 4 in source 1
    ld1       {v22.8b, v23.8b}, [x1], x4 //load row 4 in source 2
    uxtl      v8.8h, v9.8b              //converting row 1H in source 1 to 16-bit
    uxtl      v10.8h, v11.8b            //converting row 1H in source 2 to 16-bit
    mul       v24.8h, v24.8h , v2.8h    //weight 1 mult. for row 1L
    mla       v24.8h, v26.8h , v4.8h    //weight 2 mult. for row 1L
    uxtl      v28.8h, v12.8b            //converting row 2L in source 1 to 16-bit
    uxtl      v30.8h, v14.8b            //converting row 2L in source 2 to 16-bit
    mul       v8.8h, v8.8h , v2.8h      //weight 1 mult. for row 1H
    mla       v8.8h, v10.8h , v4.8h     //weight 2 mult. for row 1H
    uxtl      v12.8h, v13.8b            //converting row 2H in source 1 to 16-bit
    uxtl      v14.8h, v15.8b            //converting row 2H in source 2 to 16-bit
    mul       v28.8h, v28.8h , v2.8h    //weight 1 mult. for row 2L
    mla       v28.8h, v30.8h , v4.8h    //weight 2 mult. for row 2L
    uxtl      v26.8h, v16.8b            //converting row 3L in source 1 to 16-bit
    uxtl      v10.8h, v18.8b            //converting row 3L in source 2 to 16-bit
    mul       v12.8h, v12.8h , v2.8h    //weight 1 mult. for row 2H
    mla       v12.8h, v14.8h , v4.8h    //weight 2 mult. for row 2H
    uxtl      v16.8h, v17.8b            //converting row 3H in source 1 to 16-bit
    uxtl      v18.8h, v19.8b            //converting row 3H in source 2 to 16-bit
    mul       v26.8h, v26.8h , v2.8h    //weight 1 mult. for row 3L
    mla       v26.8h, v10.8h , v4.8h    //weight 2 mult. for row 3L
    uxtl      v30.8h, v20.8b            //converting row 4L in source 1 to 16-bit
    uxtl      v14.8h, v22.8b            //converting row 4L in source 2 to 16-bit
    mul       v16.8h, v16.8h , v2.8h    //weight 1 mult. for row 3H
    mla       v16.8h, v18.8h , v4.8h    //weight 2 mult. for row 3H
    uxtl      v20.8h, v21.8b            //converting row 4H in source 1 to 16-bit
    uxtl      v22.8h, v23.8b            //converting row 4H in source 2 to 16-bit
    mul       v30.8h, v30.8h , v2.8h    //weight 1 mult. for row 4L
    mla       v30.8h, v14.8h , v4.8h    //weight 2 mult. for row 4L
    srshl     v24.8h, v24.8h , v0.8h    //rounds off the weighted samples from row 1L
    mul       v20.8h, v20.8h , v2.8h    //weight 1 mult. for row 4H
    mla       v20.8h, v22.8h , v4.8h    //weight 2 mult. for row 4H
    srshl     v8.8h, v8.8h , v0.8h      //rounds off the weighted samples from row 1H
    srshl     v28.8h, v28.8h , v0.8h    //rounds off the weighted samples from row 2L
    add       v24.8h, v24.8h , v6.8h    //adding offset for row 1L
    srshl     v12.8h, v12.8h , v0.8h    //rounds off the weighted samples from row 2H
    add       v8.8h, v8.8h , v6.8h      //adding offset for row 1H
    srshl     v26.8h, v26.8h , v0.8h    //rounds off the weighted samples from row 3L
    add       v28.8h, v28.8h , v6.8h    //adding offset for row 2L
    srshl     v16.8h, v16.8h , v0.8h    //rounds off the weighted samples from row 3H
    add       v12.8h, v12.8h , v6.8h    //adding offset for row 2H
    srshl     v30.8h, v30.8h , v0.8h    //rounds off the weighted samples from row 4L
    add       v26.8h, v26.8h , v6.8h    //adding offset for row 3L
    srshl     v20.8h, v20.8h , v0.8h    //rounds off the weighted samples from row 4H
    add       v16.8h, v16.8h , v6.8h    //adding offset for row 3H
    sqxtun    v10.8b, v24.8h            //saturating row 1L to unsigned 8-bit
    add       v30.8h, v30.8h , v6.8h    //adding offset for row 4L
    sqxtun    v11.8b, v8.8h             //saturating row 1H to unsigned 8-bit
    add       v20.8h, v20.8h , v6.8h    //adding offset for row 4H
    sqxtun    v18.8b, v28.8h            //saturating row 2L to unsigned 8-bit
    sqxtun    v19.8b, v12.8h            //saturating row 2H to unsigned 8-bit
    sqxtun    v14.8b, v26.8h            //saturating row 3L to unsigned 8-bit
    sqxtun    v15.8b, v16.8h            //saturating row 3H to unsigned 8-bit
    st1       {v10.8b, v11.8b}, [x2], x5 //store row 1 in destination
    sqxtun    v22.8b, v30.8h            //saturating row 4L to unsigned 8-bit
    sqxtun    v23.8b, v20.8h            //saturating row 4H to unsigned 8-bit
    st1       {v18.8b, v19.8b}, [x2], x5 //store row 2 in destination
    subs      w11, w11, #4              //decrement ht by 4
    st1       {v14.8b, v15.8b}, [x2], x5 //store row 3 in destination
    st1       {v22.8b, v23.8b}, [x2], x5 //store row 4 in destination
    bgt       loop_8_uv                 //if greater than 0 repeat the loop again

end_loops_uv:

    // LDMFD sp!,{x4-x12,x15}                //Reload the registers from sp
    ldp       x19, x20, [sp], #16
    pop_v_regs
    ret