Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / vp8 / common / arm / neon / idct_dequant_full_2x_neon.asm
1 ;
2 ;  Copyright (c) 2010 The Webm project authors. All Rights Reserved.
3 ;
4 ;  Use of this source code is governed by a BSD-style license
5 ;  that can be found in the LICENSE file in the root of the source
6 ;  tree. An additional intellectual property rights grant can be found
7 ;  in the file PATENTS.  All contributing project authors may
8 ;  be found in the AUTHORS file in the root of the source tree.
9 ;
10
11
12     EXPORT  |idct_dequant_full_2x_neon|
13     ARM
14     REQUIRE8
15     PRESERVE8
16
17     AREA ||.text||, CODE, READONLY, ALIGN=2
18 ;void idct_dequant_full_2x_neon(short *q, short *dq,
19 ;                               unsigned char *dst, int stride);
20 ; r0    *q,
21 ; r1    *dq,
22 ; r2    *dst
23 ; r3    stride
24 |idct_dequant_full_2x_neon| PROC
25     vld1.16         {q0, q1}, [r1]          ; dq (same l/r)
26     vld1.16         {q2, q3}, [r0]          ; l q
27     add             r0, r0, #32
28     vld1.16         {q4, q5}, [r0]          ; r q
29     add             r12, r2, #4
30
31     ; interleave the predictors
32     vld1.32         {d28[0]}, [r2],  r3     ; l pre
33     vld1.32         {d28[1]}, [r12], r3     ; r pre
34     vld1.32         {d29[0]}, [r2],  r3
35     vld1.32         {d29[1]}, [r12], r3
36     vld1.32         {d30[0]}, [r2],  r3
37     vld1.32         {d30[1]}, [r12], r3
38     vld1.32         {d31[0]}, [r2],  r3
39     vld1.32         {d31[1]}, [r12]
40
41     adr             r1, cospi8sqrt2minus1   ; pointer to the first constant
42
43     ; dequant: q[i] = q[i] * dq[i]
44     vmul.i16        q2, q2, q0
45     vmul.i16        q3, q3, q1
46     vmul.i16        q4, q4, q0
47     vmul.i16        q5, q5, q1
48
49     vld1.16         {d0}, [r1]
50
51     ; q2: l0r0  q3: l8r8
52     ; q4: l4r4  q5: l12r12
53     vswp            d5, d8
54     vswp            d7, d10
55
56     ; _CONSTANTS_ * 4,12 >> 16
57     ; q6:  4 * sinpi : c1/temp1
58     ; q7: 12 * sinpi : d1/temp2
59     ; q8:  4 * cospi
60     ; q9: 12 * cospi
61     vqdmulh.s16     q6, q4, d0[2]           ; sinpi8sqrt2
62     vqdmulh.s16     q7, q5, d0[2]
63     vqdmulh.s16     q8, q4, d0[0]           ; cospi8sqrt2minus1
64     vqdmulh.s16     q9, q5, d0[0]
65
66     vqadd.s16       q10, q2, q3             ; a1 = 0 + 8
67     vqsub.s16       q11, q2, q3             ; b1 = 0 - 8
68
69     ; vqdmulh only accepts signed values. this was a problem because
70     ; our constant had the high bit set, and was treated as a negative value.
71     ; vqdmulh also doubles the value before it shifts by 16. we need to
72     ; compensate for this. in the case of sinpi8sqrt2, the lowest bit is 0,
73     ; so we can shift the constant without losing precision. this avoids
74     ; shift again afterward, but also avoids the sign issue. win win!
75     ; for cospi8sqrt2minus1 the lowest bit is 1, so we lose precision if we
76     ; pre-shift it
77     vshr.s16        q8, q8, #1
78     vshr.s16        q9, q9, #1
79
80     ; q4:  4 +  4 * cospi : d1/temp1
81     ; q5: 12 + 12 * cospi : c1/temp2
82     vqadd.s16       q4, q4, q8
83     vqadd.s16       q5, q5, q9
84
85     ; c1 = temp1 - temp2
86     ; d1 = temp1 + temp2
87     vqsub.s16       q2, q6, q5
88     vqadd.s16       q3, q4, q7
89
90     ; [0]: a1+d1
91     ; [1]: b1+c1
92     ; [2]: b1-c1
93     ; [3]: a1-d1
94     vqadd.s16       q4, q10, q3
95     vqadd.s16       q5, q11, q2
96     vqsub.s16       q6, q11, q2
97     vqsub.s16       q7, q10, q3
98
99     ; rotate
100     vtrn.32         q4, q6
101     vtrn.32         q5, q7
102     vtrn.16         q4, q5
103     vtrn.16         q6, q7
104     ; idct loop 2
105     ; q4: l 0, 4, 8,12 r 0, 4, 8,12
106     ; q5: l 1, 5, 9,13 r 1, 5, 9,13
107     ; q6: l 2, 6,10,14 r 2, 6,10,14
108     ; q7: l 3, 7,11,15 r 3, 7,11,15
109
110     ; q8:  1 * sinpi : c1/temp1
111     ; q9:  3 * sinpi : d1/temp2
112     ; q10: 1 * cospi
113     ; q11: 3 * cospi
114     vqdmulh.s16     q8, q5, d0[2]           ; sinpi8sqrt2
115     vqdmulh.s16     q9, q7, d0[2]
116     vqdmulh.s16     q10, q5, d0[0]          ; cospi8sqrt2minus1
117     vqdmulh.s16     q11, q7, d0[0]
118
119     vqadd.s16       q2, q4, q6             ; a1 = 0 + 2
120     vqsub.s16       q3, q4, q6             ; b1 = 0 - 2
121
122     ; see note on shifting above
123     vshr.s16        q10, q10, #1
124     vshr.s16        q11, q11, #1
125
126     ; q10: 1 + 1 * cospi : d1/temp1
127     ; q11: 3 + 3 * cospi : c1/temp2
128     vqadd.s16       q10, q5, q10
129     vqadd.s16       q11, q7, q11
130
131     ; q8: c1 = temp1 - temp2
132     ; q9: d1 = temp1 + temp2
133     vqsub.s16       q8, q8, q11
134     vqadd.s16       q9, q10, q9
135
136     ; a1+d1
137     ; b1+c1
138     ; b1-c1
139     ; a1-d1
140     vqadd.s16       q4, q2, q9
141     vqadd.s16       q5, q3, q8
142     vqsub.s16       q6, q3, q8
143     vqsub.s16       q7, q2, q9
144
145     ; +4 >> 3 (rounding)
146     vrshr.s16       q4, q4, #3              ; lo
147     vrshr.s16       q5, q5, #3
148     vrshr.s16       q6, q6, #3              ; hi
149     vrshr.s16       q7, q7, #3
150
151     vtrn.32         q4, q6
152     vtrn.32         q5, q7
153     vtrn.16         q4, q5
154     vtrn.16         q6, q7
155
156     ; adding pre
157     ; input is still packed. pre was read interleaved
158     vaddw.u8        q4, q4, d28
159     vaddw.u8        q5, q5, d29
160     vaddw.u8        q6, q6, d30
161     vaddw.u8        q7, q7, d31
162
163     vmov.i16        q14, #0
164     vmov            q15, q14
165     vst1.16         {q14, q15}, [r0]        ; write over high input
166     sub             r0, r0, #32
167     vst1.16         {q14, q15}, [r0]        ; write over low input
168
169     sub             r2, r2, r3, lsl #2      ; dst - 4*stride
170     add             r1, r2, #4              ; hi
171
172     ;saturate and narrow
173     vqmovun.s16     d0, q4                  ; lo
174     vqmovun.s16     d1, q5
175     vqmovun.s16     d2, q6                  ; hi
176     vqmovun.s16     d3, q7
177
178     vst1.32         {d0[0]}, [r2], r3       ; lo
179     vst1.32         {d0[1]}, [r1], r3       ; hi
180     vst1.32         {d1[0]}, [r2], r3
181     vst1.32         {d1[1]}, [r1], r3
182     vst1.32         {d2[0]}, [r2], r3
183     vst1.32         {d2[1]}, [r1], r3
184     vst1.32         {d3[0]}, [r2]
185     vst1.32         {d3[1]}, [r1]
186
187     bx             lr
188
189     ENDP           ; |idct_dequant_full_2x_neon|
190
191 ; Constant Pool
192 cospi8sqrt2minus1 DCD 0x4e7b
193 ; because the lowest bit in 0x8a8c is 0, we can pre-shift this
194 sinpi8sqrt2       DCD 0x4546
195
196     END