summaryrefslogtreecommitdiffstats
path: root/encoder/armv8/ime_distortion_metrics_av8.s
blob: 47c342540826f62e00119608b71884ec3c0f6b17 (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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
//******************************************************************************
//*
//* 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
//*/
//**

///**
//******************************************************************************
//*
//*
//* @brief
//*  This file contains definitions of routines that compute distortion
//*  between two macro/sub blocks of identical dimensions
//*
//* @author
//*  Ittiam
//*
//* @par List of Functions:
//*  - ime_compute_sad_16x16()
//*  - ime_compute_sad_8x8()
//*  - ime_compute_sad_4x4()
//*  - ime_compute_sad_16x8()
//*  - ime_compute_satqd_16x16_lumainter_av8()
//*
//* @remarks
//*  None
//*
//*******************************************************************************
//


///**
//******************************************************************************
//*
//* @brief computes distortion (SAD) between 2 16x16 blocks (fast mode)
//*
//* @par   Description
//*   This functions computes SAD between 2 16x16 blocks. There is a provision
//*   for early exit if the up-to computed SAD exceeds maximum allowed SAD. To
//*   compute the distortion of the entire block set u4_max_sad to USHRT_MAX.
//*
//* @param[in] pu1_src
//*  UWORD8 pointer to the source
//*
//* @param[out] pu1_dst
//*  UWORD8 pointer to the destination
//*
//* @param[in] src_strd
//*  integer source stride
//*
//* @param[in] dst_strd
//*  integer destination stride
//*
//* @param[in] i4_max_sad
//*  integer maximum allowed distortion
//*
//* @param[in] pi4_mb_distortion
//*  integer evaluated sad
//*
//* @remarks
//*
//******************************************************************************
//*/
.text
.p2align 2

.macro push_v_regs
    stp       d8, d9, [sp, #-16]!
    stp       d10, d11, [sp, #-16]!
    stp       d12, d13, [sp, #-16]!
    stp       d14, d15, [sp, #-16]!
.endm
.macro pop_v_regs
    ldp       d14, d15, [sp], #16
    ldp       d12, d13, [sp], #16
    ldp       d10, d11, [sp], #16
    ldp       d8, d9, [sp], #16
.endm

    .global ime_compute_sad_16x16_fast_av8
ime_compute_sad_16x16_fast_av8:
    push_v_regs
    lsl       x2, x2, #1
    lsl       x3, x3, #1

    mov       x6, #2
    movi      v30.8h, #0

core_loop_ime_compute_sad_16x16_fast_av8:

    ld1       {v0.16b}, [x0], x2
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x0], x2
    ld1       {v3.16b}, [x1], x3

    uabal     v30.8h, v0.8b, v1.8b
    uabal2    v30.8h, v0.16b, v1.16b

    uabal     v30.8h, v2.8b, v3.8b
    uabal2    v30.8h, v2.16b, v3.16b

    ld1       {v4.16b}, [x0], x2
    ld1       {v5.16b}, [x1], x3
    ld1       {v6.16b}, [x0], x2
    ld1       {v7.16b}, [x1], x3

    uabal     v30.8h, v4.8b, v5.8b
    uabal2    v30.8h, v4.16b, v5.16b

    uabal     v30.8h, v6.8b, v7.8b
    uabal2    v30.8h, v6.16b, v7.16b

    subs      x6, x6, #1
    bne       core_loop_ime_compute_sad_16x16_fast_av8


    addp      v30.8h, v30.8h, v30.8h
    uaddlp    v30.4s, v30.8h
    addp      v30.2s, v30.2s, v30.2s
    shl       v30.2s, v30.2s, #1

    st1       {v30.s}[0], [x5]
    pop_v_regs
    ret


///**
//******************************************************************************
//*
//*  @brief computes distortion (SAD) between 2 16x8  blocks
//*
//*
//*  @par   Description
//*   This functions computes SAD between 2 16x8 blocks. There is a provision
//*   for early exit if the up-to computed SAD exceeds maximum allowed SAD. To
//*   compute the distortion of the entire block set u4_max_sad to USHRT_MAX.
//*
//* @param[in] pu1_src
//*  UWORD8 pointer to the source
//*
//* @param[out] pu1_dst
//*  UWORD8 pointer to the destination
//*
//* @param[in] src_strd
//*  integer source stride
//*
//* @param[in] dst_strd
//*  integer destination stride
//*
//* @param[in] u4_max_sad
//*  integer maximum allowed distortion
//*
//* @param[in] pi4_mb_distortion
//*  integer evaluated sad
//*
//* @remarks
//*
//******************************************************************************
//*/
//
    .global ime_compute_sad_16x8_av8
ime_compute_sad_16x8_av8:

    //chheck what stride incremtn to use
    //earlier code did not have this lsl
    push_v_regs
    mov       x6, #2
    movi      v30.8h, #0

core_loop_ime_compute_sad_16x8_av8:

    ld1       {v0.16b}, [x0], x2
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x0], x2
    ld1       {v3.16b}, [x1], x3

    uabal     v30.8h, v0.8b, v1.8b
    uabal2    v30.8h, v0.16b, v1.16b

    uabal     v30.8h, v2.8b, v3.8b
    uabal2    v30.8h, v2.16b, v3.16b

    ld1       {v4.16b}, [x0], x2
    ld1       {v5.16b}, [x1], x3
    ld1       {v6.16b}, [x0], x2
    ld1       {v7.16b}, [x1], x3

    uabal     v30.8h, v4.8b, v5.8b
    uabal2    v30.8h, v4.16b, v5.16b

    uabal     v30.8h, v6.8b, v7.8b
    uabal2    v30.8h, v6.16b, v7.16b

    subs      x6, x6, #1
    bne       core_loop_ime_compute_sad_16x8_av8


    addp      v30.8h, v30.8h, v30.8h
    uaddlp    v30.4s, v30.8h
    addp      v30.2s, v30.2s, v30.2s

    st1       {v30.s}[0], [x5]
    pop_v_regs
    ret

///**
//******************************************************************************
//*
//* @brief computes distortion (SAD) between 2 16x16 blocks with early exit
//*
//* @par   Description
//*   This functions computes SAD between 2 16x16 blocks. There is a provision
//*   for early exit if the up-to computed SAD exceeds maximum allowed SAD. To
//*   compute the distortion of the entire block set u4_max_sad to USHRT_MAX.
//*
//* @param[in] pu1_src
//*  UWORD8 pointer to the source
//*
//* @param[out] pu1_dst
//*  UWORD8 pointer to the destination
//*
//* @param[in] src_strd
//*  integer source stride
//*
//* @param[in] dst_strd
//*  integer destination stride
//*
//* @param[in] i4_max_sad
//*  integer maximum allowed distortion
//*
//* @param[in] pi4_mb_distortion
//*  integer evaluated sad
//*
//* @remarks
//*
//******************************************************************************
//*/

    .global ime_compute_sad_16x16_ea8_av8
ime_compute_sad_16x16_ea8_av8:

    push_v_regs
    movi      v30.8h, #0

    add       x7, x0, x2
    add       x8, x1, x3

    lsl       x2, x2, #1
    lsl       x3, x3, #1

    ld1       {v0.16b}, [x0], x2
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x0], x2
    ld1       {v3.16b}, [x1], x3
    ld1       {v8.16b}, [x0], x2
    ld1       {v9.16b}, [x1], x3
    ld1       {v10.16b}, [x0], x2
    ld1       {v11.16b}, [x1], x3
    ld1       {v12.16b}, [x0], x2
    ld1       {v13.16b}, [x1], x3
    ld1       {v14.16b}, [x0], x2
    ld1       {v15.16b}, [x1], x3
    ld1       {v16.16b}, [x0], x2
    ld1       {v17.16b}, [x1], x3
    ld1       {v18.16b}, [x0], x2
    ld1       {v19.16b}, [x1], x3

    uabal     v30.8h, v0.8b, v1.8b
    uabal2    v30.8h, v0.16b, v1.16b

    uabal     v30.8h, v2.8b, v3.8b
    uabal2    v30.8h, v2.16b, v3.16b

    uabal     v30.8h, v8.8b, v9.8b
    uabal2    v30.8h, v8.16b, v9.16b

    uabal     v30.8h, v10.8b, v11.8b
    uabal2    v30.8h, v10.16b, v11.16b

    uabal     v30.8h, v12.8b, v13.8b
    uabal2    v30.8h, v12.16b, v13.16b

    uabal     v30.8h, v14.8b, v15.8b
    uabal2    v30.8h, v14.16b, v15.16b

    uabal     v30.8h, v16.8b, v17.8b
    uabal2    v30.8h, v16.16b, v17.16b

    uabal     v30.8h, v18.8b, v19.8b
    uabal2    v30.8h, v18.16b, v19.16b

    addp      v31.8h, v30.8h, v30.8h
    uaddlp    v31.4s, v31.8h
    addp      v31.2s, v31.2s, v31.2s
    mov       w6, v31.s[0]
    cmp       w6, w4
    bgt       end_func_16x16

    //do the stuff again
    ld1       {v0.16b}, [x7], x2
    ld1       {v1.16b}, [x8], x3
    ld1       {v2.16b}, [x7], x2
    ld1       {v3.16b}, [x8], x3
    ld1       {v8.16b}, [x7], x2
    ld1       {v9.16b}, [x8], x3
    ld1       {v10.16b}, [x7], x2
    ld1       {v11.16b}, [x8], x3
    ld1       {v12.16b}, [x7], x2
    ld1       {v13.16b}, [x8], x3
    ld1       {v14.16b}, [x7], x2
    ld1       {v15.16b}, [x8], x3
    ld1       {v16.16b}, [x7], x2
    ld1       {v17.16b}, [x8], x3
    ld1       {v18.16b}, [x7], x2
    ld1       {v19.16b}, [x8], x3

    uabal     v30.8h, v0.8b, v1.8b
    uabal2    v30.8h, v0.16b, v1.16b

    uabal     v30.8h, v2.8b, v3.8b
    uabal2    v30.8h, v2.16b, v3.16b

    uabal     v30.8h, v8.8b, v9.8b
    uabal2    v30.8h, v8.16b, v9.16b

    uabal     v30.8h, v10.8b, v11.8b
    uabal2    v30.8h, v10.16b, v11.16b

    uabal     v30.8h, v12.8b, v13.8b
    uabal2    v30.8h, v12.16b, v13.16b

    uabal     v30.8h, v14.8b, v15.8b
    uabal2    v30.8h, v14.16b, v15.16b

    uabal     v30.8h, v16.8b, v17.8b
    uabal2    v30.8h, v16.16b, v17.16b

    uabal     v30.8h, v18.8b, v19.8b
    uabal2    v30.8h, v18.16b, v19.16b

    addp      v31.8h, v30.8h, v30.8h
    uaddlp    v31.4s, v31.8h
    addp      v31.2s, v31.2s, v31.2s

end_func_16x16:
    st1       {v31.s}[0], [x5]
    pop_v_regs
    ret


///*
////---------------------------------------------------------------------------
//// Function Name      : ime_calculate_sad2_prog_av8()
////
//// Detail Description : This function find the sad values of 4 Progressive MBs
////                        at one shot
////
//// Platform           : CortexAv8/NEON            .
////
////-----------------------------------------------------------------------------
//*/

    .global ime_calculate_sad2_prog_av8
ime_calculate_sad2_prog_av8:

    // x0    = ref1     <UWORD8 *>
    // x1    = ref2     <UWORD8 *>
    // x2    = src     <UWORD8 *>
    // x3    = RefBufferWidth <UWORD32>
    // stack = CurBufferWidth <UWORD32>, psad <UWORD32 *>
    push_v_regs
    mov       x6, #8
    movi      v30.8h, #0
    movi      v31.8h, #0

core_loop_ime_calculate_sad2_prog_av8:

    ld1       {v0.16b}, [x0], x3
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x3], x4

    ld1       {v3.16b}, [x0], x3
    ld1       {v4.16b}, [x1], x3
    ld1       {v5.16b}, [x3], x4


    uabal     v30.8h, v0.8b, v2.8b
    uabal2    v30.8h, v0.16b, v2.16b
    uabal     v31.8h, v1.8b, v2.8b
    uabal2    v31.8h, v1.16b, v2.16b

    uabal     v30.8h, v3.8b, v5.8b
    uabal2    v30.8h, v3.16b, v5.16b
    uabal     v31.8h, v4.8b, v5.8b
    uabal2    v31.8h, v4.16b, v5.16b


    ld1       {v6.16b}, [x0], x3
    ld1       {v7.16b}, [x1], x3
    ld1       {v8.16b}, [x3], x4

    ld1       {v9.16b}, [x0], x3
    ld1       {v10.16b}, [x1], x3
    ld1       {v11.16b}, [x3], x4

    uabal     v30.8h, v6.8b, v8.8b
    uabal2    v30.8h, v6.16b, v8.16b
    uabal     v31.8h, v7.8b, v8.8b
    uabal2    v31.8h, v7.16b, v8.16b

    uabal     v30.8h, v9.8b, v11.8b
    uabal2    v30.8h, v9.16b, v11.16b
    uabal     v31.8h, v10.8b, v11.8b
    uabal2    v31.8h, v0.16b, v11.16b

    subs      x6, x6, #1
    bne       core_loop_ime_calculate_sad2_prog_av8

    addp      v30.8h, v30.8h, v31.8h
    uaddlp    v30.4s, v30.8h
    addp      v30.2s, v30.2s, v30.2s
    shl       v30.2s, v30.2s, #1

    st1       {v30.2s}, [x5]
    pop_v_regs
    ret

///*
////---------------------------------------------------------------------------
//// Function Name      : Calculate_Mad3_prog()
////
//// Detail Description : This function find the sad values of 4 Progressive MBs
////                        at one shot
////
//// Platform           : CortexA8/NEON            .
////
////-----------------------------------------------------------------------------
//*/

    .global ime_calculate_sad3_prog_av8
ime_calculate_sad3_prog_av8:

    // x0    = ref1     <UWORD8 *>
    // x1    = ref2     <UWORD8 *>
    // x2    = ref3     <UWORD8 *>
    // x3    = src     <UWORD8 *>
    // stack = RefBufferWidth <UWORD32>, CurBufferWidth <UWORD32>, psad <UWORD32 *>


    // x0    = ref1     <UWORD8 *>
    // x1    = ref2     <UWORD8 *>
    // x2    = src     <UWORD8 *>
    // x3    = RefBufferWidth <UWORD32>
    // stack = CurBufferWidth <UWORD32>, psad <UWORD32 *>
    push_v_regs
    mov       x6, #16
    movi      v29.8h, #0
    movi      v30.8h, #0
    movi      v31.8h, #0

core_loop_ime_calculate_sad3_prog_av8:

    ld1       {v0.16b}, [x0], x4
    ld1       {v1.16b}, [x1], x4
    ld1       {v2.16b}, [x2], x4
    ld1       {v3.16b}, [x3], x5

    uabal     v29.8h, v0.8b, v3.8b
    uabal2    v29.8h, v0.16b, v3.16b
    uabal     v30.8h, v1.8b, v3.8b
    uabal2    v30.8h, v1.16b, v3.16b
    uabal     v31.8h, v2.8b, v3.8b
    uabal2    v31.8h, v2.16b, v3.16b

    ld1       {v4.16b}, [x0], x4
    ld1       {v5.16b}, [x1], x4
    ld1       {v6.16b}, [x2], x4
    ld1       {v7.16b}, [x3], x5

    uabal     v29.8h, v4.8b, v7.8b
    uabal2    v29.8h, v4.16b, v7.16b
    uabal     v30.8h, v5.8b, v7.8b
    uabal2    v30.8h, v5.16b, v7.16b
    uabal     v31.8h, v6.8b, v7.8b
    uabal2    v31.8h, v6.16b, v7.16b

    subs      x6, x6, #1
    bne       core_loop_ime_calculate_sad2_prog_av8

    addp      v30.8h, v30.8h, v31.8h
    uaddlp    v30.4s, v30.8h
    addp      v30.2s, v30.2s, v30.2s
    shl       v30.2s, v30.2s, #1

    st1       {v30.2s}, [x5]
    pop_v_regs
    ret




///**
//******************************************************************************
//*
//* @brief computes distortion (SAD) for sub-pel motion estimation
//*
//* @par   Description
//*   This functions computes SAD for all the 8 half pel points
//*
//* @param[out] pi4_sad
//*  integer evaluated sad
//*  pi4_sad[0] - half x
//*  pi4_sad[1] - half x - 1
//*  pi4_sad[2] - half y
//*  pi4_sad[3] - half y - 1
//*  pi4_sad[4] - half xy
//*  pi4_sad[5] - half xy - 1
//*  pi4_sad[6] - half xy - strd
//*  pi4_sad[7] - half xy - 1 - strd
//*
//* @remarks
//*
//******************************************************************************
//*/

.text
.p2align 2

    .global ime_sub_pel_compute_sad_16x16_av8
ime_sub_pel_compute_sad_16x16_av8:
    push_v_regs
    sub       x7, x1, #1                //x left
    sub       x8, x2, x5                //y top
    sub       x9, x3, #1                //xy  left
    sub       x10, x3, x5               //xy top
    sub       x11, x10, #1              //xy top left

    movi      v24.8h, #0
    movi      v25.8h, #0
    movi      v26.8h, #0
    movi      v27.8h, #0
    movi      v28.8h, #0
    movi      v29.8h, #0
    movi      v30.8h, #0
    movi      v31.8h, #0

    mov       x12, #16
core_loop_ime_sub_pel_compute_sad_16x16_av8:

    ld1       {v0.16b}, [x0], x4        //src
    ld1       {v1.16b}, [x1], x5        //x
    ld1       {v2.16b}, [x7], x5        //x left
    ld1       {v3.16b}, [x2], x5        //y
    ld1       {v9.16b}, [x8], x5        //y top
    ld1       {v10.16b}, [x3], x5       //xy
    ld1       {v11.16b}, [x9], x5       //xy left
    ld1       {v12.16b}, [x10], x5      //xy top
    ld1       {v13.16b}, [x11], x5      //xy top left

    uabal     v24.8h, v0.8b, v1.8b
    uabal2    v24.8h, v0.16b, v1.16b
    uabal     v25.8h, v0.8b, v2.8b
    uabal2    v25.8h, v0.16b, v2.16b
    uabal     v26.8h, v0.8b, v3.8b
    uabal2    v26.8h, v0.16b, v3.16b
    uabal     v27.8h, v0.8b, v9.8b
    uabal2    v27.8h, v0.16b, v9.16b
    uabal     v28.8h, v0.8b, v10.8b
    uabal2    v28.8h, v0.16b, v10.16b
    uabal     v29.8h, v0.8b, v11.8b
    uabal2    v29.8h, v0.16b, v11.16b
    uabal     v30.8h, v0.8b, v12.8b
    uabal2    v30.8h, v0.16b, v12.16b
    uabal     v31.8h, v0.8b, v13.8b
    uabal2    v31.8h, v0.16b, v13.16b

    subs      x12, x12, #1
    bne       core_loop_ime_sub_pel_compute_sad_16x16_av8

    addp      v24.8h, v24.8h, v25.8h
    addp      v26.8h, v26.8h, v27.8h
    addp      v28.8h, v28.8h, v29.8h
    addp      v30.8h, v30.8h, v31.8h

    uaddlp    v24.4s, v24.8h
    uaddlp    v26.4s, v26.8h
    uaddlp    v28.4s, v28.8h
    uaddlp    v30.4s, v30.8h

    addp      v24.4s, v24.4s, v26.4s
    addp      v25.4s, v28.4s, v30.4s

    st1       {v24.4s-v25.4s}, [x6]


    pop_v_regs
    ret


///**
//******************************************************************************
//*
//* @brief computes distortion (SAD) between 2 16x16 blocks
//*
//* @par   Description
//*   This functions computes SAD between 2 16x16 blocks. There is a provision
//*   for early exit if the up-to computed SAD exceeds maximum allowed SAD. To
//*   compute the distortion of the entire block set u4_max_sad to USHRT_MAX.
//*
//* @param[in] pu1_src
//*  UWORD8 pointer to the source
//*
//* @param[out] pu1_dst
//*  UWORD8 pointer to the destination
//*
//* @param[in] src_strd
//*  integer source stride
//*
//* @param[in] dst_strd
//*  integer destination stride
//*
//* @param[in] i4_max_sad
//*  integer maximum allowed distortion
//*
//* @param[in] pi4_mb_distortion
//*  integer evaluated sad
//*
//* @remarks
//*
//******************************************************************************
//*/
    .global ime_compute_sad_16x16_av8
ime_compute_sad_16x16_av8:
    push_v_regs
    mov       x6, #4
    movi      v30.8h, #0

core_loop_ime_compute_sad_16x16_av8:

    ld1       {v0.16b}, [x0], x2
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x0], x2
    ld1       {v3.16b}, [x1], x3

    uabal     v30.8h, v0.8b, v1.8b
    uabal2    v30.8h, v0.16b, v1.16b

    uabal     v30.8h, v2.8b, v3.8b
    uabal2    v30.8h, v2.16b, v3.16b

    ld1       {v4.16b}, [x0], x2
    ld1       {v5.16b}, [x1], x3
    ld1       {v6.16b}, [x0], x2
    ld1       {v7.16b}, [x1], x3

    uabal     v30.8h, v4.8b, v5.8b
    uabal2    v30.8h, v4.16b, v5.16b

    uabal     v30.8h, v6.8b, v7.8b
    uabal2    v30.8h, v6.16b, v7.16b

    subs      x6, x6, #1
    bne       core_loop_ime_compute_sad_16x16_av8


    addp      v30.8h, v30.8h, v30.8h
    uaddlp    v30.4s, v30.8h
    addp      v30.2s, v30.2s, v30.2s

    st1       {v30.s}[0], [x5]
    pop_v_regs
    ret


