xref: /aosp_15_r20/external/libaom/av1/encoder/x86/error_sse2.asm (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1;
2; Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3;
4; This source code is subject to the terms of the BSD 2 Clause License and
5; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6; was not distributed with this source code in the LICENSE file, you can
7; obtain it at www.aomedia.org/license/software. If the Alliance for Open
8; Media Patent License 1.0 was not distributed with this source code in the
9; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10;
11
12;
13
14; Increment %1 by sizeof() tran_low_t * %2.
15%macro INCREMENT_ELEMENTS_TRAN_LOW 2
16  lea %1, [%1 + %2 * 4]
17%endmacro
18
19; Load %2 + %3 into m%1.
20; %3 is the offset in elements, not bytes.
21; If tran_low_t is 16 bits (low bit depth configuration) then load the value
22; directly. If tran_low_t is 32 bits (high bit depth configuration) then pack
23; the values down to 16 bits.
24%macro LOAD_TRAN_LOW 3
25  mova     m%1, [%2 + (%3) * 4]
26  packssdw m%1, [%2 + (%3) * 4 + 16]
27%endmacro
28
29%define private_prefix av1
30
31%include "third_party/x86inc/x86inc.asm"
32
33SECTION .text
34
35; int64_t av1_block_error(int16_t *coeff, int16_t *dqcoeff, intptr_t block_size,
36;                         int64_t *ssz)
37
38INIT_XMM sse2
39cglobal block_error, 3, 3, 8, uqc, dqc, size, ssz
40  pxor      m4, m4                 ; sse accumulator
41  pxor      m6, m6                 ; ssz accumulator
42  pxor      m5, m5                 ; dedicated zero register
43.loop:
44  LOAD_TRAN_LOW 2, uqcq, 0
45  LOAD_TRAN_LOW 0, dqcq, 0
46  LOAD_TRAN_LOW 3, uqcq, 8
47  LOAD_TRAN_LOW 1, dqcq, 8
48  INCREMENT_ELEMENTS_TRAN_LOW uqcq, 16
49  INCREMENT_ELEMENTS_TRAN_LOW dqcq, 16
50  sub    sizeq, 16
51  psubw     m0, m2
52  psubw     m1, m3
53  ; individual errors are max. 15bit+sign, so squares are 30bit, and
54  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit)
55  pmaddwd   m0, m0
56  pmaddwd   m1, m1
57  pmaddwd   m2, m2
58  pmaddwd   m3, m3
59  ; the sum of 2 31bit integers will fit in a 32bit unsigned integer
60  paddd     m0, m1
61  paddd     m2, m3
62  ; accumulate in 64bit
63  punpckldq m7, m0, m5
64  punpckhdq m0, m5
65  paddq     m4, m7
66  punpckldq m7, m2, m5
67  paddq     m4, m0
68  punpckhdq m2, m5
69  paddq     m6, m7
70  paddq     m6, m2
71  jg .loop
72
73  ; accumulate horizontally and store in return value
74  movhlps   m5, m4
75  movhlps   m7, m6
76  paddq     m4, m5
77  paddq     m6, m7
78%if AOM_ARCH_X86_64
79  movq    rax, m4
80  movq [sszq], m6
81%else
82  mov     eax, sszm
83  pshufd   m5, m4, 0x1
84  movq  [eax], m6
85  movd    eax, m4
86  movd    edx, m5
87%endif
88  RET
89