2 ; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
12 %include "vpx_ports/x86_abi_support.asm"
14 %macro STACK_FRAME_CREATE
0
29 movsxd rax
, dword ptr arg
(2)
30 lea rcx
, [rsi
+ rax
*2]
32 %ifidn __OUTPUT_FORMAT__
,x64
44 %macro STACK_FRAME_DESTROY
0
55 %ifidn __OUTPUT_FORMAT__
,x64
61 ;void vp8_short_fdct4x4_sse2(short *input, short *output, int pitch)
62 global sym
(vp8_short_fdct4x4_sse2
)
63 sym
(vp8_short_fdct4x4_sse2
):
67 movq xmm0
, MMWORD
PTR[input
] ;03 02 01 00
68 movq xmm2
, MMWORD
PTR[input
+ pitch
] ;13 12 11 10
69 lea input
, [input
+2*pitch
]
70 movq xmm1
, MMWORD
PTR[input
] ;23 22 21 20
71 movq xmm3
, MMWORD
PTR[input
+ pitch
] ;33 32 31 30
73 punpcklqdq xmm0
, xmm2
;13 12 11 10 03 02 01 00
74 punpcklqdq xmm1
, xmm3
;33 32 31 30 23 22 21 20
77 punpckldq xmm0
, xmm1
;23 22 03 02 21 20 01 00
78 punpckhdq xmm2
, xmm1
;33 32 13 12 31 30 11 10
80 punpckldq xmm0
, xmm2
;31 21 30 20 11 10 01 00
81 pshufhw xmm1
, xmm1
, 0b1h ;22 23 02 03 xx xx xx xx
82 pshufhw xmm2
, xmm2
, 0b1h ;32 33 12 13 xx xx xx xx
84 punpckhdq xmm1
, xmm2
;32 33 22 23 12 13 02 03
86 paddw xmm0
, xmm1
;b1 a1 b1 a1 b1 a1 b1 a1
87 psubw xmm3
, xmm1
;c1 d1 c1 d1 c1 d1 c1 d1
88 psllw xmm0
, 3 ;b1 <<= 3 a1 <<= 3
89 psllw xmm3
, 3 ;c1 <<= 3 d1 <<= 3
92 pmaddwd xmm0
, XMMWORD
PTR[GLOBAL(_mult_add
)] ;a1 + b1
93 pmaddwd xmm1
, XMMWORD
PTR[GLOBAL(_mult_sub
)] ;a1 - b1
95 pmaddwd xmm3
, XMMWORD
PTR[GLOBAL(_5352_2217
)] ;c1*2217 + d1*5352
96 pmaddwd xmm4
, XMMWORD
PTR[GLOBAL(_2217_neg5352
)];d1*2217 - c1*5352
98 paddd xmm3
, XMMWORD
PTR[GLOBAL(_14500
)]
99 paddd xmm4
, XMMWORD
PTR[GLOBAL(_7500
)]
100 psrad xmm3
, 12 ;(c1 * 2217 + d1 * 5352 + 14500)>>12
101 psrad xmm4
, 12 ;(d1 * 2217 - c1 * 5352 + 7500)>>12
103 packssdw xmm0
, xmm1
;op[2] op[0]
104 packssdw xmm3
, xmm4
;op[3] op[1]
105 ; 23 22 21 20 03 02 01 00
107 ; 33 32 31 30 13 12 11 10
110 punpcklqdq xmm0
, xmm3
;13 12 11 10 03 02 01 00
111 punpckhqdq xmm2
, xmm3
;23 22 21 20 33 32 31 30
114 punpcklwd xmm0
, xmm2
;32 30 22 20 12 10 02 00
115 punpckhwd xmm3
, xmm2
;33 31 23 21 13 11 03 01
117 punpcklwd xmm0
, xmm3
;13 12 11 10 03 02 01 00
118 punpckhwd xmm2
, xmm3
;33 32 31 30 23 22 21 20
120 movdqa xmm5
, XMMWORD
PTR[GLOBAL(_7
)]
121 pshufd xmm2
, xmm2
, 04eh
123 paddw xmm0
, xmm2
;b1 b1 b1 b1 a1 a1 a1 a1
124 psubw xmm3
, xmm2
;c1 c1 c1 c1 d1 d1 d1 d1
126 pshufd xmm0
, xmm0
, 0d8h
;b1 b1 a1 a1 b1 b1 a1 a1
127 movdqa xmm2
, xmm3
;save d1 for compare
128 pshufd xmm3
, xmm3
, 0d8h
;c1 c1 d1 d1 c1 c1 d1 d1
129 pshuflw xmm0
, xmm0
, 0d8h
;b1 b1 a1 a1 b1 a1 b1 a1
130 pshuflw xmm3
, xmm3
, 0d8h
;c1 c1 d1 d1 c1 d1 c1 d1
131 pshufhw xmm0
, xmm0
, 0d8h
;b1 a1 b1 a1 b1 a1 b1 a1
132 pshufhw xmm3
, xmm3
, 0d8h
;c1 d1 c1 d1 c1 d1 c1 d1
134 pmaddwd xmm0
, XMMWORD
PTR[GLOBAL(_mult_add
)] ;a1 + b1
135 pmaddwd xmm1
, XMMWORD
PTR[GLOBAL(_mult_sub
)] ;a1 - b1
137 pxor xmm4
, xmm4
;zero out for compare
141 psrad xmm0
, 4 ;(a1 + b1 + 7)>>4
142 psrad xmm1
, 4 ;(a1 - b1 + 7)>>4
143 pandn xmm2
, XMMWORD
PTR[GLOBAL(_cmp_mask
)] ;clear upper,
144 ;and keep bit 0 of lower
147 pmaddwd xmm3
, XMMWORD
PTR[GLOBAL(_5352_2217
)] ;c1*2217 + d1*5352
148 pmaddwd xmm4
, XMMWORD
PTR[GLOBAL(_2217_neg5352
)] ;d1*2217 - c1*5352
149 paddd xmm3
, XMMWORD
PTR[GLOBAL(_12000
)]
150 paddd xmm4
, XMMWORD
PTR[GLOBAL(_51000
)]
151 packssdw xmm0
, xmm1
;op[8] op[0]
152 psrad xmm3
, 16 ;(c1 * 2217 + d1 * 5352 + 12000)>>16
153 psrad xmm4
, 16 ;(d1 * 2217 - c1 * 5352 + 51000)>>16
155 packssdw xmm3
, xmm4
;op[12] op[4]
157 paddw xmm3
, xmm2
;op[4] += (d1!=0)
158 punpcklqdq xmm0
, xmm3
;op[4] op[0]
159 punpckhqdq xmm1
, xmm3
;op[12] op[8]
161 movdqa XMMWORD
PTR[output
+ 0], xmm0
162 movdqa XMMWORD
PTR[output
+ 16], xmm1
166 ;void vp8_short_fdct8x4_sse2(short *input, short *output, int pitch)
167 global sym
(vp8_short_fdct8x4_sse2
)
168 sym
(vp8_short_fdct8x4_sse2
):
172 ; read the input data
173 movdqa xmm0
, [input
]
174 movdqa xmm2
, [input
+ pitch
]
175 lea input
, [input
+2*pitch
]
176 movdqa xmm4
, [input
]
177 movdqa xmm3
, [input
+ pitch
]
179 ; transpose for the first stage
180 movdqa xmm1
, xmm0
; 00 01 02 03 04 05 06 07
181 movdqa xmm5
, xmm4
; 20 21 22 23 24 25 26 27
183 punpcklwd xmm0
, xmm2
; 00 10 01 11 02 12 03 13
184 punpckhwd xmm1
, xmm2
; 04 14 05 15 06 16 07 17
186 punpcklwd xmm4
, xmm3
; 20 30 21 31 22 32 23 33
187 punpckhwd xmm5
, xmm3
; 24 34 25 35 26 36 27 37
189 movdqa xmm2
, xmm0
; 00 10 01 11 02 12 03 13
190 punpckldq xmm0
, xmm4
; 00 10 20 30 01 11 21 31
192 punpckhdq xmm2
, xmm4
; 02 12 22 32 03 13 23 33
194 movdqa xmm4
, xmm1
; 04 14 05 15 06 16 07 17
195 punpckldq xmm4
, xmm5
; 04 14 24 34 05 15 25 35
197 punpckhdq xmm1
, xmm5
; 06 16 26 36 07 17 27 37
198 movdqa xmm3
, xmm2
; 02 12 22 32 03 13 23 33
200 punpckhqdq xmm3
, xmm1
; 03 13 23 33 07 17 27 37
201 punpcklqdq xmm2
, xmm1
; 02 12 22 32 06 16 26 36
203 movdqa xmm1
, xmm0
; 00 10 20 30 01 11 21 31
204 punpcklqdq xmm0
, xmm4
; 00 10 20 30 04 14 24 34
206 punpckhqdq xmm1
, xmm4
; 01 11 21 32 05 15 25 35
217 paddw xmm0
, xmm3
; a1 = 0 + 3
218 paddw xmm1
, xmm2
; b1 = 1 + 2
220 psubw xmm4
, xmm2
; c1 = 1 - 2
221 psubw xmm5
, xmm3
; d1 = 0 - 3
230 movdqa xmm2
, xmm0
; a1
232 paddw xmm0
, xmm1
; op[0] = a1 + b1
233 psubw xmm2
, xmm1
; op[2] = a1 - b1
237 movdqa xmm1
, xmm5
; d1
238 punpcklwd xmm1
, xmm4
; c1 d1
239 punpckhwd xmm5
, xmm4
; c1 d1
244 pmaddwd xmm1
, XMMWORD
PTR[GLOBAL (_5352_2217
)] ; c1*2217 + d1*5352
245 pmaddwd xmm4
, XMMWORD
PTR[GLOBAL (_5352_2217
)] ; c1*2217 + d1*5352
247 pmaddwd xmm3
, XMMWORD
PTR[GLOBAL(_2217_neg5352
)] ; d1*2217 - c1*5352
248 pmaddwd xmm5
, XMMWORD
PTR[GLOBAL(_2217_neg5352
)] ; d1*2217 - c1*5352
250 paddd xmm1
, XMMWORD
PTR[GLOBAL(_14500
)]
251 paddd xmm4
, XMMWORD
PTR[GLOBAL(_14500
)]
252 paddd xmm3
, XMMWORD
PTR[GLOBAL(_7500
)]
253 paddd xmm5
, XMMWORD
PTR[GLOBAL(_7500
)]
255 psrad xmm1
, 12 ; (c1 * 2217 + d1 * 5352 + 14500)>>12
256 psrad xmm4
, 12 ; (c1 * 2217 + d1 * 5352 + 14500)>>12
257 psrad xmm3
, 12 ; (d1 * 2217 - c1 * 5352 + 7500)>>12
258 psrad xmm5
, 12 ; (d1 * 2217 - c1 * 5352 + 7500)>>12
260 packssdw xmm1
, xmm4
; op[1]
261 packssdw xmm3
, xmm5
; op[3]
264 ; transpose for the second stage
265 movdqa xmm4
, xmm0
; 00 10 20 30 04 14 24 34
266 movdqa xmm5
, xmm2
; 02 12 22 32 06 16 26 36
268 punpcklwd xmm0
, xmm1
; 00 01 10 11 20 21 30 31
269 punpckhwd xmm4
, xmm1
; 04 05 14 15 24 25 34 35
271 punpcklwd xmm2
, xmm3
; 02 03 12 13 22 23 32 33
272 punpckhwd xmm5
, xmm3
; 06 07 16 17 26 27 36 37
274 movdqa xmm1
, xmm0
; 00 01 10 11 20 21 30 31
275 punpckldq xmm0
, xmm2
; 00 01 02 03 10 11 12 13
277 punpckhdq xmm1
, xmm2
; 20 21 22 23 30 31 32 33
279 movdqa xmm2
, xmm4
; 04 05 14 15 24 25 34 35
280 punpckldq xmm2
, xmm5
; 04 05 06 07 14 15 16 17
282 punpckhdq xmm4
, xmm5
; 24 25 26 27 34 35 36 37
283 movdqa xmm3
, xmm1
; 20 21 22 23 30 31 32 33
285 punpckhqdq xmm3
, xmm4
; 30 31 32 33 34 35 36 37
286 punpcklqdq xmm1
, xmm4
; 20 21 22 23 24 25 26 27
288 movdqa xmm4
, xmm0
; 00 01 02 03 10 11 12 13
289 punpcklqdq xmm0
, xmm2
; 00 01 02 03 04 05 06 07
291 punpckhqdq xmm4
, xmm2
; 10 11 12 13 14 15 16 17
301 paddw xmm0
, xmm3
; a1 = 0 + 3
302 paddw xmm1
, xmm4
; b1 = 1 + 2
304 psubw xmm4
, xmm2
; c1 = 1 - 2
305 psubw xmm5
, xmm3
; d1 = 0 - 3
307 pxor xmm6
, xmm6
; zero out for compare
309 pcmpeqw xmm6
, xmm5
; d1 != 0
311 pandn xmm6
, XMMWORD
PTR[GLOBAL(_cmp_mask8x4
)] ; clear upper,
312 ; and keep bit 0 of lower
315 movdqa xmm2
, xmm0
; a1
317 paddw xmm0
, xmm1
; a1 + b1
318 psubw xmm2
, xmm1
; a1 - b1
320 paddw xmm0
, XMMWORD
PTR[GLOBAL(_7w
)]
321 paddw xmm2
, XMMWORD
PTR[GLOBAL(_7w
)]
323 psraw xmm0
, 4 ; op[0] = (a1 + b1 + 7)>>4
324 psraw xmm2
, 4 ; op[8] = (a1 - b1 + 7)>>4
328 movdqa xmm1
, xmm5
; d1
329 punpcklwd xmm1
, xmm4
; c1 d1
330 punpckhwd xmm5
, xmm4
; c1 d1
335 pmaddwd xmm1
, XMMWORD
PTR[GLOBAL (_5352_2217
)] ; c1*2217 + d1*5352
336 pmaddwd xmm4
, XMMWORD
PTR[GLOBAL (_5352_2217
)] ; c1*2217 + d1*5352
338 pmaddwd xmm3
, XMMWORD
PTR[GLOBAL(_2217_neg5352
)] ; d1*2217 - c1*5352
339 pmaddwd xmm5
, XMMWORD
PTR[GLOBAL(_2217_neg5352
)] ; d1*2217 - c1*5352
341 paddd xmm1
, XMMWORD
PTR[GLOBAL(_12000
)]
342 paddd xmm4
, XMMWORD
PTR[GLOBAL(_12000
)]
343 paddd xmm3
, XMMWORD
PTR[GLOBAL(_51000
)]
344 paddd xmm5
, XMMWORD
PTR[GLOBAL(_51000
)]
346 psrad xmm1
, 16 ; (c1 * 2217 + d1 * 5352 + 14500)>>16
347 psrad xmm4
, 16 ; (c1 * 2217 + d1 * 5352 + 14500)>>16
348 psrad xmm3
, 16 ; (d1 * 2217 - c1 * 5352 + 7500)>>16
349 psrad xmm5
, 16 ; (d1 * 2217 - c1 * 5352 + 7500)>>16
351 packssdw xmm1
, xmm4
; op[4]
352 packssdw xmm3
, xmm5
; op[12]
354 paddw xmm1
, xmm6
; op[4] += (d1!=0)
359 punpcklqdq xmm0
, xmm1
360 punpckhqdq xmm4
, xmm1
362 punpcklqdq xmm2
, xmm3
363 punpckhqdq xmm5
, xmm3
365 movdqa XMMWORD
PTR[output
+ 0 ], xmm0
366 movdqa XMMWORD
PTR[output
+ 16], xmm2
367 movdqa XMMWORD
PTR[output
+ 32], xmm4
368 movdqa XMMWORD
PTR[output
+ 48], xmm5