///*
////---------------------------------------------------------------------------
//// Function Name      : Calculate_Mad4_prog()
////
//// Detail Description : This function find the sad values of 4 Progressive MBs
////                        at one shot
////
//// Platform           : CortexA8/NEON            .
////
////-----------------------------------------------------------------------------
//*/

    .global ime_calculate_sad4_prog_av8
ime_calculate_sad4_prog_av8:
    push_v_regs
    sub       x5, x0, #1                //left
    add       x6, x0, #1                //right
    sub       x7, x0, x2                //top
    add       x8, x0, x2                //bottom

    movi      v28.8h, #0
    movi      v29.8h, #0
    movi      v30.8h, #0
    movi      v31.8h, #0

    mov       x9, #16
core_loop_ime_calculate_sad4_prog_av8:

    ld1       {v0.16b}, [x1], x3
    ld1       {v1.16b}, [x5], x2
    ld1       {v2.16b}, [x6], x2
    ld1       {v3.16b}, [x7], x2
    ld1       {v9.16b}, [x8], x2

    uabal     v28.8h, v0.8b, v1.8b
    uabal2    v28.8h, v0.16b, v1.16b
    uabal     v29.8h, v0.8b, v2.8b
    uabal2    v29.8h, v0.16b, v2.16b
    uabal     v30.8h, v0.8b, v3.8b
    uabal2    v30.8h, v0.16b, v3.16b
    uabal     v31.8h, v0.8b, v9.8b
    uabal2    v31.8h, v0.16b, v9.16b

    subs      x9, x9, #1
    bne       core_loop_ime_calculate_sad4_prog_av8

    addp      v28.8h, v28.8h, v29.8h
    addp      v30.8h, v30.8h, v31.8h

    uaddlp    v28.4s, v28.8h
    uaddlp    v30.4s, v30.8h

    addp      v28.4s, v28.4s, v30.4s
    st1       {v28.4s}, [x4]
    pop_v_regs
    ret



