summaryrefslogtreecommitdiffstats
path: root/common/armv8/ih264_iquant_itrans_recon_av8.s
blob: 4c830369b8d794fcf8a6f3e6dfa33ee32c36eeb5 (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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
//******************************************************************************
//*
//* 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_iquant_itrans_recon_a9.s
// *
// * //brief
// *  Contains function definitions for single stage  inverse transform
// *
// * //author
// *  Parthiban V
// *     Mohit
// *  Harinarayanaan
// *
// * //par List of Functions:
// *  - ih264_iquant_itrans_recon_4x4_av8()
// *     - ih264_iquant_itrans_recon_8x8_av8()
// *     - ih264_iquant_itrans_recon_chroma_4x4_av8()
// *
// * //remarks
// *  None
// *
// *******************************************************************************

.text
.p2align 2
.include "ih264_neon_macros.s"

///*
// *******************************************************************************
// *
// * //brief
// *  This function performs inverse quant and Inverse transform type Ci4 for 4*4 block
// *
// * //par Description:
// *  Performs inverse transform Ci4 and adds the residue to get the
// *  reconstructed block
// *
// * //param[in] pi2_src
// *  Input 4x4 coefficients
// *
// * //param[in] pu1_pred
// *  Prediction 4x4 block
// *
// * //param[out] pu1_out
// *  Output 4x4 block
// *
// * //param[in] u4_qp_div_6
// *     QP
// *
// * //param[in] pu2_weigh_mat
// * Pointer to weight matrix
// *
// * //param[in] pred_strd,
// *  Prediction stride
// *
// * //param[in] out_strd
// *  Output Stride
// *
// *//param[in] pi2_tmp
// * temporary buffer of size 1*16
// *
// * //param[in] pu2_iscal_mat
// * Pointer to the inverse quantization matrix
// *
// * //returns  Void
// *
// * //remarks
// *  None
// *
// *******************************************************************************
// */
//void ih264_iquant_itrans_recon_4x4(WORD16 *pi2_src,
//                                    UWORD8 *pu1_pred,
//                                    UWORD8 *pu1_out,
//                                    WORD32 pred_strd,
//                                    WORD32 out_strd,
//                                    const UWORD16 *pu2_iscal_mat,
//                                    const UWORD16 *pu2_weigh_mat,
//                                    UWORD32 u4_qp_div_6,
//                                    WORD32 *pi4_tmp,
//                                    WORD32 iq_start_idx
//                                    WORD16 *pi2_dc_ld_addr)
//**************Variables Vs Registers*****************************************
//x0 => *pi2_src
//x1 => *pu1_pred
//x2 => *pu1_out
//x3 =>  pred_strd
//x4 =>  out_strd
//x5 => *pu2_iscal_mat
//x6 => *pu2_weigh_mat
//x7 =>  u4_qp_div_6
//   =>  pi4_tmp
//   =>  iq_start_idx
//   =>  pi2_dc_ld_addr
//Only one shift is done in horizontal inverse because,
//if u4_qp_div_6 is lesser than 4 then shift value will be neagative and do negative left shift, in this case rnd_factor has value
//if u4_qp_div_6 is greater than 4 then shift value will be positive and do left shift, here rnd_factor is 0

    .global ih264_iquant_itrans_recon_4x4_av8
ih264_iquant_itrans_recon_4x4_av8:

    push_v_regs

    dup       v30.4s, w7                //Populate the u4_qp_div_6 in Q15

    ldr       w8, [sp, #72]             //Loads iq_start_idx
    sxtw      x8, w8

    ldr       x10, [sp, #80]            //Load alternate dc address

    subs      x8, x8, #1                // if x8 == 1 => intra case , so result of subtraction is zero and z flag is set


//=======================DEQUANT FROM HERE===================================

    ld4       {v20.4h - v23.4h}, [x5]   // load pu2_iscal_mat[i], i =0..15
    ld4       {v26.4h - v29.4h}, [x6]   // pu2_weigh_mat[i], i =0..15
    ld4       {v16.4h - v19.4h}, [x0]   // pi2_src_tmp[i], i =0..15


    mul       v20.4h, v20.4h, v26.4h    // x[i]=(scale[i] * dequant[i]) where i = 0..3
    mul       v21.4h, v21.4h, v27.4h    // x[i]=(scale[i] * dequant[i]) where i = 4..7
    mul       v22.4h, v22.4h, v28.4h    // x[i]=(scale[i] * dequant[i]) where i = 8..11
    mul       v23.4h, v23.4h, v29.4h    // x[i]=(scale[i] * dequant[i]) where i = 12..14

    smull     v0.4s, v16.4h, v20.4h     // q0  = p[i] = (x[i] * trns_coeff[i]) where i = 0..3
    smull     v2.4s, v17.4h, v21.4h     // q1  = p[i] = (x[i] * trns_coeff[i]) where i = 4..7
    smull     v4.4s, v18.4h, v22.4h     // q2  = p[i] = (x[i] * trns_coeff[i]) where i = 8..11
    smull     v6.4s, v19.4h, v23.4h     // q3  = p[i] = (x[i] * trns_coeff[i]) where i = 12..15

    sshl      v0.4s, v0.4s, v30.4s      // q0  = q[i] = (p[i] << (qp/6)) where i = 0..3
    sshl      v2.4s, v2.4s, v30.4s      // q1  = q[i] = (p[i] << (qp/6)) where i = 4..7
    sshl      v4.4s, v4.4s, v30.4s      // q2  = q[i] = (p[i] << (qp/6)) where i = 8..11
    sshl      v6.4s, v6.4s, v30.4s      // q3  = q[i] = (p[i] << (qp/6)) where i = 12..15

    sqrshrn   v0.4h, v0.4s, #0x4        // d0  = c[i] = ((q[i] + 32) >> 4) where i = 0..3
    sqrshrn   v1.4h, v2.4s, #0x4        // d1  = c[i] = ((q[i] + 32) >> 4) where i = 4..7
    sqrshrn   v2.4h, v4.4s, #0x4        // d2  = c[i] = ((q[i] + 32) >> 4) where i = 8..11
    sqrshrn   v3.4h, v6.4s, #0x4        // d3  = c[i] = ((q[i] + 32) >> 4) where i = 12..15

    bne       skip_loading_luma_dc_src
    ld1       {v0.h}[0], [x10]          // loads signed halfword pi2_dc_ld_addr[0], if x8==1
skip_loading_luma_dc_src:

    //========= PROCESS IDCT FROM HERE =======
    //Steps for Stage 1:
    //------------------
    ld1       {v30.s}[0], [x1], x3      // i row load pu1_pred buffer

    sshr      v8.4h, v1.4h, #1          // d1>>1
    sshr      v9.4h, v3.4h, #1          // d3>>1

    add       v4.4h, v0.4h, v2.4h       // x0 = d0 + d2//
    sub       v5.4h, v0.4h, v2.4h       // x1 = d0 - d2//
    sub       v6.4h, v8.4h, v3.4h       // x2 = (d1 >> 1) -  d3//
    add       v7.4h, v1.4h, v9.4h       // x3 =  d1  + (d3 >>  1)//

    ld1       {v30.s}[1], [x1], x3      // ii row load pu1_pred buffer

    add       v10.4h, v4.4h , v7.4h     // x0+x3
    add       v11.4h, v5.4h , v6.4h     // x1+x2
    sub       v12.4h, v5.4h , v6.4h     // x1-x2
    sub       v13.4h, v4.4h , v7.4h

    ld1       {v31.s}[0], [x1], x3      // iii row load pu1_pred buf


    //Steps for Stage 2:
    //transopose
    trn1      v4.4h, v10.4h, v11.4h
    trn2      v5.4h, v10.4h, v11.4h
    trn1      v6.4h, v12.4h, v13.4h
    trn2      v7.4h, v12.4h, v13.4h

    trn1      v10.2s, v4.2s, v6.2s      // 0
    trn1      v11.2s, v5.2s, v7.2s      // 8
    trn2      v12.2s, v4.2s, v6.2s      // 4
    trn2      v13.2s, v5.2s, v7.2s
    //end transpose

    sshr      v18.4h, v11.4h, #1        // q0>>1
    sshr      v19.4h, v13.4h, #1        // q1>>1

    add       v14.4h, v10.4h, v12.4h    // x0 = q0 + q2//
    sub       v15.4h, v10.4h, v12.4h    // x1 = q0 - q2//
    sub       v16.4h, v18.4h, v13.4h    // x2 = (q1 >> 1) -  q3//
    add       v17.4h, v11.4h, v19.4h    // x3 = q1+ (q3 >> 3)//


    ld1       {v31.s}[1], [x1], x3      // iv row load pu1_pred buffer

    add       v20.4h, v14.4h, v17.4h    // x0 + x3
    add       v21.4h, v15.4h, v16.4h    // x1 + x2
    sub       v22.4h, v15.4h, v16.4h    // x1 - x2
    sub       v23.4h, v14.4h, v17.4h    // x0 - x3

    mov       v20.d[1], v21.d[0]
    mov       v22.d[1], v23.d[0]

    srshr     v20.8h, v20.8h, #6
    srshr     v22.8h, v22.8h, #6

    uaddw     v20.8h, v20.8h , v30.8b
    uaddw     v22.8h, v22.8h , v31.8b

    sqxtun    v0.8b, v20.8h
    sqxtun    v1.8b, v22.8h

    st1       {v0.s}[0], [x2], x4       //i row store the value
    st1       {v0.s}[1], [x2], x4       //ii row store the value
    st1       {v1.s}[0], [x2], x4       //iii row store the value
    st1       {v1.s}[1], [x2]           //iv row store the value

    pop_v_regs
    ret


///**
// *******************************************************************************
// *
// * @brief
// *  This function performs inverse quant and Inverse transform type Ci4 for 4*4 block
// *
// * @par Description:
// *  Performs inverse transform Ci4 and adds the residue to get the
// *  reconstructed block
// *
// * @param[in] pi2_src
// *  Input 4x4 coefficients
// *
// * @param[in] pu1_pred
// *  Prediction 4x4 block
// *
// * @param[out] pu1_out
// *  Output 4x4 block
// *
// * @param[in] u4_qp_div_6
// *     QP
// *
// * @param[in] pu2_weigh_mat
// * Pointer to weight matrix
// *
// * @param[in] pred_strd,
// *  Prediction stride
// *
// * @param[in] out_strd
// *  Output Stride
// *
// *@param[in] pi2_tmp
// * temporary buffer of size 1*16
// *
// * @param[in] pu2_iscal_mat
// * Pointer to the inverse quantization matrix
// *
// * @returns  Void
// *
// * @remarks
// *  None
// *
// *******************************************************************************
// */
//void ih264_iquant_itrans_recon_chroma_4x4(WORD16 *pi2_src,
//                                          UWORD8 *pu1_pred,
//                                          UWORD8 *pu1_out,
//                                          WORD32 pred_strd,
//                                          WORD32 out_strd,
//                                          const UWORD16 *pu2_iscal_mat,
//                                          const UWORD16 *pu2_weigh_mat,
//                                          UWORD32 u4_qp_div_6,
//                                          WORD32 *pi4_tmp
//                                          WORD16 *pi2_dc_src)
//**************Variables Vs Registers*****************************************
//x0 => *pi2_src
//x1 => *pu1_pred
//x2 => *pu1_out
//x3 =>  pred_strd
//x4 =>  out_strd
//x5 => *pu2_iscal_mat
//x6 => *pu2_weigh_mat
//x7 =>  u4_qp_div_6
//sp =>  pi4_tmp
//sp#8 => *pi2_dc_src

    .global ih264_iquant_itrans_recon_chroma_4x4_av8
ih264_iquant_itrans_recon_chroma_4x4_av8:

//VLD4.S16 is used because the pointer is incremented by SUB_BLK_WIDTH_4x4
//If the macro value changes need to change the instruction according to it.
//Only one shift is done in horizontal inverse because,
//if u4_qp_div_6 is lesser than 4 then shift value will be neagative and do negative left shift, in this case rnd_factor has value
//if u4_qp_div_6 is greater than 4 then shift value will be positive and do left shift, here rnd_factor is 0

//at the end of the fucntion, we could have moved 64 bits into heigher 64 bits of register and done further processing
//but it seem to give only reduce the number of instruction by 1. [Since a15 we saw add and sub to be very high throughput
//all instructions were taken as equal

    //reduce sp by 64
    push_v_regs

    dup       v30.4s, w7                //Populate the u4_qp_div_6 in Q15

    //was at sp + 8, hence now at sp+64+8 = sp+72
    ldr       x10, [sp, #72]            //Load alternate dc address

//=======================DEQUANT FROM HERE===================================

    ld4       {v20.4h - v23.4h}, [x5]   // load pu2_iscal_mat[i], i =0..15
    ld4       {v26.4h - v29.4h}, [x6]   // pu2_weigh_mat[i], i =0..15
    ld4       {v16.4h - v19.4h}, [x0]   // pi2_src_tmp[i], i =0..15


    mul       v20.4h, v20.4h, v26.4h    // x[i]=(scale[i] * dequant[i]) where i = 0..3
    mul       v21.4h, v21.4h, v27.4h    // x[i]=(scale[i] * dequant[i]) where i = 4..7
    mul       v22.4h, v22.4h, v28.4h    // x[i]=(scale[i] * dequant[i]) where i = 8..11
    mul       v23.4h, v23.4h, v29.4h    // x[i]=(scale[i] * dequant[i]) where i = 12..14

    smull     v0.4s, v16.4h, v20.4h     // q0  = p[i] = (x[i] * trns_coeff[i]) where i = 0..3
    smull     v2.4s, v17.4h, v21.4h     // q1  = p[i] = (x[i] * trns_coeff[i]) where i = 4..7
    smull     v4.4s, v18.4h, v22.4h     // q2  = p[i] = (x[i] * trns_coeff[i]) where i = 8..11
    smull     v6.4s, v19.4h, v23.4h     // q3  = p[i] = (x[i] * trns_coeff[i]) where i = 12..15

    sshl      v0.4s, v0.4s, v30.4s      // q0  = q[i] = (p[i] << (qp/6)) where i = 0..3
    sshl      v2.4s, v2.4s, v30.4s      // q1  = q[i] = (p[i] << (qp/6)) where i = 4..7
    sshl      v4.4s, v4.4s, v30.4s      // q2  = q[i] = (p[i] << (qp/6)) where i = 8..11
    sshl      v6.4s, v6.4s, v30.4s      // q3  = q[i] = (p[i] << (qp/6)) where i = 12..15

    sqrshrn   v0.4h, v0.4s, #0x4        // d0  = c[i] = ((q[i] + 32) >> 4) where i = 0..3
    sqrshrn   v1.4h, v2.4s, #0x4        // d1  = c[i] = ((q[i] + 32) >> 4) where i = 4..7
    sqrshrn   v2.4h, v4.4s, #0x4        // d2  = c[i] = ((q[i] + 32) >> 4) where i = 8..11
    sqrshrn   v3.4h, v6.4s, #0x4        // d3  = c[i] = ((q[i] + 32) >> 4) where i = 12..15

    ld1       {v0.h}[0], [x10]          // loads signed halfword pi2_dc_src[0]

    //========= PROCESS IDCT FROM HERE =======
    //Steps for Stage 1:
    //------------------

    sshr      v8.4h, v1.4h, #1          // d1>>1
    sshr      v9.4h, v3.4h, #1          // d3>>1

    add       v4.4h, v0.4h, v2.4h       // x0 = d0 + d2//
    sub       v5.4h, v0.4h, v2.4h       // x1 = d0 - d2//
    sub       v6.4h, v8.4h, v3.4h       // x2 = (d1 >> 1) -  d3//
    add       v7.4h, v1.4h, v9.4h       // x3 =  d1  + (d3 >>  1)//


    add       v10.4h, v4.4h , v7.4h     // x0+x3
    add       v11.4h, v5.4h , v6.4h     // x1+x2
    sub       v12.4h, v5.4h , v6.4h     // x1-x2
    sub       v13.4h, v4.4h , v7.4h

    ld1       {v26.8b}, [x1], x3        // i row load pu1_pred buffer
    ld1       {v27.8b}, [x1], x3        // ii row load pu1_pred buffer
    ld1       {v28.8b}, [x1], x3        // iii row load pu1_pred buf
    ld1       {v29.8b}, [x1], x3        // iv row load pu1_pred buffer

    //Steps for Stage 2:
    //transopose
    trn1      v4.4h, v10.4h, v11.4h
    trn2      v5.4h, v10.4h, v11.4h
    trn1      v6.4h, v12.4h, v13.4h
    trn2      v7.4h, v12.4h, v13.4h

    trn1      v10.2s, v4.2s, v6.2s      // 0
    trn1      v11.2s, v5.2s, v7.2s      // 8
    trn2      v12.2s, v4.2s, v6.2s      // 4
    trn2      v13.2s, v5.2s, v7.2s
    //end transpose

    sshr      v18.4h, v11.4h, #1        // q0>>1
    sshr      v19.4h, v13.4h, #1        // q1>>1

    add       v14.4h, v10.4h, v12.4h    // x0 = q0 + q2//
    sub       v15.4h, v10.4h, v12.4h    // x1 = q0 - q2//
    sub       v16.4h, v18.4h, v13.4h    // x2 = (q1 >> 1) -  q3//
    add       v17.4h, v11.4h, v19.4h    // x3 = q1+ (q3 >> 3)//

    //Backup the output addr
    mov       x0, x2

    //load outpt buufer for interleaving
    ld1       {v10.8b}, [x2], x4
    ld1       {v11.8b}, [x2], x4
    ld1       {v12.8b}, [x2], x4
    ld1       {v13.8b}, [x2]

    add       v20.4h, v14.4h, v17.4h    // x0 + x3
    add       v21.4h, v15.4h, v16.4h    // x1 + x2
    sub       v22.4h, v15.4h, v16.4h    // x1 - x2
    sub       v23.4h, v14.4h, v17.4h    // x0 - x3

    srshr     v20.4h, v20.4h, #6
    srshr     v21.4h, v21.4h, #6
    srshr     v22.4h, v22.4h, #6
    srshr     v23.4h, v23.4h, #6

    //nop       v30.8b                            //dummy for deinterleaving
    movi      v31.4h, #0x00ff           //mask for interleaving [copy lower 8 bits]

    //Extract u/v plane from interleaved data
    uzp1      v26.8b, v26.8b, v30.8b
    uzp1      v27.8b, v27.8b, v30.8b
    uzp1      v28.8b, v28.8b, v30.8b
    uzp1      v29.8b, v29.8b, v30.8b

    uaddw     v20.8h, v20.8h, v26.8b
    uaddw     v21.8h, v21.8h, v27.8b
    uaddw     v22.8h, v22.8h, v28.8b
    uaddw     v23.8h, v23.8h, v29.8b

    sqxtun    v0.8b, v20.8h
    sqxtun    v1.8b, v21.8h
    sqxtun    v2.8b, v22.8h
    sqxtun    v3.8b, v23.8h

    //long the output so that we have 0 at msb and value at lsb
    uxtl      v6.8h, v0.8b
    uxtl      v7.8h, v1.8b
    uxtl      v8.8h, v2.8b
    uxtl      v9.8h, v3.8b

    //select lsbs from proceesd data and msbs from pu1_out loaded data
    bit       v10.8b, v6.8b, v31.8b
    bit       v11.8b, v7.8b, v31.8b
    bit       v12.8b, v8.8b, v31.8b
    bit       v13.8b, v9.8b, v31.8b

    //store the interleaved result
    st1       {v10.8b}, [x0], x4
    st1       {v11.8b}, [x0], x4
    st1       {v12.8b}, [x0], x4
    st1       {v13.8b}, [x0]

    pop_v_regs
    ret

///*
// *******************************************************************************
// *
// * //brief
// *  This function performs inverse quant and Inverse transform type Ci4 for 8*8 block
// *
// * //par Description:
// *  Performs inverse transform Ci8 and adds the residue to get the
// *  reconstructed block
// *
// * //param[in] pi2_src
// *  Input 4x4 coefficients
// *
// * //param[in] pu1_pred
// *  Prediction 4x4 block
// *
// * //param[out] pu1_out
// *  Output 4x4 block
// *
// * //param[in] u4_qp_div_6
// *     QP
// *
// * //param[in] pu2_weigh_mat
// * Pointer to weight matrix
// *
// * //param[in] pred_strd,
// *  Prediction stride
// *
// * //param[in] out_strd
// *  Output Stride
// *
// *//param[in] pi2_tmp
// * temporary buffer of size 1*64
// *
// * //param[in] pu2_iscal_mat
// * Pointer to the inverse quantization matrix
// *
// * //returns  Void
// *
// * //remarks
// *  None
// *
// *******************************************************************************
// */
//void ih264_iquant_itrans_recon_8x8(WORD16 *pi2_src,
//                                   UWORD8 *pu1_pred,
//                                   UWORD8 *pu1_out,
//                                   WORD32 pred_strd,
//                                   WORD32 out_strd,
//                                   const UWORD16 *pu2_iscal_mat,
//                                   const UWORD16 *pu2_weigh_mat,
//                                   UWORD32 u4_qp_div_6,
//                                   WORD32 *pi4_tmp,
//                                   WORD32 iq_start_idx
//                                   WORD16 *pi2_dc_ld_addr)
//**************Variables Vs Registers*****************************************
//x0       => *pi2_src
//x1       => *pu1_pred
//x2       => *pu1_out
//x3       =>  pred_strd
//x4       =>  out_strd
//x5       =>  *pu2_iscal_mat
//x6       =>  *pu2_weigh_mat
//x7       =>  u4_qp_div_6
//NOT USED =>  pi4_tmp
//NOT USED =>  iq_start_idx
//NOT USED =>  pi2_dc_ld_addr

    .global ih264_iquant_itrans_recon_8x8_av8
ih264_iquant_itrans_recon_8x8_av8:

    push_v_regs

    ld1       {v8.8h -v11.8h}, [x5], #64
    ld1       {v12.8h-v15.8h}, [x5]

    ld1       {v16.8h -v19.8h}, [x6], #64
    ld1       {v20.8h -v23.8h}, [x6]

    mov       x8, #16
    ld1       {v0.8h}, [x0], x8
    ld1       {v1.8h}, [x0], x8
    ld1       {v2.8h}, [x0], x8
    ld1       {v3.8h}, [x0], x8
    ld1       {v4.8h}, [x0], x8
    ld1       {v5.8h}, [x0], x8
    ld1       {v6.8h}, [x0], x8
    ld1       {v7.8h}, [x0]

    mul       v8.8h, v8.8h, v16.8h
    mul       v9.8h, v9.8h, v17.8h
    mul       v10.8h, v10.8h, v18.8h
    mul       v11.8h, v11.8h, v19.8h
    mul       v12.8h, v12.8h, v20.8h
    mul       v13.8h, v13.8h, v21.8h
    mul       v14.8h, v14.8h, v22.8h
    mul       v15.8h, v15.8h, v23.8h

    smull     v16.4s, v0.4h, v8.4h
    smull2    v17.4s, v0.8h, v8.8h
    smull     v18.4s, v1.4h, v9.4h
    smull2    v19.4s, v1.8h, v9.8h
    smull     v20.4s, v2.4h, v10.4h
    smull2    v21.4s, v2.8h, v10.8h
    smull     v22.4s, v3.4h, v11.4h
    smull2    v23.4s, v3.8h, v11.8h
    smull     v24.4s, v4.4h, v12.4h
    smull2    v25.4s, v4.8h, v12.8h
    smull     v26.4s, v5.4h, v13.4h
    smull2    v27.4s, v5.8h, v13.8h
    smull     v28.4s, v6.4h, v14.4h
    smull2    v29.4s, v6.8h, v14.8h
    smull     v30.4s, v7.4h, v15.4h
    smull2    v31.4s, v7.8h, v15.8h

    dup       v0.4s, w7

    sshl      v16.4s, v16.4s, v0.4s
    sshl      v17.4s, v17.4s, v0.4s
    sshl      v18.4s, v18.4s, v0.4s
    sshl      v19.4s, v19.4s, v0.4s
    sshl      v20.4s, v20.4s, v0.4s
    sshl      v21.4s, v21.4s, v0.4s
    sshl      v22.4s, v22.4s, v0.4s
    sshl      v23.4s, v23.4s, v0.4s
    sshl      v24.4s, v24.4s, v0.4s
    sshl      v25.4s, v25.4s, v0.4s
    sshl      v26.4s, v26.4s, v0.4s
    sshl      v27.4s, v27.4s, v0.4s
    sshl      v28.4s, v28.4s, v0.4s
    sshl      v29.4s, v29.4s, v0.4s
    sshl      v30.4s, v30.4s, v0.4s
    sshl      v31.4s, v31.4s, v0.4s

    sqrshrn   v0.4h, v16.4s, #6
    sqrshrn2  v0.8h, v17.4s, #6
    sqrshrn   v1.4h, v18.4s, #6
    sqrshrn2  v1.8h, v19.4s, #6
    sqrshrn   v2.4h, v20.4s, #6
    sqrshrn2  v2.8h, v21.4s, #6
    sqrshrn   v3.4h, v22.4s, #6
    sqrshrn2  v3.8h, v23.4s, #6
    sqrshrn   v4.4h, v24.4s, #6
    sqrshrn2  v4.8h, v25.4s, #6
    sqrshrn   v5.4h, v26.4s, #6
    sqrshrn2  v5.8h, v27.4s, #6
    sqrshrn   v6.4h, v28.4s, #6
    sqrshrn2  v6.8h, v29.4s, #6
    sqrshrn   v7.4h, v30.4s, #6
    sqrshrn2  v7.8h, v31.4s, #6

    //loop counter
    mov       x8, #2
//1x8 transofORM
trans_1x8_1d:

    //transpose 8x8
    trn1      v8.8h, v0.8h, v1.8h
    trn2      v9.8h, v0.8h, v1.8h
    trn1      v10.8h, v2.8h, v3.8h
    trn2      v11.8h, v2.8h, v3.8h
    trn1      v12.8h, v4.8h, v5.8h
    trn2      v13.8h, v4.8h, v5.8h
    trn1      v14.8h, v6.8h, v7.8h
    trn2      v15.8h, v6.8h, v7.8h

    trn1      v0.4s, v8.4s, v10.4s
    trn2      v2.4s, v8.4s, v10.4s
    trn1      v1.4s, v9.4s, v11.4s
    trn2      v3.4s, v9.4s, v11.4s
    trn1      v4.4s, v12.4s, v14.4s
    trn2      v6.4s, v12.4s, v14.4s
    trn1      v5.4s, v13.4s, v15.4s
    trn2      v7.4s, v13.4s, v15.4s

    trn1      v8.2d, v0.2d, v4.2d       //0
    trn2      v12.2d, v0.2d, v4.2d      //1
    trn1      v9.2d, v1.2d, v5.2d       //2
    trn2      v13.2d, v1.2d, v5.2d      //3
    trn1      v10.2d, v2.2d, v6.2d      //4
    trn2      v14.2d, v2.2d, v6.2d      //5
    trn1      v11.2d, v3.2d, v7.2d      //6
    trn2      v15.2d, v3.2d, v7.2d      //7

    // 1 3 5 6 7
    sshr      v16.8h, v9.8h, #1         //(pi2_tmp_ptr[1] >> 1)
    sshr      v17.8h, v10.8h, #1        //(pi2_tmp_ptr[2] >> 1)
    sshr      v18.8h, v11.8h, #1        //(pi2_tmp_ptr[3] >> 1)
    sshr      v19.8h, v13.8h, #1        //(pi2_tmp_ptr[5] >> 1)
    sshr      v20.8h, v14.8h, #1        //(pi2_tmp_ptr[6] >> 1)
    sshr      v21.8h, v15.8h, #1        //(pi2_tmp_ptr[7] >> 1)

    add       v0.8h, v8.8h, v12.8h      // i_y0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[4] );
    sub       v2.8h, v8.8h, v12.8h      // i_y2 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[4] );

    sub       v4.8h, v17.8h, v14.8h     //i_y4 = ((pi2_tmp_ptr[2] >> 1) - pi2_tmp_ptr[6] );
    add       v6.8h, v10.8h, v20.8h     //i_y6 = (pi2_tmp_ptr[2] + (pi2_tmp_ptr[6] >> 1));

    //-w3 + w5
    ssubl     v22.4s, v13.4h, v11.4h
    ssubl2    v23.4s, v13.8h, v11.8h
    //w3 + w5
    saddl     v24.4s, v13.4h, v11.4h
    saddl2    v25.4s, v13.8h, v11.8h
    //-w1 + w7
    ssubl     v26.4s, v15.4h, v9.4h
    ssubl2    v27.4s, v15.8h, v9.8h
    //w1 + w7
    saddl     v28.4s, v15.4h, v9.4h
    saddl2    v29.4s, v15.8h, v9.8h

    //-w3 + w5 - w7
    ssubw     v22.4s, v22.4s, v15.4h
    ssubw2    v23.4s, v23.4s, v15.8h
    //w3 + w5 + w1
    saddw     v24.4s, v24.4s, v9.4h
    saddw2    v25.4s, v25.4s, v9.8h
    //-w1 + w7 + w5
    saddw     v26.4s, v26.4s, v13.4h
    saddw2    v27.4s, v27.4s, v13.8h
    //w1 + w7 - w3
    ssubw     v28.4s, v28.4s, v11.4h
    ssubw2    v29.4s, v29.4s, v11.8h

    //-w3 + w5 - w7 - (w7 >> 1)
    ssubw     v22.4s, v22.4s, v21.4h
    ssubw2    v23.4s, v23.4s, v21.8h
    //w3 + w5 + w1 + (w1 >> 1)
    saddw     v24.4s, v24.4s, v16.4h
    saddw2    v25.4s, v25.4s, v16.8h
    //-w1 + w7 + w5 + (w5 >> 1)
    saddw     v26.4s, v26.4s, v19.4h
    saddw2    v27.4s, v27.4s, v19.8h
    //w1 + w7 - w3 - (w3 >> 1)
    ssubw     v28.4s, v28.4s, v18.4h
    ssubw2    v29.4s, v29.4s, v18.8h

    xtn       v1.4h, v22.4s
    xtn2      v1.8h, v23.4s
    xtn       v3.4h, v28.4s
    xtn2      v3.8h, v29.4s
    xtn       v5.4h, v26.4s
    xtn2      v5.8h, v27.4s
    xtn       v7.4h, v24.4s
    xtn2      v7.8h, v25.4s

    sshr      v16.8h, v1.8h, #2         //(y1 >> 2)
    sshr      v17.8h, v3.8h, #2         //(y3 >> 2)
    sshr      v18.8h, v5.8h, #2         //(y5 >> 2)
    sshr      v19.8h, v7.8h, #2         //(y7 >> 2)

    add       v8.8h, v0.8h, v6.8h
    add       v9.8h, v1.8h, v19.8h
    add       v10.8h, v2.8h, v4.8h
    add       v11.8h, v3.8h, v18.8h
    sub       v12.8h, v2.8h, v4.8h
    sub       v13.8h, v17.8h, v5.8h
    sub       v14.8h, v0.8h, v6.8h
    sub       v15.8h, v7.8h, v16.8h

    add       v0.8h, v8.8h, v15.8h
    add       v1.8h, v10.8h, v13.8h
    add       v2.8h, v12.8h, v11.8h
    add       v3.8h, v14.8h, v9.8h
    sub       v4.8h, v14.8h, v9.8h
    sub       v5.8h, v12.8h, v11.8h
    sub       v6.8h, v10.8h, v13.8h
    sub       v7.8h, v8.8h, v15.8h

    subs      x8, x8, #1
    bne       trans_1x8_1d

    ld1       {v22.8b}, [x1], x3
    ld1       {v23.8b}, [x1], x3
    ld1       {v24.8b}, [x1], x3
    ld1       {v25.8b}, [x1], x3
    ld1       {v26.8b}, [x1], x3
    ld1       {v27.8b}, [x1], x3
    ld1       {v28.8b}, [x1], x3
    ld1       {v29.8b}, [x1]

    srshr     v0.8h, v0.8h, #6
    srshr     v1.8h, v1.8h, #6
    srshr     v2.8h, v2.8h, #6
    srshr     v3.8h, v3.8h, #6
    srshr     v4.8h, v4.8h, #6
    srshr     v5.8h, v5.8h, #6
    srshr     v6.8h, v6.8h, #6
    srshr     v7.8h, v7.8h, #6

    uaddw     v0.8h, v0.8h, v22.8b
    uaddw     v1.8h, v1.8h, v23.8b
    uaddw     v2.8h, v2.8h, v24.8b
    uaddw     v3.8h, v3.8h, v25.8b
    uaddw     v4.8h, v4.8h, v26.8b
    uaddw     v5.8h, v5.8h, v27.8b
    uaddw     v6.8h, v6.8h, v28.8b
    uaddw     v7.8h, v7.8h, v29.8b

    sqxtun    v0.8b, v0.8h
    sqxtun    v1.8b, v1.8h
    sqxtun    v2.8b, v2.8h
    sqxtun    v3.8b, v3.8h
    sqxtun    v4.8b, v4.8h
    sqxtun    v5.8b, v5.8h
    sqxtun    v6.8b, v6.8h
    sqxtun    v7.8b, v7.8h

    st1       {v0.8b}, [x2], x4
    st1       {v1.8b}, [x2], x4
    st1       {v2.8b}, [x2], x4
    st1       {v3.8b}, [x2], x4
    st1       {v4.8b}, [x2], x4
    st1       {v5.8b}, [x2], x4
    st1       {v6.8b}, [x2], x4
    st1       {v7.8b}, [x2]

    pop_v_regs
    ret