Skip to content

Latest commit

 

History

History
312 lines (281 loc) · 6.53 KB

synth_x86_64_s32.S

File metadata and controls

312 lines (281 loc) · 6.53 KB
 
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
/*
synth_x86_64_s32: SSE optimized synth for x86-64 (s32 output version)
copyright 1995-2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Taihei Monma
*/
#include "mangle.h"
#ifdef IS_MSABI
/* short *window; */
#define ARG0 %r10
/* short *b0; */
#define ARG1 %rdx
/* short *samples; */
#define ARG2 %r8
/* int bo1; */
#define ARG3 %r9
#else
/* real *window; */
#define ARG0 %rdi
/* real *b0; */
#define ARG1 %rsi
/* real *samples; */
#define ARG2 %rdx
/* int bo1; */
#define ARG3 %rcx
#endif
#define XMMREG_SCALE %xmm15 /* {65536.0, 65536.0, 65536.0, 65536.0} */
#define XMMREG_MAX %xmm14 /* {32767.999, 32767.999, 32767.999, 32767.999} */
#define XMMREG_MIN %xmm13 /* {-32768.0, -32768.0, -32768.0, -32768.0} */
#define XMMREG_CLIP %xmm12
/*
int synth_1to1_s32_x86_64_asm(real *window, real *b0, int32_t *samples, int bo1);
return value: number of clipped samples
*/
#ifndef __APPLE__
.section .rodata
#else
.data
#endif
ALIGN32
ASM_NAME(scale_s32):
.long 1199570944
.long 1199570944
.long 1199570944
.long 1199570944
ALIGN16
ASM_NAME(maxmin_s32):
.long 1191182335
.long 1191182335
.long 1191182335
.long 1191182335
.long -956301312
.long -956301312
.long -956301312
.long -956301312
.text
ALIGN16
.globl ASM_NAME(synth_1to1_s32_x86_64_asm)
ASM_NAME(synth_1to1_s32_x86_64_asm):
#ifdef IS_MSABI /* should save xmm6-15 */
movq %rcx, ARG0
subq $168, %rsp /* stack alignment + 10 xmm registers */
movaps %xmm6, (%rsp)
movaps %xmm7, 16(%rsp)
movaps %xmm8, 32(%rsp)
movaps %xmm9, 48(%rsp)
movaps %xmm10, 64(%rsp)
movaps %xmm11, 80(%rsp)
movaps %xmm12, 96(%rsp)
movaps %xmm13, 112(%rsp)
movaps %xmm14, 128(%rsp)
movaps %xmm15, 144(%rsp)
#endif
leaq ASM_NAME(scale_s32)(%rip), %rax
movaps (%rax), XMMREG_SCALE
leaq ASM_NAME(maxmin_s32)(%rip), %rax
movaps (%rax), XMMREG_MAX
movaps 16(%rax), XMMREG_MIN
xorps XMMREG_CLIP, XMMREG_CLIP
andq $0xf, ARG3
shlq $2, ARG3
leaq 64(ARG0), ARG0
subq ARG3, ARG0
movl $4, %ecx
ALIGN16
1:
movups (ARG0), %xmm8
movups 16(ARG0), %xmm1
movups 32(ARG0), %xmm2
movups 48(ARG0), %xmm3
movups 128(ARG0), %xmm9
movups 144(ARG0), %xmm5
movups 160(ARG0), %xmm6
movups 176(ARG0), %xmm7
mulps (ARG1), %xmm8
mulps 16(ARG1), %xmm1
mulps 32(ARG1), %xmm2
mulps 48(ARG1), %xmm3
mulps 64(ARG1), %xmm9
mulps 80(ARG1), %xmm5
mulps 96(ARG1), %xmm6
mulps 112(ARG1), %xmm7
addps %xmm1, %xmm8
addps %xmm2, %xmm3
addps %xmm5, %xmm9
addps %xmm7, %xmm6
addps %xmm3, %xmm8
addps %xmm6, %xmm9
leaq 256(ARG0), ARG0
leaq 128(ARG1), ARG1
movups (ARG0), %xmm10
movups 16(ARG0), %xmm1
movups 32(ARG0), %xmm2
movups 48(ARG0), %xmm3
movups 128(ARG0), %xmm11
movups 144(ARG0), %xmm5
movups 160(ARG0), %xmm6
movups 176(ARG0), %xmm7
mulps (ARG1), %xmm10
mulps 16(ARG1), %xmm1
mulps 32(ARG1), %xmm2
mulps 48(ARG1), %xmm3
mulps 64(ARG1), %xmm11
mulps 80(ARG1), %xmm5
mulps 96(ARG1), %xmm6
mulps 112(ARG1), %xmm7
addps %xmm1, %xmm10
addps %xmm2, %xmm3
addps %xmm5, %xmm11
addps %xmm7, %xmm6
addps %xmm3, %xmm10
addps %xmm6, %xmm11
leaq 256(ARG0), ARG0
leaq 128(ARG1), ARG1
movaps %xmm8, %xmm0
movaps %xmm10, %xmm1
unpcklps %xmm9, %xmm8
unpcklps %xmm11, %xmm10
unpckhps %xmm9, %xmm0
unpckhps %xmm11, %xmm1
movaps %xmm8, %xmm2
movaps %xmm0, %xmm3
movlhps %xmm10, %xmm8
movhlps %xmm2, %xmm10
movlhps %xmm1, %xmm0
movhlps %xmm3, %xmm1
subps %xmm10, %xmm8
subps %xmm1, %xmm0
addps %xmm8, %xmm0
movups (ARG2), %xmm1
movups 16(ARG2), %xmm2
movaps %xmm0, %xmm3
movaps %xmm0, %xmm4
mulps XMMREG_SCALE, %xmm0
cmpnleps XMMREG_MAX, %xmm3
cmpltps XMMREG_MIN, %xmm4
cvtps2dq %xmm0, %xmm0
xorps %xmm3, %xmm0
shufps $0xdd, %xmm2, %xmm1
movaps %xmm0, %xmm2
unpcklps %xmm1, %xmm0
unpckhps %xmm1, %xmm2
movups %xmm0, (ARG2)
movups %xmm2, 16(ARG2)
psrld $31, %xmm3
psrld $31, %xmm4
paddd %xmm4, %xmm3
paddd %xmm3, XMMREG_CLIP
leaq 32(ARG2), ARG2
decl %ecx
jnz 1b
movl $4, %ecx
ALIGN16
1:
movups (ARG0), %xmm8
movups 16(ARG0), %xmm1
movups 32(ARG0), %xmm2
movups 48(ARG0), %xmm3
movups 128(ARG0), %xmm9
movups 144(ARG0), %xmm5
movups 160(ARG0), %xmm6
movups 176(ARG0), %xmm7
mulps (ARG1), %xmm8
mulps 16(ARG1), %xmm1
mulps 32(ARG1), %xmm2
mulps 48(ARG1), %xmm3
mulps -64(ARG1), %xmm9
mulps -48(ARG1), %xmm5
mulps -32(ARG1), %xmm6
mulps -16(ARG1), %xmm7
addps %xmm1, %xmm8
addps %xmm2, %xmm3
addps %xmm5, %xmm9
addps %xmm7, %xmm6
addps %xmm3, %xmm8
addps %xmm6, %xmm9
leaq 256(ARG0), ARG0
leaq -128(ARG1), ARG1
movups (ARG0), %xmm10
movups 16(ARG0), %xmm1
movups 32(ARG0), %xmm2
movups 48(ARG0), %xmm3
movups 128(ARG0), %xmm11
movups 144(ARG0), %xmm5
movups 160(ARG0), %xmm6
movups 176(ARG0), %xmm7
mulps (ARG1), %xmm10
mulps 16(ARG1), %xmm1
mulps 32(ARG1), %xmm2
mulps 48(ARG1), %xmm3
mulps -64(ARG1), %xmm11
mulps -48(ARG1), %xmm5
mulps -32(ARG1), %xmm6
mulps -16(ARG1), %xmm7
addps %xmm1, %xmm10
addps %xmm2, %xmm3
addps %xmm5, %xmm11
addps %xmm7, %xmm6
addps %xmm3, %xmm10
addps %xmm6, %xmm11
leaq 256(ARG0), ARG0
leaq -128(ARG1), ARG1
movaps %xmm8, %xmm0
movaps %xmm10, %xmm1
unpcklps %xmm9, %xmm8
unpcklps %xmm11, %xmm10
unpckhps %xmm9, %xmm0
unpckhps %xmm11, %xmm1
movaps %xmm8, %xmm2
movaps %xmm0, %xmm3
movlhps %xmm10, %xmm8
movhlps %xmm2, %xmm10
movlhps %xmm1, %xmm0
movhlps %xmm3, %xmm1
addps %xmm10, %xmm8
addps %xmm1, %xmm0
addps %xmm8, %xmm0
movups (ARG2), %xmm1
movups 16(ARG2), %xmm2
movaps %xmm0, %xmm3
movaps %xmm0, %xmm4
mulps XMMREG_SCALE, %xmm0
cmpnleps XMMREG_MAX, %xmm3
cmpltps XMMREG_MIN, %xmm4
cvtps2dq %xmm0, %xmm0
xorps %xmm3, %xmm0
shufps $0xdd, %xmm2, %xmm1
movaps %xmm0, %xmm2
unpcklps %xmm1, %xmm0
unpckhps %xmm1, %xmm2
movups %xmm0, (ARG2)
movups %xmm2, 16(ARG2)
psrld $31, %xmm3
psrld $31, %xmm4
paddd %xmm4, %xmm3
paddd %xmm3, XMMREG_CLIP
leaq 32(ARG2), ARG2
decl %ecx
jnz 1b
pshuflw $0xee, XMMREG_CLIP, %xmm0
movhlps XMMREG_CLIP, %xmm1
pshuflw $0xee, %xmm1, %xmm2
paddd %xmm0, XMMREG_CLIP
paddd %xmm1, XMMREG_CLIP
paddd %xmm2, XMMREG_CLIP
movd XMMREG_CLIP, %eax
#ifdef IS_MSABI
movaps (%rsp), %xmm6
movaps 16(%rsp), %xmm7
movaps 32(%rsp), %xmm8
movaps 48(%rsp), %xmm9
movaps 64(%rsp), %xmm10
movaps 80(%rsp), %xmm11
movaps 96(%rsp), %xmm12
movaps 112(%rsp), %xmm13
movaps 128(%rsp), %xmm14
movaps 144(%rsp), %xmm15
addq $168, %rsp
#endif
ret
NONEXEC_STACK