summaryrefslogtreecommitdiffstats
path: root/common/arm64/ihevc_weighted_pred_bi_default.s
blob: d98e0250a05def1ea987f4161bb9307c03b08fbc (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
///*****************************************************************************
//*
//* Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
//*
//* 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.
//*
//*****************************************************************************/
///**
//*******************************************************************************
//* @file
//*  ihevc_weighted_pred_bi_default.s
//*
//* @brief
//*  contains function definitions for weighted prediction used in inter
//* prediction
//*
//* @author
//*  parthiban v
//*
//* @par list of functions:
//*  - ihevc_weighted_pred_bi_default()
//*
//* @remarks
//*  none
//*
//*******************************************************************************
//*/
///**
//*******************************************************************************
//*
//* @brief
//*  does default bi-weighted prediction on the arrays pointed by pi2_src1 and
//* pi2_src2 and stores it at location  pointed by pi2_dst assumptions : the
//* function is optimized considering the fact width and  height are multiple
//* of 2.
//*
//* @par description:
//*  dst = ( (src1 + lvl_shift1) +  (src2 + lvl_shift2) +  1 << (shift - 1) )
//* >> shift  where shift = 15 - bitdepth
//*
//* @param[in] pi2_src1
//*  pointer to source 1
//*
//* @param[in] pi2_src2
//*  pointer to source 2
//*
//* @param[out] pu1_dst
//*  pointer to destination
//*
//* @param[in] src_strd1
//*  source stride 1
//*
//* @param[in] src_strd2
//*  source stride 2
//*
//* @param[in] dst_strd
//*  destination stride
//*
//* @param[in] lvl_shift1
//*  added before shift and offset
//*
//* @param[in] lvl_shift2
//*  added before shift and offset
//*
//* @param[in] ht
//*  height of the source
//*
//* @param[in] wd
//*  width of the source
//*
//* @returns
//*
//* @remarks
//*  none
//*
//*******************************************************************************
//*/
//void ihevc_weighted_pred_bi_default(word16 *pi2_src1,
//                                    word16 *pi2_src2,
//                                    uword8 *pu1_dst,
//                                    word32 src_strd1,
//                                    word32 src_strd2,
//                                    word32 dst_strd,
//                                    word32 lvl_shift1,
//                                    word32 lvl_shift2,
//                                    word32 ht,
//                                    word32 wd)

//**************variables vs registers*****************************************
//    x0 => *pi2_src1
//    x1 => *pi2_src2
//    x2 => *pu1_dst
//    x3 =>  src_strd1
//    x4 =>  src_strd2
//    x5 =>  dst_strd
//    x6 =>  lvl_shift1
//    x7 =>  lvl_shift2
//    x8 =>  ht
//    x9 =>  wd
.text
.align 4

.include "ihevc_neon_macros.s"

.globl ihevc_weighted_pred_bi_default_av8

.type ihevc_weighted_pred_bi_default_av8, %function

ihevc_weighted_pred_bi_default_av8:

    ldr         w8,[sp,#0]
    ldr         w9,[sp,#8]

    // stmfd sp!, {x4-x12, x14}                //stack stores the values of the arguments

    stp         x19, x20,[sp,#-16]!
    stp         x21, x22,[sp,#-16]!

    mov         x15,x4 // src_strd2 40
    mov         x16,x5 // dst_strd 44
    mov         x17,x6 // lvl_shift1 48
    mov         x19,x7 // lvl_shift2 52
    mov         x20,x8 // ht 56
    mov         x21,x9 // wd 60

    mov         x4,x15                      //load src_strd2
    lsl         x3,x3,#1
    mov         x5,x16                      //load dst_strd
    mov         x6,x17                      //load lvl_shift1
    lsl         x4,x4,#1
    mov         x7,x19                      //load lvl_shift2
    mov         x8,x20                      //load ht
    mov         x9,x21                      //load wd
    dup         v4.8h,w6                    //lvl_shift1_t = vmov_n_s16((int16_t)lvl_shift1)
    dup         v6.8h,w7                    //lvl_shift2_t = vmov_n_s16((int16_t)lvl_shift2)
    movi        v0.8h, #0x40                //tmp_lvl_shift = 1 << (shift - 1)
    add         v4.8h,  v4.8h,v6.8h
    add         v0.8h,  v0.8h ,  v4.8h
//   vmvn.i32    v2.8h,#0x6                         @vmovq_n_s32(tmp_shift)
    lsl         x6,x9,#1
    sub         x20,x6,x3,lsl #2            //4*src_strd1 - wd
    neg         x7, x20
    sub         x20,x6,x4,lsl #2            //4*src_strd2 - wd
    neg         x10, x20
    //asr            x6,#1
    //rsb            x6,x6,x5,lsl #2             @4*dst_strd - wd

    cmp         x8,#0                       //check ht == 0
    beq         end_loops                   //if equal, then end the function

chroma_decision:
    orr         x14,x8,x9
    cmp         x14,#10
    beq         outer_loop_chroma_8x2

    cmp         x14,#6
    beq         outer_loop_chroma_4x2


luma_decision:
    cmp         x9,#24
    beq         outer_loop_8

    cmp         x9,#16
    bge         outer_loop_16

    cmp         x9,#12
    beq         outer_loop_4

    cmp         x9,#8
    bge         outer_loop_8






outer_loop_4:
    cmp         x9,#0                       //check wd == 0
    beq         end_loops                   //if equal, then end the function

core_loop_4:
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
    ld1         {v6.4h},[x0],#8             //load and increment the pi2_src1
    add         x14,x2,x5                   //pu1_dst_tmp = pu1_dst + dst_strd
    ld1         {v7.4h},[x1],#8             //load and increment the pi2_src2
    ld1         {v1.4h},[x11],x3            //load and increment the pi2_src1 ii iteration
    sqadd       v18.4h,v6.4h,v7.4h
    sqadd       v18.4h,v18.4h,v0.4h         //vaddq_s32(i4_tmp1_t1, tmp_lvl_shift_t)
    ld1         {v3.4h},[x12],x4            //load and increment the pi2_src2 ii iteration
    sqadd       v20.4h,v1.4h,v3.4h          //vaddq_s32(i4_tmp2_t1, i4_tmp2_t2)
    sqadd       v19.4h,v20.4h,v0.4h         //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t)
    mov         v18.d[1],v19.d[0]
    sqshrun     v20.8b, v18.8h,#7
    ld1         {v22.4h},[x11],x3           //load and increment the pi2_src1 iii iteration
    ld1         {v23.4h},[x12],x4           //load and increment the pi2_src2 iii iteration
    sqadd       v30.4h,v22.4h,v23.4h
    sqadd       v30.4h,v30.4h,v0.4h         //vaddq_s32(i4_tmp1_t1, tmp_lvl_shift_t) iii iteration
    ld1         {v24.4h},[x11],x3           //load and increment the pi2_src1 iv iteration
    ld1         {v25.4h},[x12],x4           //load and increment the pi2_src2 iv iteration
    sqadd       v18.4h,v24.4h,v25.4h        //vaddq_s32(i4_tmp2_t1, i4_tmp2_t2) iv iteration
    sqadd       v31.4h,v18.4h,v0.4h
    mov         v30.d[1],v31.d[0]
    st1         {v20.s}[0],[x2],#4          //store pu1_dst i iteration
    st1         {v20.s}[1],[x14],x5         //store pu1_dst ii iteration
    sqshrun     v30.8b, v30.8h,#7
    st1         {v30.s}[0],[x14],x5         //store pu1_dst iii iteration                                                //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t) iv iteratio
    subs        x9,x9,#4                    //decrement wd by 4 and check for 0
    st1         {v30.s}[1],[x14],x5         //store pu1_dst iv iteration
    bgt         core_loop_4                 //if greater than 0 repeat the core loop again

end_core_loop_4:

    subs        x8,x8,#4                    //decrement the ht by 4

    add         x0,x0,x7                    //pi2_src1 + 4*src_strd1 - 2*wd(since pi2_src1 is 16 bit pointer double the increment with double the wd decrement)
    asr         x9,x6,#1
    add         x1,x1,x10                   //pi2_src2 + 4*src_strd2 - 2*wd
    sub         x20,x9,x5,lsl #2            //4*dst_strd - wd
    neg         x14, x20
    add         x2,x2,x14
                                            //pu1_dst + dst_std - wd
    bgt         core_loop_4                 //if ht is greater than 0 goto outer_loop

    b           end_loops


// this is only for chroma module with input 2x2
outer_loop_chroma_4x2:
    cmp         x9,#0                       //check wd == 0
    beq         end_loops                   //if equal, then end the function
    sub         x20,x6,x3,lsl #1            //2*src_strd1 - wd
    neg         x7, x20
    sub         x20,x6,x4,lsl #1            //2*src_strd2 - wd
    neg         x10, x20
core_loop_chroma_4x2:
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
    ld1         {v6.4h},[x0],#8             //load and increment the pi2_src1
    add         x14,x2,x5                   //pu1_dst_tmp = pu1_dst + dst_strd
    ld1         {v7.4h},[x1],#8             //load and increment the pi2_src2
    ld1         {v1.4h},[x11],x3            //load and increment the pi2_src1 ii iteration
    sqadd       v18.4h,v6.4h,v7.4h
    sqadd       v18.4h,v18.4h,v0.4h         //vaddq_s32(i4_tmp1_t1, tmp_lvl_shift_t)
    ld1         {v3.4h},[x12],x4            //load and increment the pi2_src2 ii iteration
    sqadd       v20.4h,v1.4h,v3.4h          //vaddq_s32(i4_tmp2_t1, i4_tmp2_t2)
    sqadd       v19.4h,v20.4h,v0.4h         //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t)
    mov         v18.d[1],v19.d[0]
    sqshrun     v20.8b, v18.8h,#7
    st1         {v20.s}[0],[x2],#4          //store pu1_dst i iteration
    st1         {v20.s}[1],[x14],x5         //store pu1_dst ii iteration

    subs        x9,x9,#4                    //decrement wd by 4 and check for 0

    bgt         core_loop_chroma_4x2        //if greater than 0 repeat the core loop again

end_core_loop_chorma_4x2:

    subs        x8,x8,#2                    //decrement the ht by 4

    add         x0,x0,x7                    //pi2_src1 + 2*src_strd1 - 2*wd(since pi2_src1 is 16 bit pointer double the increment with double the wd decrement)
    asr         x9,x6,#1
    add         x1,x1,x10                   //pi2_src2 + 2*src_strd2 - 2*wd
    sub         x20,x9,x5,lsl #1            //2*dst_strd - wd
    neg         x14, x20
    add         x2,x2,x14
                                            //pu1_dst + dst_std - wd
    bgt         core_loop_chroma_4x2        //if ht is greater than 0 goto outer_loop

    b           end_loops



outer_loop_8:
    cmp         x9,#0                       //check wd == 0
    beq         end_loops                   //if equal, then end the function
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
core_loop_8:

    ld1         { v24.8h},[x0],#16          //load and increment the pi2_src1
    add         x14,x2,x5                   //pu1_dst_tmp = pu1_dst + dst_strd
    ld1         { v26.8h},[x1],#16          //load and increment the pi2_src2
    sqadd       v24.8h,v24.8h,v26.8h
    ld1         { v28.8h},[x11],x3          //load and increment the pi2_src1 ii iteration
    sqadd       v24.8h,v24.8h,v0.8h         //vaddq_s32(i4_tmp1_t1, tmp_lvl_shift_t)
    ld1         { v30.8h},[x12],x4          //load and increment the pi2_src2 ii iteration
    ld1         { v16.8h},[x11],x3          //load and increment the pi2_src1 iii iteration
    sqadd       v22.8h,v28.8h,v30.8h        //vaddq_s32(i4_tmp2_t1, i4_tmp2_t2)
    ld1         { v18.8h},[x12],x4          //load and increment the pi2_src2 iii iteration
    sqadd       v22.8h,v22.8h,v0.8h         //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t)
    sqshrun     v20.8b, v24.8h,#7
    ld1         { v17.8h},[x11],x3          //load and increment the pi2_src1 iv iteration
    sqadd       v30.8h,v16.8h,v18.8h
    sqshrun     v21.8b, v22.8h,#7
    ld1         { v29.8h},[x12],x4          //load and increment the pi2_src2 iv iteration
    sqadd       v30.8h,v30.8h,v0.8h         //vaddq_s32(i4_tmp1_t1, tmp_lvl_shift_t) iii iteration
    st1         {v20.2s},[x2],#8            //store pu1_dst i iteration
    sqadd       v1.8h,v17.8h,v29.8h         //vaddq_s32(i4_tmp2_t1, i4_tmp2_t2) iv iteration
    st1         {v21.2s},[x14],x5           //store pu1_dst ii iteration
    sqadd       v1.8h,v1.8h,v0.8h
    sqshrun     v30.8b, v30.8h,#7
    sqshrun     v31.8b, v1.8h,#7
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
    st1         {v30.2s},[x14],x5           //store pu1_dst iii iteration                                                //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t) iv iteratio
    subs        x9,x9,#8                    //decrement wd by 4 and check for 0
    st1         {v31.2s},[x14],x5           //store pu1_dst iv iteration
    bgt         core_loop_8                 //if greater than 0 repeat the core loop again

end_core_loop_8:

    subs        x8,x8,#4                    //decrement the ht by 4

    add         x0,x0,x7                    //pi2_src1 + 4*src_strd1 - 2*wd(since pi2_src1 is 16 bit pointer double the increment with double the wd decrement)
    asr         x9,x6,#1
    add         x1,x1,x10                   //pi2_src2 + 4*src_strd2 - 2*wd
    sub         x20,x9,x5,lsl #2            //4*dst_strd - wd
    neg         x14, x20
    add         x2,x2,x14
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)                                  //pu1_dst + dst_std - wd

    bgt         core_loop_8
    b           end_loops



// this is only for chroma module with inpput 4x2
outer_loop_chroma_8x2:
    cmp         x9,#0                       //check wd == 0
    beq         end_loops                   //if equal, then end the function
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
    sub         x20,x6,x3,lsl #1            //2*src_strd1 - wd
    neg         x7, x20
    sub         x20,x6,x4,lsl #1            //2*src_strd2 - wd
    neg         x10, x20
core_loop_chroma_8x2:

    ld1         { v24.8h},[x0],#16          //load and increment the pi2_src1
    add         x14,x2,x5                   //pu1_dst_tmp = pu1_dst + dst_strd
    ld1         { v26.8h},[x1],#16          //load and increment the pi2_src2
    sqadd       v24.8h,v24.8h,v26.8h
    ld1         { v28.8h},[x11],x3          //load and increment the pi2_src1 ii iteration
    sqadd       v24.8h,v24.8h,v0.8h         //vaddq_s32(i4_tmp1_t1, tmp_lvl_shift_t)
    ld1         { v30.8h},[x12],x4          //load and increment the pi2_src2 ii iteration
    ld1         { v16.8h},[x11],x3          //load and increment the pi2_src1 iii iteration
    sqadd       v22.8h,v28.8h,v30.8h        //vaddq_s32(i4_tmp2_t1, i4_tmp2_t2)
    sqadd       v22.8h,v22.8h,v0.8h         //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t)
    sqshrun     v20.8b, v24.8h,#7
    sqshrun     v21.8b, v22.8h,#7
    st1         {v20.2s},[x2],#8            //store pu1_dst i iteration
    st1         {v21.2s},[x14],x5           //store pu1_dst ii iteration

    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
                                            //vaddq_s32(i4_tmp2_t1, tmp_lvl_shift_t) iv iteratio
    subs        x9,x9,#8                    //decrement wd by 4 and check for 0

    bgt         core_loop_chroma_8x2        //if greater than 0 repeat the core loop again

end_core_loop_chroma_8x2:

    subs        x8,x8,#2                    //decrement the ht by 4

    add         x0,x0,x7                    //pi2_src1 + 4*src_strd1 - 2*wd(since pi2_src1 is 16 bit pointer double the increment with double the wd decrement)
    asr         x9,x6,#1
    add         x1,x1,x10                   //pi2_src2 + 4*src_strd2 - 2*wd
    sub         x20,x9,x5,lsl #1            //4*dst_strd - wd
    neg         x14, x20
    add         x2,x2,x14
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)                                  //pu1_dst + dst_std - wd

    bgt         core_loop_chroma_8x2

    b           end_loops




outer_loop_16:
    cmp         x9,#0                       //check wd == 0
    beq         end_loops                   //if equal, then end the function
    add         x11,x0,x3                   //pi2_src_tmp1 = pi2_src1 + 2*src_strd1(2* because pi1_src is a 16 bit pointer)
    add         x12,x1,x4                   //pi2_src_tmp2 = pi2_src2 + 2*src_strd2(2* because pi2_src is a 16 bit pointer)
    sub         x20,x6,x3,lsl #1            //2*src_strd1 - wd
    neg         x7, x20
    mov         x14,#16
    sub         x10,x14,x5
    sub         x11,x3,x14
    sub         x12,x14,x3

    sub         x20,x9,x5,lsl #1            //2*dst_strd - wd
    neg         x14, x20



prolog_16:


    ld1         { v2.8h},[x0],#16           //load and increment the pi2_src1
    ld1         { v4.8h},[x1],#16           //load and increment the pi2_src2
    ld1         { v5.8h},[x0],x11           //load and increment the pi2_src1
    ld1         { v17.8h},[x1],x11          //load and increment the pi2_src2
    ld1         { v6.8h},[x0],#16           //load and increment the pi2_src1 ii iteration
    subs        x9,x9,#16
    ld1         { v1.8h},[x1],#16           //load and increment the pi2_src2 ii iteration
    sub         x20,x8,#2
    csel        x8, x20, x8,eq
    sqadd       v22.8h,v2.8h,v4.8h
    ld1         { v29.8h},[x0],x12          //load and increment the pi2_src1 ii iteration
    sqadd       v28.8h,v5.8h,v17.8h
    ld1         { v16.8h},[x1],x12          //load and increment the pi2_src2 ii iteration
    add         x20,x0,x7
    csel        x0, x20, x0,eq
    add         x20,x1,x7
    csel        x1, x20, x1,eq
    sqadd       v24.8h,v6.8h,v1.8h
    ld1         { v2.8h},[x0],#16
    sqadd       v26.8h,v29.8h,v16.8h
// if the input is chroma with 8x2 block size
    cmp         x8,#0
    beq         epilog_16

    ld1         { v4.8h},[x1],#16           //load and increment the pi2_src2
    sqadd       v22.8h,v22.8h,v0.8h
    ld1         { v5.8h},[x0],x11           //load and increment the pi2_src1
    sqadd       v28.8h,v28.8h,v0.8h
    ld1         { v17.8h},[x1],x11          //load and increment the pi2_src2
    sqadd       v24.8h,v24.8h,v0.8h
    ld1         { v6.8h},[x0],#16           //load and increment the pi2_src1 ii iteration
    sqadd       v30.8h,v26.8h,v0.8h
    sqshrun     v20.8b, v22.8h,#7
    ld1         { v1.8h},[x1],#16           //load and increment the pi2_src2 ii iteration
    sqshrun     v21.8b, v28.8h,#7
    ld1         { v29.8h},[x0],x12          //load and increment the pi2_src1 ii iteration
    sqshrun     v26.8b, v24.8h,#7
    ld1         { v16.8h},[x1],x12          //load and increment the pi2_src2 ii iteration
    sqshrun     v27.8b, v30.8h,#7



core_loop_16:

    cmp         x9,#0
    sqadd       v22.8h,v2.8h,v4.8h
    asr         x20,x6,#1
    csel        x9,x20,x9,eq
    //asreq           x9,x6,#1
    mov         v20.d[1],v21.d[0]
    mov         v26.d[1],v27.d[0]
    st1         { v20.4s},[x2],x5
    sqadd       v28.8h,v5.8h,v17.8h
    st1         { v26.4s},[x2],x10
    add         x20,x2,x14
    csel        x2, x20, x2,eq
    sqadd       v24.8h,v6.8h,v1.8h
    subs        x9,x9,#16
    add         x20,x0,x7
    csel        x0, x20, x0,eq
    sqadd       v26.8h,v29.8h,v16.8h

    add         x20,x1,x7
    csel        x1, x20, x1,eq
    sub         x20,x8,#2
    csel        x8,x20,x8,eq
    cmp         x8,#0
    //subeqs           x8,x8,#2                      //decrement the ht by 2
    beq         epilog_16


    sqadd       v22.8h,v22.8h,v0.8h
    ld1         { v2.8h},[x0],#16           //load and increment the pi2_src1
    sqadd       v28.8h,v28.8h,v0.8h
    ld1         { v4.8h},[x1],#16           //load and increment the pi2_src2
    sqadd       v24.8h,v24.8h,v0.8h
    ld1         { v5.8h},[x0],x11           //load and increment the pi2_src1
    sqadd       v30.8h,v26.8h,v0.8h
    ld1         { v17.8h},[x1],x11          //load and increment the pi2_src2
    sqshrun     v20.8b, v22.8h,#7
    ld1         { v6.8h},[x0],#16           //load and increment the pi2_src1 ii iteration
    sqshrun     v21.8b, v28.8h,#7
    ld1         { v1.8h},[x1],#16           //load and increment the pi2_src2 ii iteration
    sqshrun     v26.8b, v24.8h,#7
    ld1         { v29.8h},[x0],x12          //load and increment the pi2_src1 ii iteration
    sqshrun     v27.8b, v30.8h,#7
    ld1         { v16.8h},[x1],x12          //load and increment the pi2_src2 ii iteration


    b           core_loop_16


epilog_16:

    sqadd       v22.8h,v22.8h,v0.8h
    sqadd       v28.8h,v28.8h,v0.8h
    sqadd       v24.8h,v24.8h,v0.8h
    sqadd       v30.8h,v26.8h,v0.8h
    sqshrun     v20.8b, v22.8h,#7
    sqshrun     v21.8b, v28.8h,#7
    sqshrun     v26.8b, v24.8h,#7
    sqshrun     v27.8b, v30.8h,#7
    mov         v20.d[1],v21.d[0]
    mov         v26.d[1],v27.d[0]
    st1         { v20.4s},[x2],x5
    st1         { v26.4s},[x2]



end_core_loop_16:








end_loops:
    // ldmfd sp!,{x4-x12,x15}                  //reload the registers from sp
    ldp         x21, x22,[sp],#16
    ldp         x19, x20,[sp],#16

    ret