| 1 |
/* |
| 2 |
decode_3dnow.s - 3DNow! optimized synth_1to1() |
| 3 |
|
| 4 |
copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1 |
| 5 |
see COPYING and AUTHORS files in distribution or http://mpg123.org |
| 6 |
initially written by Syuuhei Kashiyama |
| 7 |
|
| 8 |
This code based 'decode_3dnow.s' by Syuuhei Kashiyama |
| 9 |
<[email protected]>,only two types of changes have been made: |
| 10 |
|
| 11 |
- remove PREFETCH instruction for speedup |
| 12 |
- change function name for support 3DNow! automatic detect |
| 13 |
- femms moved to before 'call dct64_3dnow' |
| 14 |
|
| 15 |
You can find Kashiyama's original 3dnow! support patch |
| 16 |
(for mpg123-0.59o) at |
| 17 |
http://user.ecc.u-tokyo.ac.jp/~g810370/linux-simd/ (Japanese). |
| 18 |
|
| 19 |
by KIMURA Takuhiro <[email protected]> - until 31.Mar.1999 |
| 20 |
<[email protected]> - after 1.Apr.1999 |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
Replacement of synth_1to1() with AMD's 3DNow! SIMD operations support |
| 25 |
|
| 26 |
Syuuhei Kashiyama <[email protected]> |
| 27 |
|
| 28 |
The author of this program disclaim whole expressed or implied |
| 29 |
warranties with regard to this program, and in no event shall the |
| 30 |
author of this program liable to whatever resulted from the use of |
| 31 |
this program. Use it at your own risk. |
| 32 |
*/ |
| 33 |
|
| 34 |
#include "mangle.h" |
| 35 |
|
| 36 |
#ifdef ACCURATE_ROUNDING |
| 37 |
RODATA |
| 38 |
ALIGN8 |
| 39 |
max_s16: |
| 40 |
.long 1191181824 /* 32767.0 */ |
| 41 |
.long 1191181824 |
| 42 |
min_s16: |
| 43 |
.long -956301312 /* -32768.0 */ |
| 44 |
.long -956301312 |
| 45 |
ftoi_magic: |
| 46 |
.long 1262485504 /* 2^23 + 2^22 */ |
| 47 |
.long 1262485504 |
| 48 |
#endif |
| 49 |
.text |
| 50 |
ALIGN16 |
| 51 |
.globl ASM_NAME(INT123_synth_1to1_3dnow_asm) |
| 52 |
/* int synth_1to1_3dnow_asm(real *bandPtr, int channel, unsigned char *out, unsigned char *buffs, int *bo, real *decwin); */ |
| 53 |
ASM_NAME(INT123_synth_1to1_3dnow_asm): |
| 54 |
subl $24,%esp |
| 55 |
pushl %ebp |
| 56 |
pushl %edi |
| 57 |
xorl %ebp,%ebp |
| 58 |
pushl %esi |
| 59 |
pushl %ebx |
| 60 |
/* stack old: 0=ebx 4=esi 8=edi 12=ebp 16,20,24,28,32,36=local 40=back 44=bandptr 48=channel 52=out 56=pnt */ |
| 61 |
/* stack new: 0=ebx 4=esi 8=edi 12=ebp 16,20,24,28,32,36=local 40=back 44=bandptr 48=channel 52=out 56=buffs 60=bo 64=decwin */ |
| 62 |
#define OUT 52(%esp) |
| 63 |
#define CHANNEL 48(%esp) |
| 64 |
#define BANDPTR 44(%esp) |
| 65 |
#define BUFFS 56(%esp) |
| 66 |
#define BO 60(%esp) |
| 67 |
#define DECWIN 64(%esp) |
| 68 |
#define LOCAL0 16(%esp) |
| 69 |
#define LOCAL1 20(%esp) |
| 70 |
#define EBXSAVE 24(%esp) |
| 71 |
#define LOCAL5 36(%esp) |
| 72 |
|
| 73 |
#ifdef ACCURATE_ROUNDING |
| 74 |
#undef _EBX_ |
| 75 |
#define _EBX_ %eax |
| 76 |
GET_GOT |
| 77 |
/* FIXME */ |
| 78 |
#if PIC |
| 79 |
movl _EBX_, EBXSAVE |
| 80 |
#endif |
| 81 |
#endif |
| 82 |
movl OUT,%esi |
| 83 |
movl %esi,LOCAL0 /* save buffer start (samples pointer) to another local var */ |
| 84 |
movl CHANNEL,%ebx |
| 85 |
movl BO,%esi /* bo address */ |
| 86 |
movl (%esi),%edx /* bo value */ |
| 87 |
|
| 88 |
femms |
| 89 |
testl %ebx,%ebx |
| 90 |
jne .L26 |
| 91 |
/* if(!channel) */ |
| 92 |
decl %edx /* --bo */ |
| 93 |
andl $15,%edx |
| 94 |
movl %edx,(%esi) /* save bo */ |
| 95 |
movl BUFFS,%ecx |
| 96 |
jmp .L27 |
| 97 |
.L26: /* if(channel) */ |
| 98 |
addl $2,LOCAL0 /* samples++ */ |
| 99 |
movl BUFFS,%ecx |
| 100 |
addl $2176,%ecx |
| 101 |
.L27: |
| 102 |
/* edx (and it's lower end) still holds bo value */ |
| 103 |
testb $1,%dl /* bo & 0x1 */ |
| 104 |
je .L28 |
| 105 |
movl %edx,LOCAL5 |
| 106 |
movl %ecx,%ebx |
| 107 |
movl BANDPTR,%esi |
| 108 |
movl %edx,%edi |
| 109 |
pushl %esi |
| 110 |
sall $2,%edi |
| 111 |
movl %ebx,%eax |
| 112 |
movl %edi,24(%esp) /* LOCAL1, actually */ |
| 113 |
addl %edi,%eax |
| 114 |
pushl %eax |
| 115 |
movl %edx,%eax |
| 116 |
incl %eax |
| 117 |
andl $15,%eax |
| 118 |
leal 1088(,%eax,4),%eax |
| 119 |
addl %ebx,%eax |
| 120 |
pushl %eax |
| 121 |
call FUNC(INT123_dct64_3dnow) |
| 122 |
addl $12,%esp |
| 123 |
jmp .L29 |
| 124 |
.L28: |
| 125 |
leal 1(%edx),%esi |
| 126 |
movl BANDPTR,%edi |
| 127 |
movl %esi,LOCAL5 |
| 128 |
leal 1092(%ecx,%edx,4),%eax |
| 129 |
pushl %edi |
| 130 |
leal 1088(%ecx),%ebx |
| 131 |
pushl %eax |
| 132 |
sall $2,%esi |
| 133 |
leal (%ecx,%edx,4),%eax |
| 134 |
pushl %eax |
| 135 |
call FUNC(INT123_dct64_3dnow) |
| 136 |
addl $12,%esp |
| 137 |
movl %esi,LOCAL1 |
| 138 |
.L29: |
| 139 |
movl DECWIN,%edx |
| 140 |
addl $64,%edx |
| 141 |
movl $16,%ecx |
| 142 |
subl LOCAL1,%edx |
| 143 |
movl LOCAL0,%edi |
| 144 |
|
| 145 |
pcmpeqb %mm7,%mm7 |
| 146 |
pslld $31,%mm7 |
| 147 |
movq (%edx),%mm0 |
| 148 |
movq (%ebx),%mm1 |
| 149 |
ALIGN32 |
| 150 |
.L33: |
| 151 |
#if defined(ACCURATE_ROUNDING) && defined(PIC) |
| 152 |
movl EBXSAVE, _EBX_ |
| 153 |
#endif |
| 154 |
movq 8(%edx),%mm3 |
| 155 |
pfmul %mm1,%mm0 |
| 156 |
movq 8(%ebx),%mm4 |
| 157 |
movq 16(%edx),%mm5 |
| 158 |
pfmul %mm4,%mm3 |
| 159 |
movq 16(%ebx),%mm6 |
| 160 |
pfadd %mm3,%mm0 |
| 161 |
movq 24(%edx),%mm1 |
| 162 |
pfmul %mm6,%mm5 |
| 163 |
movq 24(%ebx),%mm2 |
| 164 |
pfadd %mm5,%mm0 |
| 165 |
movq 32(%edx),%mm3 |
| 166 |
pfmul %mm2,%mm1 |
| 167 |
movq 32(%ebx),%mm4 |
| 168 |
pfadd %mm1,%mm0 |
| 169 |
movq 40(%edx),%mm5 |
| 170 |
pfmul %mm4,%mm3 |
| 171 |
movq 40(%ebx),%mm6 |
| 172 |
pfadd %mm3,%mm0 |
| 173 |
movq 48(%edx),%mm1 |
| 174 |
pfmul %mm6,%mm5 |
| 175 |
movq 48(%ebx),%mm2 |
| 176 |
pfadd %mm0,%mm5 |
| 177 |
movq 56(%edx),%mm3 |
| 178 |
pfmul %mm1,%mm2 |
| 179 |
movq 56(%ebx),%mm4 |
| 180 |
pfadd %mm5,%mm2 |
| 181 |
addl $64,%ebx |
| 182 |
subl $-128,%edx |
| 183 |
movq (%edx),%mm0 |
| 184 |
pfmul %mm4,%mm3 |
| 185 |
movq (%ebx),%mm1 |
| 186 |
pfadd %mm3,%mm2 |
| 187 |
movq %mm2,%mm3 |
| 188 |
psrlq $32,%mm3 |
| 189 |
pfsub %mm3,%mm2 |
| 190 |
incl %ebp |
| 191 |
#ifdef ACCURATE_ROUNDING |
| 192 |
pfmin LOCAL_VAR(max_s16),%mm2 |
| 193 |
pfmax LOCAL_VAR(min_s16),%mm2 |
| 194 |
pfadd LOCAL_VAR(ftoi_magic),%mm2 |
| 195 |
#else |
| 196 |
pf2id %mm2,%mm2 |
| 197 |
packssdw %mm2,%mm2 |
| 198 |
#endif |
| 199 |
movd %mm2,%eax |
| 200 |
movw %ax,0(%edi) |
| 201 |
addl $4,%edi |
| 202 |
decl %ecx |
| 203 |
jnz .L33 |
| 204 |
|
| 205 |
#if defined(ACCURATE_ROUNDING) && defined(PIC) |
| 206 |
movl EBXSAVE, _EBX_ |
| 207 |
#endif |
| 208 |
movd (%ebx),%mm0 |
| 209 |
movd (%edx),%mm1 |
| 210 |
punpckldq 8(%ebx),%mm0 |
| 211 |
punpckldq 8(%edx),%mm1 |
| 212 |
movd 16(%ebx),%mm3 |
| 213 |
movd 16(%edx),%mm4 |
| 214 |
pfmul %mm1,%mm0 |
| 215 |
punpckldq 24(%ebx),%mm3 |
| 216 |
punpckldq 24(%edx),%mm4 |
| 217 |
movd 32(%ebx),%mm5 |
| 218 |
movd 32(%edx),%mm6 |
| 219 |
pfmul %mm4,%mm3 |
| 220 |
punpckldq 40(%ebx),%mm5 |
| 221 |
punpckldq 40(%edx),%mm6 |
| 222 |
pfadd %mm3,%mm0 |
| 223 |
movd 48(%ebx),%mm1 |
| 224 |
movd 48(%edx),%mm2 |
| 225 |
pfmul %mm6,%mm5 |
| 226 |
punpckldq 56(%ebx),%mm1 |
| 227 |
punpckldq 56(%edx),%mm2 |
| 228 |
pfadd %mm5,%mm0 |
| 229 |
pfmul %mm2,%mm1 |
| 230 |
pfadd %mm1,%mm0 |
| 231 |
pfacc %mm1,%mm0 |
| 232 |
#ifdef ACCURATE_ROUNDING |
| 233 |
pfmin LOCAL_VAR(max_s16),%mm0 |
| 234 |
pfmax LOCAL_VAR(min_s16),%mm0 |
| 235 |
pfadd LOCAL_VAR(ftoi_magic),%mm0 |
| 236 |
#else |
| 237 |
pf2id %mm0,%mm0 |
| 238 |
packssdw %mm0,%mm0 |
| 239 |
#endif |
| 240 |
movd %mm0,%eax |
| 241 |
movw %ax,0(%edi) |
| 242 |
incl %ebp |
| 243 |
movl LOCAL5,%esi |
| 244 |
addl $-64,%ebx |
| 245 |
movl $15,%ebp |
| 246 |
addl $4,%edi |
| 247 |
leal -128(%edx,%esi,8),%edx |
| 248 |
|
| 249 |
movl $15,%ecx |
| 250 |
movd (%ebx),%mm0 |
| 251 |
movd -4(%edx),%mm1 |
| 252 |
punpckldq 4(%ebx),%mm0 |
| 253 |
punpckldq -8(%edx),%mm1 |
| 254 |
ALIGN32 |
| 255 |
.L46: |
| 256 |
#if defined(ACCURATE_ROUNDING) && defined(PIC) |
| 257 |
movl EBXSAVE, _EBX_ |
| 258 |
#endif |
| 259 |
movd 8(%ebx),%mm3 |
| 260 |
movd -12(%edx),%mm4 |
| 261 |
pfmul %mm1,%mm0 |
| 262 |
punpckldq 12(%ebx),%mm3 |
| 263 |
punpckldq -16(%edx),%mm4 |
| 264 |
movd 16(%ebx),%mm5 |
| 265 |
movd -20(%edx),%mm6 |
| 266 |
pfmul %mm4,%mm3 |
| 267 |
punpckldq 20(%ebx),%mm5 |
| 268 |
punpckldq -24(%edx),%mm6 |
| 269 |
pfadd %mm3,%mm0 |
| 270 |
movd 24(%ebx),%mm1 |
| 271 |
movd -28(%edx),%mm2 |
| 272 |
pfmul %mm6,%mm5 |
| 273 |
punpckldq 28(%ebx),%mm1 |
| 274 |
punpckldq -32(%edx),%mm2 |
| 275 |
pfadd %mm5,%mm0 |
| 276 |
movd 32(%ebx),%mm3 |
| 277 |
movd -36(%edx),%mm4 |
| 278 |
pfmul %mm2,%mm1 |
| 279 |
punpckldq 36(%ebx),%mm3 |
| 280 |
punpckldq -40(%edx),%mm4 |
| 281 |
pfadd %mm1,%mm0 |
| 282 |
movd 40(%ebx),%mm5 |
| 283 |
movd -44(%edx),%mm6 |
| 284 |
pfmul %mm4,%mm3 |
| 285 |
punpckldq 44(%ebx),%mm5 |
| 286 |
punpckldq -48(%edx),%mm6 |
| 287 |
pfadd %mm3,%mm0 |
| 288 |
movd 48(%ebx),%mm1 |
| 289 |
movd -52(%edx),%mm2 |
| 290 |
pfmul %mm6,%mm5 |
| 291 |
punpckldq 52(%ebx),%mm1 |
| 292 |
punpckldq -56(%edx),%mm2 |
| 293 |
pfadd %mm0,%mm5 |
| 294 |
movd 56(%ebx),%mm3 |
| 295 |
movd -60(%edx),%mm4 |
| 296 |
pfmul %mm2,%mm1 |
| 297 |
punpckldq 60(%ebx),%mm3 |
| 298 |
punpckldq (%edx),%mm4 |
| 299 |
pfadd %mm1,%mm5 |
| 300 |
addl $-128,%edx |
| 301 |
addl $-64,%ebx |
| 302 |
movd (%ebx),%mm0 |
| 303 |
movd -4(%edx),%mm1 |
| 304 |
pfmul %mm4,%mm3 |
| 305 |
punpckldq 4(%ebx),%mm0 |
| 306 |
punpckldq -8(%edx),%mm1 |
| 307 |
pfadd %mm5,%mm3 |
| 308 |
pfacc %mm3,%mm3 |
| 309 |
incl %ebp |
| 310 |
pxor %mm7,%mm3 |
| 311 |
#ifdef ACCURATE_ROUNDING |
| 312 |
pfmin LOCAL_VAR(max_s16),%mm3 |
| 313 |
pfmax LOCAL_VAR(min_s16),%mm3 |
| 314 |
pfadd LOCAL_VAR(ftoi_magic),%mm3 |
| 315 |
#else |
| 316 |
pf2id %mm3,%mm3 |
| 317 |
packssdw %mm3,%mm3 |
| 318 |
#endif |
| 319 |
movd %mm3,%eax |
| 320 |
movw %ax,(%edi) |
| 321 |
addl $4,%edi |
| 322 |
decl %ecx |
| 323 |
jnz .L46 |
| 324 |
|
| 325 |
femms |
| 326 |
movl %ebp,%eax |
| 327 |
popl %ebx |
| 328 |
popl %esi |
| 329 |
popl %edi |
| 330 |
popl %ebp |
| 331 |
addl $24,%esp |
| 332 |
ret |
| 333 |
|
| 334 |
#if defined(PIC) && defined(__APPLE__) |
| 335 |
.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 |
| 336 |
FUNC(INT123_dct64_3dnow): |
| 337 |
.indirect_symbol ASM_NAME(INT123_dct64_3dnow) |
| 338 |
hlt ; hlt ; hlt ; hlt ; hlt |
| 339 |
#endif |
| 340 |
|
| 341 |
NONEXEC_STACK |