//*****************************************************************************
//*
//* Function Name         : ime_compute_satqd_16x16_lumainter_av8
//* Description           : This fucntion computes SAD for a 16x16 block.
//                        : It also computes if any 4x4 block will have a nonzero coefficent after transform and quant
//
//  Arguments             :   x0 :pointer to src buffer
//                            x1 :pointer to est buffer
//                            x2 :source stride
//                            x3 :est stride
//                            STACk :Threshold,distotion,is_nonzero
//*
//* Values Returned   : NONE
//*
//* Register Usage    : x0-x11
//* Stack Usage       :
//* Cycles            : Around
//* Interruptiaility  : Interruptable
//*
//* Known Limitations
//*   \Assumptions    :
//*
//* Revision History  :
//*         DD MM YYYY    Author(s)           Changes
//*         14 04 2014    Harinarayanan K K  First version
//*
//*****************************************************************************
    .global ime_compute_satqd_16x16_lumainter_av8
ime_compute_satqd_16x16_lumainter_av8:
    //x0 :pointer to src buffer
    //x1 :pointer to est buffer
    //x2 :Source stride
    //x3 :Pred stride
    //x4 :Threshold pointer
    //x5 :Distortion,ie SAD
    //x6 :is nonzero
    //x7 :loop counter
    push_v_regs
    stp       d8, d9, [sp, #-16]!
    stp       d10, d11, [sp, #-16]!
    stp       d12, d13, [sp, #-16]!
    stp       d14, d15, [sp, #-16]!

    ld1       {v30.8h}, [x4]

    dup       v20.4h, v30.h[1]          //ls1
    dup       v24.4h, v30.h[0]          //ls2
    dup       v21.4h, v30.h[5]          //ls3
    dup       v25.4h, v30.h[7]          //ls4
    dup       v22.4h, v30.h[3]          //ls5
    dup       v26.4h, v30.h[4]          //ls6
    dup       v23.4h, v30.h[6]          //ls7
    dup       v27.4h, v30.h[2]          //ls8

    mov       v20.d[1], v24.d[0]
    mov       v21.d[1], v25.d[0]
    mov       v22.d[1], v26.d[0]
    mov       v23.d[1], v27.d[0]

    add       x4, x4, #16
    ld1       {v29.h}[0], [x4]
    dup       v29.4h, v29.h[0]

    movi      v31.8h, #0

    mov       x7, #4
core_loop_satqd_ime_compute_satqd_16x16_lumainter:
    ld1       {v0.16b}, [x0], x2
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x0], x2
    ld1       {v3.16b}, [x1], x3
    ld1       {v4.16b}, [x0], x2
    ld1       {v5.16b}, [x1], x3
    ld1       {v6.16b}, [x0], x2
    ld1       {v7.16b}, [x1], x3

    uabdl     v10.8h, v0.8b, v1.8b
    uabdl2    v15.8h, v0.16b, v1.16b
    uabdl     v11.8h, v2.8b, v3.8b
    uabdl2    v16.8h, v2.16b, v3.16b
    uabdl     v12.8h, v4.8b, v5.8b
    uabdl2    v17.8h, v4.16b, v5.16b
    uabdl     v13.8h, v6.8b, v7.8b
    uabdl2    v18.8h, v6.16b, v7.16b

    add       v0.8h, v10.8h, v13.8h
    add       v1.8h, v11.8h, v12.8h
    add       v2.8h, v15.8h, v18.8h
    add       v3.8h, v16.8h, v17.8h

    //v0 : S1     S4     S4     S1        A1    A4    A4    A1
    //v1 : S2     S3     S3     S2        A2    A3    A3    A2
    //v2 : B1     B4     B4     B1        X1    X4    X4    X1
    //v3 : B3     B2     B2     B3        X3    X2    X2    X3

    trn1      v4.8h, v0.8h, v1.8h
    trn2      v5.8h, v0.8h, v1.8h
    trn1      v6.8h, v2.8h, v3.8h
    trn2      v7.8h, v2.8h, v3.8h

    trn1      v0.4s, v4.4s, v6.4s
    trn2      v2.4s, v4.4s, v6.4s
    trn1      v1.4s, v5.4s, v7.4s
    trn2      v3.4s, v5.4s, v7.4s

    add       v4.8h, v0.8h, v3.8h
    add       v5.8h, v1.8h, v2.8h
    //v4 : S1     S2     B1     B2      A1    A2    X1    X2
    //v5 : S4     S3     B4     B3      A4    A3    X4    X3

    //compute sad for each 4x4 block
    add       v6.8h, v4.8h, v5.8h
    addp      v19.8h, v6.8h, v6.8h
    //duplicate the sad into 128 bit so that we can compare using 128bit
    add       v31.4h, v31.4h, v19.4h

    //sad_2 = sad_1<<1;
    shl       v28.8h, v19.8h, #1

    //sad_2 - pu2_thrsh
    sub       v24.8h, v28.8h, v20.8h
    sub       v25.8h, v28.8h, v21.8h
    sub       v26.8h, v28.8h, v22.8h
    sub       v27.8h, v28.8h, v23.8h

    trn1      v0.4s, v4.4s, v5.4s
    trn2      v1.4s, v4.4s, v5.4s
    //v0 : S1     S2     S4     S3      A1    A2    A4    A3
    //v1 : B1     B2     B4     B3      X1    X2    X4    X3

    trn1      v4.8h, v0.8h, v1.8h
    trn2      v5.8h, v0.8h, v1.8h
    //v4 : S1     B1     S4     B4      A1    X1    A4    X4
    //v5 : S2     B2     S3     B3      A2    X2    A3    X3

    mov       v7.s[0], v4.s[1]
    mov       v7.s[1], v4.s[3]
    mov       v6.s[0], v5.s[1]          // V4 //S1 B1 A1 X1
    mov       v6.s[1], v5.s[3]          // V5 //S2 B2 A2 X2
    mov       v4.s[1], v4.s[2]          // V6 //S3 B3 A3 X3
    mov       v5.s[1], v5.s[2]          // V7 //S4 B4 A4 X4

    shl       v0.4h, v4.4h, #1          //S1<<1
    shl       v1.4h, v5.4h, #1          //S2<<1
    shl       v2.4h, v6.4h, #1          //S3<<1
    shl       v3.4h, v7.4h, #1          //S4<<1

    add       v8.4h, v5.4h, v6.4h       //(s2[j] + s3[j]))
    add       v9.4h, v4.4h, v7.4h       //(s1[j] + s4[j]))
    add       v10.4h, v6.4h, v7.4h      //(s3[j] + s4[j]))
    sub       v11.4h, v6.4h, v0.4h      //(s3[j] - (s1[j]<<1))
    sub       v12.4h, v7.4h, v1.4h      //(s4[j] - (s2[j]<<1))
    add       v13.4h, v4.4h, v5.4h      //(s1[j] + s2[j]))
    sub       v14.4h, v5.4h, v3.4h      //(s2[j] - (s4[j]<<1)))
    sub       v15.4h, v4.4h, v2.4h      //(s1[j] - (s3[j]<<1)))

    mov       v8.d[1], v9.d[0]
    mov       v10.d[1], v11.d[0]
    mov       v12.d[1], v13.d[0]
    mov       v14.d[1], v15.d[0]

    cmge      v0.8h, v24.8h, v8.8h      //ls1 ls2
    cmge      v1.8h, v25.8h, v10.8h     //ls3 ls4
    cmge      v2.8h, v26.8h, v12.8h     //ls5 ls6
    cmge      v3.8h, v27.8h, v14.8h     //ls7 ls8
    cmge      v4.4h, v19.4h, v29.4h     //sad

    orr       v0.16b, v0.16b, v1.16b
    orr       v2.16b, v2.16b, v3.16b
    orr       v2.16b, v0.16b, v2.16b
    xtn       v2.8b, v2.8h
    orr       v2.8b, v2.8b, v4.8b

    //if the comparison is non zero, out
    mov       x4, v2.d[0]
    cmp       x4, #0
    bne       core_loop_compute_sad_pre

    subs      x7, x7, #1
    bne       core_loop_satqd_ime_compute_satqd_16x16_lumainter
    b         satdq_end_func


core_loop_compute_sad:
    ld1       {v0.16b}, [x0], x2
    ld1       {v1.16b}, [x1], x3
    ld1       {v2.16b}, [x0], x2
    ld1       {v3.16b}, [x1], x3

    uabal     v31.8h, v0.8b, v1.8b
    uabal2    v31.8h, v0.16b, v1.16b

    uabal     v31.8h, v2.8b, v3.8b
    uabal2    v31.8h, v2.16b, v3.16b

    ld1       {v4.16b}, [x0], x2
    ld1       {v5.16b}, [x1], x3
    ld1       {v6.16b}, [x0], x2
    ld1       {v7.16b}, [x1], x3

    uabal     v31.8h, v4.8b, v5.8b
    uabal2    v31.8h, v4.16b, v5.16b

    uabal     v31.8h, v6.8b, v7.8b
    uabal2    v31.8h, v6.16b, v7.16b

core_loop_compute_sad_pre:
    subs      x7, x7, #1
    bne       core_loop_compute_sad

satdq_end_func:

    mov       x7, #1
    cmp       x4, #0
    csel      x7, x4, x7, eq
    str       w7, [x6]

    addp      v31.8h, v31.8h, v31.8h
    uaddlp    v31.4s, v31.8h
    addp      v31.2s, v31.2s, v31.2s
    st1       {v31.s}[0], [x5]


    ldp       d14, d15, [sp], #16
    ldp       d12, d13, [sp], #16
    ldp       d10, d11, [sp], #16
    ldp       d8, d9, [sp], #16
    pop_v_regs
    ret