summaryrefslogtreecommitdiffstats
path: root/common/arm64/ihevc_intra_pred_filters_luma_mode_19_to_25.s
blob: fe7ac11cd410ebd1ef5dd3b7ca109bf839cc97b5 (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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
///*****************************************************************************
//*
//* 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_intra_pred_luma_mode_19_to_25.s
//*
//* @brief
//*  contains function definitions for intra prediction dc filtering.
//* functions are coded using neon  intrinsics and can be compiled using

//* rvct
//*
//* @author
//*  naveen sr
//*
//* @par list of functions:
//*
//*
//* @remarks
//*  none
//*
//*******************************************************************************
//*/
///**
//*******************************************************************************
//*
//* @brief
//*    luma intraprediction filter for dc input
//*
//* @par description:
//*
//* @param[in] pu1_ref
//*  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
//*
//* @param[in] nt
//*  size of tranform block
//*
//* @param[in] mode
//*  type of filtering
//*
//* @returns
//*
//* @remarks
//*  none
//*
//*******************************************************************************
//*/

//void ihevc_intra_pred_luma_mode_19_to_25(uword8* pu1_ref,
//                               word32 src_strd,
//                               uword8* pu1_dst,
//                               word32 dst_strd,
//                               word32 nt,
//                               word32 mode)
//
//**************variables vs registers*****************************************
//x0 => *pu1_ref
//x1 => src_strd
//x2 => *pu1_dst
//x3 => dst_strd

//stack contents from #40
//    nt
//    mode

.text
.align 4
.include "ihevc_neon_macros.s"



.globl ihevc_intra_pred_luma_mode_19_to_25_av8
.extern gai4_ihevc_ang_table
.extern gai4_ihevc_inv_ang_table
.extern gau1_ihevc_planar_factor

.type ihevc_intra_pred_luma_mode_19_to_25_av8, %function

ihevc_intra_pred_luma_mode_19_to_25_av8:

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

    adrp        x7,  :got:gai4_ihevc_ang_table
    ldr         x7,  [x7, #:got_lo12:gai4_ihevc_ang_table]

    adrp        x8,  :got:gai4_ihevc_inv_ang_table
    ldr         x8,  [x8, #:got_lo12:gai4_ihevc_inv_ang_table]

    add         x7, x7, x5, lsl #2          //gai4_ihevc_ang_table[mode]
    add         x8, x8, x5, lsl #2          //gai4_ihevc_inv_ang_table
    sub         x8, x8, #48                 //gai4_ihevc_inv_ang_table[mode - 12]

    ldr         w7,  [x7]                   //intra_pred_ang
    sxtw        x7,w7
    sub         sp, sp, #132                //ref_temp[2 * max_cu_size + 1]

    ldr         w8,  [x8]                   //inv_ang
    sxtw        x8,w8
    add         x6, sp, x4                  //ref_temp + nt

    mul         x9, x4, x7                  //nt*intra_pred_ang

    sub         x6, x6, #1                  //ref_temp + nt - 1

    add         x1, x0, x4, lsl #1          //x1 = &src[2nt]
    dup         v30.8b,w7                   //intra_pred_ang

    mov         x7, x4

    asr         x9, x9, #5

    ld1         {v0.s}[0],[x1],#4           // pu1_ref[two_nt + k]

    st1         {v0.s}[0],[x6],#4           //ref_temp[k + nt - 1] = pu1_ref[two_nt + k]//

    subs        x7, x7, #4
    beq         end_loop_copy
    sub         x1, x1,#4
    sub         x6, x6,#4
    subs        x7,x7,#4
    beq         loop_copy_8
    subs        x7,x7,#8
    beq         loop_copy_16

loop_copy_32:
    ld1         {v0.8b},[x1],#8
    ld1         {v1.8b},[x1],#8
    ld1         {v2.8b},[x1],#8
    ld1         {v3.8b},[x1],#8

    st1         {v0.8b},[x6],#8
    st1         {v1.8b},[x6],#8
    st1         {v2.8b},[x6],#8
    st1         {v3.8b},[x6],#8
    b           end_loop_copy

loop_copy_16:
    ld1         {v0.8b},[x1],#8
    ld1         {v1.8b},[x1],#8

    st1         {v0.8b},[x6],#8
    st1         {v1.8b},[x6],#8
    b           end_loop_copy

loop_copy_8:
    ld1         {v0.8b},[x1],#8
    st1         {v0.8b},[x6],#8

end_loop_copy:

    ldrb        w11, [x1]
    sxtw        x11,w11
    strb        w11, [x6]
    sxtw        x11,w11

    cmp         x9, #-1
    bge         linear_filtering

    add         x6, sp, x4                  //ref_temp + nt
    sub         x6, x6, #2                  //ref_temp + nt - 2

    mov         x12, #-1

    sub         x20, x9, x12                //count to take care off ref_idx
    neg         x9, x20

    add         x1, x0, x4, lsl #1          //x1 = &src[2nt]

    mov         x7, #128                    //inv_ang_sum

loop_copy_ref_idx:

    add         x7, x7, x8                  //inv_ang_sum += inv_ang
    lsr         x14, x7, #8
    neg         x20,x14
    ldrb        w11, [x1, x20]
    sxtw        x11,w11
//    ldrb        x11, [x1, -x7, lsr #8]
    strb        w11, [x6], #-1
    sxtw        x11,w11

    subs        x9, x9, #1

    bne         loop_copy_ref_idx


linear_filtering:
//    after copy
//    below code is taken from mode 27 to 33 and modified

    adrp        x6,  :got:gai4_ihevc_ang_table //loads word32 gai4_ihevc_ang_table[35]
    ldr         x6,  [x6, #:got_lo12:gai4_ihevc_ang_table]

    add         x8,x6,x5,lsl #2             //*gai4_ihevc_ang_table[mode]
    ldr         w9, [x8]                    //intra_pred_ang = gai4_ihevc_ang_table[mode]
    sxtw        x9,w9
    adrp        x1, :got:gau1_ihevc_planar_factor //used for ((row + 1) * intra_pred_ang) row values
    ldr         x1, [x1, #:got_lo12:gau1_ihevc_planar_factor]
    add         x6,x1,#1

    add         x8, sp, x4                  //ref_temp + nt
    sub         x8, x8,#1                   //ref_temp + nt -1

    tst         x4,#7
    mov         x14,#0                      //row
    mov         x12,x4
    bne         core_loop_4

core_loop_8:
    add         x8,x8,#1                    //pu1_ref_main_idx += (two_nt + 1)
    dup         v0.8b,w9                    //intra_pred_ang
    lsr         x12, x4, #3                 //divide by 8

    movi        v1.8b, #32
    mul         x7, x4, x12

    movi        v6.8h, #31
    //lsl            x12,x3,#3

    mov         x1,x8
    //sub            x12,x12,x4
    mov         x5,x4
    mov         x11,#1

prologue:
    ld1         {v3.8b},[x6]                //loads the row value
    smull       v2.8h, v3.8b, v0.8b         //pos = ((row + 1) * intra_pred_ang)
    and         v4.16b,  v2.16b ,  v6.16b   //dup_const_fract(fract = pos & (31))
    xtn         v4.8b,  v4.8h
    shrn        v5.8b, v2.8h,#5             //idx = pos >> 5

    dup         v31.8b, v4.8b[0]
    add         x0,x2,x3

    umov        w14, v5.2s[0]               //(i row)extract idx to the r register
    sxtw        x14,w14

    dup         v29.8b, v4.8b[1]            //(ii)
    sbfx        x9,x14,#0,#8

    add         x10,x8,x9                   //(i row)*pu1_ref[ref_main_idx]

    ld1         {v8.8b},[x10],x11           //(i row)ref_main_idx
    sbfx        x9,x14,#8,#8

    ld1         {v9.8b},[x10]               //(i row)ref_main_idx_1
    add         x12,x8,x9                   //(ii)*pu1_ref[ref_main_idx]

    sbfx        x9,x14,#16,#8
    sub         v30.8b,  v1.8b ,  v31.8b    //32-fract(dup_const_32_fract)
    add         x10,x8,x9                   //(iii)*pu1_ref[ref_main_idx]

    ld1         {v12.8b},[x12],x11          //(ii)ref_main_idx
    umull       v10.8h, v8.8b, v30.8b       //(i row)vmull_u8(ref_main_idx, dup_const_32_fract)

    ld1         {v13.8b},[x12]              //(ii)ref_main_idx_1
    umlal       v10.8h, v9.8b, v31.8b       //(i row)vmull_u8(ref_main_idx_1, dup_const_fract)

    dup         v27.8b, v4.8b[2]            //(iii)
    sub         v28.8b,  v1.8b ,  v29.8b    //(ii)32-fract(dup_const_32_fract)
    sbfx        x9,x14,#24,#8

    dup         v25.8b, v4.8b[3]            //(iv)
    umull       v14.8h, v12.8b, v28.8b      //(ii)vmull_u8(ref_main_idx, dup_const_32_fract)
    add         x12,x8,x9                   //(iv)*pu1_ref[ref_main_idx]

    ld1         {v16.8b},[x10],x11          //(iii)ref_main_idx
    umlal       v14.8h, v13.8b, v29.8b      //(ii)vmull_u8(ref_main_idx_1, dup_const_fract)

    ld1         {v17.8b},[x10]              //(iii)ref_main_idx_1
    rshrn       v10.8b, v10.8h,#5           //(i row)shift_res = vrshrn_n_u16(add_res, 5)

    ld1         {v20.8b},[x12],x11          //(iv)ref_main_idx
    sub         v26.8b,  v1.8b ,  v27.8b    //(iii)32-fract(dup_const_32_fract)

    ld1         {v21.8b},[x12]              //(iv)ref_main_idx_1

    dup         v31.8b, v4.8b[4]            //(v)
    umull       v18.8h, v16.8b, v26.8b      //(iii)vmull_u8(ref_main_idx, dup_const_32_fract)

    umov        w14, v5.2s[1]               //extract idx to the r register
    sxtw        x14,w14
    umlal       v18.8h, v17.8b, v27.8b      //(iii)vmull_u8(ref_main_idx_1, dup_const_fract)

    st1         {v10.8b},[x2],#8            //(i row)
    rshrn       v14.8b, v14.8h,#5           //(ii)shift_res = vrshrn_n_u16(add_res, 5)

    sbfx        x9,x14,#0,#8
    dup         v29.8b, v4.8b[5]            //(vi)
    add         x10,x8,x9                   //(v)*pu1_ref[ref_main_idx]

    ld1         {v8.8b},[x10],x11           //(v)ref_main_idx
    sub         v24.8b,  v1.8b ,  v25.8b    //(iv)32-fract(dup_const_32_fract)

    umull       v22.8h, v20.8b, v24.8b      //(iv)vmull_u8(ref_main_idx, dup_const_32_fract)
    sbfx        x9,x14,#8,#8

    ld1         {v9.8b},[x10]               //(v)ref_main_idx_1
    umlal       v22.8h, v21.8b, v25.8b      //(iv)vmull_u8(ref_main_idx_1, dup_const_fract)

    st1         {v14.8b},[x0],x3            //(ii)
    rshrn       v18.8b, v18.8h,#5           //(iii)shift_res = vrshrn_n_u16(add_res, 5)

    add         x12,x8,x9                   //(vi)*pu1_ref[ref_main_idx]
    dup         v27.8b, v4.8b[6]            //(vii)

    sbfx        x9,x14,#16,#8
    sub         v30.8b,  v1.8b ,  v31.8b    //(v)32-fract(dup_const_32_fract)
    add         x10,x8,x9                   //(vii)*pu1_ref[ref_main_idx]

    ld1         {v12.8b},[x12],x11          //(vi)ref_main_idx
    umull       v10.8h, v8.8b, v30.8b       //(v)vmull_u8(ref_main_idx, dup_const_32_fract)

    ld1         {v13.8b},[x12]              //(vi)ref_main_idx_1
    umlal       v10.8h, v9.8b, v31.8b       //(v)vmull_u8(ref_main_idx_1, dup_const_fract)

    st1         {v18.8b},[x0],x3            //(iii)
    rshrn       v22.8b, v22.8h,#5           //(iv)shift_res = vrshrn_n_u16(add_res, 5)

    dup         v25.8b, v4.8b[7]            //(viii)
    sbfx        x9,x14,#24,#8

    ld1         {v16.8b},[x10],x11          //(vii)ref_main_idx
    sub         v28.8b,  v1.8b ,  v29.8b    //(vi)32-fract(dup_const_32_fract)

    ld1         {v17.8b},[x10]              //(vii)ref_main_idx_1
    umull       v14.8h, v12.8b, v28.8b      //(vi)vmull_u8(ref_main_idx, dup_const_32_fract)

    add         x12,x8,x9                   //(viii)*pu1_ref[ref_main_idx]
    umlal       v14.8h, v13.8b, v29.8b      //(vi)vmull_u8(ref_main_idx_1, dup_const_fract)
    subs        x4,x4,#8

    st1         {v22.8b},[x0],x3            //(iv)
    rshrn       v10.8b, v10.8h,#5           //(v)shift_res = vrshrn_n_u16(add_res, 5)

    ld1         {v20.8b},[x12],x11          //(viii)ref_main_idx
    sub         v26.8b,  v1.8b ,  v27.8b    //(vii)32-fract(dup_const_32_fract)

    ld1         {v21.8b},[x12]              //(viii)ref_main_idx_1
    umull       v18.8h, v16.8b, v26.8b      //(vii)vmull_u8(ref_main_idx, dup_const_32_fract)

    add         x20,x8,#8
    csel        x8, x20, x8,gt
    umlal       v18.8h, v17.8b, v27.8b      //(vii)vmull_u8(ref_main_idx_1, dup_const_fract)
    sub         x20,x7,#8
    csel        x7, x20, x7,gt

    st1         {v10.8b},[x0],x3            //(v)
    rshrn       v14.8b, v14.8h,#5           //(vi)shift_res = vrshrn_n_u16(add_res, 5)

    beq         epilogue

    ld1         {v5.8b},[x6]                //loads the row value
    smull       v2.8h, v5.8b, v0.8b         //pos = ((row + 1) * intra_pred_ang)
    and         v4.16b,  v2.16b ,  v6.16b   //dup_const_fract(fract = pos & (31))
    xtn         v4.8b,  v4.8h
    shrn        v3.8b, v2.8h,#5             //idx = pos >> 5
    umov        w14, v3.2s[0]               //(i)extract idx to the r register
    sxtw        x14,w14
    sbfx        x9,x14,#0,#8
    add         x10,x8,x9                   //(i)*pu1_ref[ref_main_idx]

kernel_8_rows:
    dup         v31.8b, v4.8b[0]
    subs        x4,x4,#8
    sbfx        x9,x14,#8,#8

    ld1         {v8.8b},[x10],x11           //(i)ref_main_idx
    sub         v24.8b,  v1.8b ,  v25.8b    //(viii)32-fract(dup_const_32_fract)

    add         x20,x6,#8                   //increment the row value
    csel        x6, x20, x6,le
    add         x12,x8,x9                   //(ii)*pu1_ref[ref_main_idx]

    ld1         {v9.8b},[x10]               //(i)ref_main_idx_1
    umull       v22.8h, v20.8b, v24.8b      //(viii)vmull_u8(ref_main_idx, dup_const_32_fract)

    ld1         {v5.8b},[x6]                //loads the row value
    umlal       v22.8h, v21.8b, v25.8b      //(viii)vmull_u8(ref_main_idx_1, dup_const_fract)

    dup         v29.8b, v4.8b[1]            //(ii)
    rshrn       v18.8b, v18.8h,#5           //(vii)shift_res = vrshrn_n_u16(add_res, 5)

    sbfx        x9,x14,#16,#8

    st1         {v14.8b},[x0],x3            //(vi)
    sub         v30.8b,  v1.8b ,  v31.8b    //(i)32-fract(dup_const_32_fract)

    add         x10,x8,x9                   //(iii)*pu1_ref[ref_main_idx]

    ld1         {v12.8b},[x12],x11          //(ii)ref_main_idx
    umull       v10.8h, v8.8b, v30.8b       //(i)vmull_u8(ref_main_idx, dup_const_32_fract)

    ld1         {v13.8b},[x12]              //(ii)ref_main_idx_1
    umlal       v10.8h, v9.8b, v31.8b       //(i)vmull_u8(ref_main_idx_1, dup_const_fract)

    sbfx        x9,x14,#24,#8
    csel        x4, x5, x4,le               //reload nt

    umov        w14, v3.2s[1]               //extract idx to the r register
    sxtw        x14,w14
    rshrn       v22.8b, v22.8h,#5           //(viii)shift_res = vrshrn_n_u16(add_res, 5)

    dup         v27.8b, v4.8b[2]            //(iii)
    sub         v28.8b,  v1.8b ,  v29.8b    //(ii)32-fract(dup_const_32_fract)
    add         x12,x8,x9                   //(iv)*pu1_ref[ref_main_idx]

    ld1         {v16.8b},[x10],x11          //(iii)ref_main_idx
    umull       v14.8h, v12.8b, v28.8b      //(ii)vmull_u8(ref_main_idx, dup_const_32_fract)

    st1         {v18.8b},[x0],x3            //(vii)
    umlal       v14.8h, v13.8b, v29.8b      //(ii)vmull_u8(ref_main_idx_1, dup_const_fract)

    ld1         {v17.8b},[x10]              //(iii)ref_main_idx_1
    rshrn       v10.8b, v10.8h,#5           //(i)shift_res = vrshrn_n_u16(add_res, 5)

    dup         v25.8b, v4.8b[3]            //(iv)
    smull       v2.8h, v5.8b, v0.8b         //pos = ((row + 1) * intra_pred_ang)

    st1         {v22.8b},[x0]               //(viii)
    sub         v26.8b,  v1.8b ,  v27.8b    //(iii)32-fract(dup_const_32_fract)

    ld1         {v20.8b},[x12],x11          //(iv)ref_main_idx
    umull       v18.8h, v16.8b, v26.8b      //(iii)vmull_u8(ref_main_idx, dup_const_32_fract)

    ld1         {v21.8b},[x12]              //(iv)ref_main_idx_1
    umlal       v18.8h, v17.8b, v27.8b      //(iii)vmull_u8(ref_main_idx_1, dup_const_fract)

    sbfx        x9,x14,#0,#8
    add         x0,x2,x3

    dup         v31.8b, v4.8b[4]            //(v)
    rshrn       v14.8b, v14.8h,#5           //(ii)shift_res = vrshrn_n_u16(add_res, 5)

    add         x10,x8,x9                   //(v)*pu1_ref[ref_main_idx]
    sbfx        x9,x14,#8,#8

    st1         {v10.8b},[x2],#8            //(i)
    sub         v24.8b,  v1.8b ,  v25.8b    //(iv)32-fract(dup_const_32_fract)

    dup         v29.8b, v4.8b[5]            //(vi)
    umull       v22.8h, v20.8b, v24.8b      //(iv)vmull_u8(ref_main_idx, dup_const_32_fract)

    dup         v27.8b, v4.8b[6]            //(vii)
    umlal       v22.8h, v21.8b, v25.8b      //(iv)vmull_u8(ref_main_idx_1, dup_const_fract)

    add         x12,x8,x9                   //(vi)*pu1_ref[ref_main_idx]
    sbfx        x9,x14,#16,#8

    dup         v25.8b, v4.8b[7]            //(viii)
    rshrn       v18.8b, v18.8h,#5           //(iii)shift_res = vrshrn_n_u16(add_res, 5)

    ld1         {v8.8b},[x10],x11           //(v)ref_main_idx
    and         v4.16b,  v2.16b ,  v6.16b   //dup_const_fract(fract = pos & (31))

    ld1         {v9.8b},[x10]               //(v)ref_main_idx_1
    shrn        v3.8b, v2.8h,#5             //idx = pos >> 5

    st1         {v14.8b},[x0],x3            //(ii)
    rshrn       v22.8b, v22.8h,#5           //(iv)shift_res = vrshrn_n_u16(add_res, 5)

    add         x10,x8,x9                   //(vii)*pu1_ref[ref_main_idx]
    sbfx        x9,x14,#24,#8

    ld1         {v12.8b},[x12],x11          //(vi)ref_main_idx
    sub         v30.8b,  v1.8b ,  v31.8b    //(v)32-fract(dup_const_32_fract)

    ld1         {v13.8b},[x12]              //(vi)ref_main_idx_1
    umull       v10.8h, v8.8b, v30.8b       //(v)vmull_u8(ref_main_idx, dup_const_32_fract)

    umov        w14, v3.2s[0]               //(i)extract idx to the r register
    sxtw        x14,w14
    umlal       v10.8h, v9.8b, v31.8b       //(v)vmull_u8(ref_main_idx_1, dup_const_fract)

    add         x12,x8,x9                   //(viii)*pu1_ref[ref_main_idx]
    csel        x8, x1, x8,le               //reload the source to pu1_src+2nt

    ld1         {v16.8b},[x10],x11          //(vii)ref_main_idx
    sub         v28.8b,  v1.8b ,  v29.8b    //(vi)32-fract(dup_const_32_fract)

    st1         {v18.8b},[x0],x3            //(iii)
    umull       v14.8h, v12.8b, v28.8b      //(vi)vmull_u8(ref_main_idx, dup_const_32_fract)

    ld1         {v17.8b},[x10]              //(vii)ref_main_idx_1
    umlal       v14.8h, v13.8b, v29.8b      //(vi)vmull_u8(ref_main_idx_1, dup_const_fract)

    ld1         {v20.8b},[x12],x11          //(viii)ref_main_idx
    rshrn       v10.8b, v10.8h,#5           //(v)shift_res = vrshrn_n_u16(add_res, 5)

    ld1         {v21.8b},[x12]              //(viii)ref_main_idx_1
    sub         v26.8b,  v1.8b ,  v27.8b    //(vii)32-fract(dup_const_32_fract)

    add         x20,x8,#8                   //increment the source next set 8 columns in same row
    csel        x8, x20, x8,gt
    lsl         x20, x3,#3
    csel        x12,x20,x12,le
    sub         x20,x12,x5
    csel        x12, x20, x12,le

    st1         {v22.8b},[x0],x3            //(iv)
    umull       v18.8h, v16.8b, v26.8b      //(vii)vmull_u8(ref_main_idx, dup_const_32_fract)

    st1         {v10.8b},[x0],x3            //(v)
    umlal       v18.8h, v17.8b, v27.8b      //(vii)vmull_u8(ref_main_idx_1, dup_const_fract)

    add         x20,x2,x12                  //increment the dst pointer to 8*dst_strd - nt
    csel        x2, x20, x2,le
    sbfx        x9,x14,#0,#8

    xtn         v4.8b,  v4.8h
    rshrn       v14.8b, v14.8h,#5           //(vi)shift_res = vrshrn_n_u16(add_res, 5)

    subs        x7,x7,#8
    add         x10,x8,x9                   //(i)*pu1_ref[ref_main_idx]

    bne         kernel_8_rows

epilogue:
    st1         {v14.8b},[x0],x3            //(vi)
    rshrn       v18.8b, v18.8h,#5           //(vii)shift_res = vrshrn_n_u16(add_res, 5)

    sub         v24.8b,  v1.8b ,  v25.8b    //(viii)32-fract(dup_const_32_fract)
    umull       v22.8h, v20.8b, v24.8b      //(viii)vmull_u8(ref_main_idx, dup_const_32_fract)
    umlal       v22.8h, v21.8b, v25.8b      //(viii)vmull_u8(ref_main_idx_1, dup_const_fract)

    st1         {v18.8b},[x0],x3            //(vii)
    rshrn       v22.8b, v22.8h,#5           //(viii)shift_res = vrshrn_n_u16(add_res, 5)

    st1         {v22.8b},[x0],x3            //(viii)
    b           end_loops

core_loop_4:
    add         x6,x8,#1                    //pu1_ref_main_idx +=  1
    mov         x8,#0

    add         x5,x8,#1                    //row + 1
    mul         x5, x5, x9                  //pos = ((row + 1) * intra_pred_ang)
    asr         x14, x5, #5                 //if(fract_prev > fract)
    and         x5,x5,#31                   //fract = pos & (31)
    add         x10,x6,x14                  //pu1_ref_main_idx += 1
    add         x11,x10,#1                  //pu1_ref_main_idx_1 += 1
    dup         v0.8b,w5                    //dup_const_fract
    sub         x20,x5,#32
    neg         x4, x20
    dup         v1.8b,w4                    //dup_const_32_fract

//inner_loop_4
    ld1         {v2.s}[0],[x10]             //ref_main_idx
    add         x8,x8,#1
//    mov            x14,x5                            @fract_prev = fract

    ld1         {v3.s}[0],[x11]             //ref_main_idx_1
    add         x5,x8,#1                    //row + 1
    mul         x5, x5, x9                  //pos = ((row + 1) * intra_pred_ang)
    asr         x14, x5, #5                 // pos >> 5
    and         x5,x5,#31                   //fract = pos & (31)
    add         x10,x6,x14                  //pu1_ref_main_idx += 1
    add         x11,x10,#1                  //pu1_ref_main_idx_1 += 1

    dup         v6.8b,w5                    //dup_const_fract
    umull       v4.8h, v2.8b, v1.8b         //vmull_u8(ref_main_idx, dup_const_32_fract)

    sub         x20,x5,#32
    neg         x4, x20
    dup         v7.8b,w4                    //dup_const_32_fract
    umlal       v4.8h, v3.8b, v0.8b         //vmull_u8(ref_main_idx_1, dup_const_fract)

    ld1         {v8.s}[0],[x10]             //ref_main_idx
    add         x8,x8,#1

    ld1         {v9.s}[0],[x11]             //ref_main_idx_1
    rshrn       v4.8b, v4.8h,#5             //shift_res = vrshrn_n_u16(add_res, 5)

//    mov            x14,x5                            @fract_prev = fract
    add         x5,x8,#1                    //row + 1
    mul         x5, x5, x9                  //pos = ((row + 1) * intra_pred_ang)
    asr         x14, x5, #5                 //if(fract_prev > fract)
    and         x5,x5,#31                   //fract = pos & (31)
    add         x10,x6,x14                  //ref_main + idx
    add         x11,x10,#1                  //pu1_ref_main_idx_1 += 1

    dup         v12.8b,w5                   //dup_const_fract
    umull       v10.8h, v8.8b, v7.8b        //vmull_u8(ref_main_idx, dup_const_32_fract)

    sub         x20,x5,#32
    neg         x4, x20
    dup         v13.8b,w4                   //dup_const_32_fract
    umlal       v10.8h, v9.8b, v6.8b        //vmull_u8(ref_main_idx_1, dup_const_fract)

    ld1         {v14.s}[0],[x10]            //ref_main_idx
    add         x8,x8,#1

    st1         {v4.s}[0],[x2],x3
    rshrn       v10.8b, v10.8h,#5           //shift_res = vrshrn_n_u16(add_res, 5)

    ld1         {v15.s}[0],[x11]            //ref_main_idx_1
//    mov            x14,x5                            @fract_prev = fract
    add         x5,x8,#1                    //row + 1
    mul         x5, x5, x9                  //pos = ((row + 1) * intra_pred_ang)
    asr         x14, x5, #5                 //if(fract_prev > fract)
    and         x5,x5,#31                   //fract = pos & (31)
    add         x10,x6,x14                  //pu1_ref_main_idx += 1
    add         x11,x10,#1                  //pu1_ref_main_idx_1 += 1

    dup         v18.8b,w5                   //dup_const_fract
    umull       v16.8h, v14.8b, v13.8b      //vmull_u8(ref_main_idx, dup_const_32_fract)

    sub         x20,x5,#32
    neg         x4, x20
    dup         v19.8b,w4                   //dup_const_32_fract
    umlal       v16.8h, v15.8b, v12.8b      //vmull_u8(ref_main_idx_1, dup_const_fract)

    ld1         {v20.s}[0],[x10]            //ref_main_idx

    st1         {v10.s}[0],[x2],x3
    rshrn       v16.8b, v16.8h,#5           //shift_res = vrshrn_n_u16(add_res, 5)
    ld1         {v21.s}[0],[x11]            //ref_main_idx_1

    umull       v22.8h, v20.8b, v19.8b      //vmull_u8(ref_main_idx, dup_const_32_fract)
    umlal       v22.8h, v21.8b, v18.8b      //vmull_u8(ref_main_idx_1, dup_const_fract)

    st1         {v16.s}[0],[x2],x3
    rshrn       v22.8b, v22.8h,#5           //shift_res = vrshrn_n_u16(add_res, 5)

    st1         {v22.s}[0],[x2],x3

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