1# MMX assist routines for peakval 2# Copyright 2001 Phil Karn, KA9Q 3# May be used under the terms of the GNU Lesser General Public License (LGPL) 4 5 .text 6 7# Find peak value in signed 16-bit input samples 8# int peakval_mmx(signed short *in,int cnt); 9 .global peakval_mmx 10 .type peakval_mmx,@function 11 .align 16 12peakval_mmx: 13 pushl %ebp 14 movl %esp,%ebp 15 pushl %esi 16 pushl %ecx 17 pushl %ebx 18 19 movl 8(%ebp),%esi 20 movl 12(%ebp),%ecx 21 22 pxor %mm7,%mm7 # clear peak 23 241: subl $4,%ecx 25 jl 2f 26 movq (%esi),%mm0 27 movq %mm0,%mm1 28 psraw $15,%mm1 # mm1 = 1's if negative, 0's if positive 29 pxor %mm1,%mm0 # complement negatives 30 psubw %mm1,%mm0 # add 1 to negatives 31 movq %mm7,%mm6 # copy previous peak 32 pcmpgtw %mm0,%mm6 # ff == old peak greater 33 pand %mm6,%mm7 # select old peaks that are greater 34 pandn %mm0,%mm6 # select new values that are greater 35 por %mm6,%mm7 36 37 addl $8,%esi 38 jmp 1b 39 402: movd %mm7,%eax 41 psrlq $16,%mm7 42 andl $0xffff,%eax 43 44 movd %mm7,%edx 45 psrlq $16,%mm7 46 andl $0xffff,%edx 47 cmpl %edx,%eax 48 jnl 3f 49 movl %edx,%eax 503: 51 movd %mm7,%edx 52 psrlq $16,%mm7 53 andl $0xffff,%edx 54 cmpl %edx,%eax 55 jnl 4f 56 movl %edx,%eax 574: 58 movd %mm7,%edx 59 andl $0xffff,%edx 60 cmpl %edx,%eax 61 jnl 5f 62 movl %edx,%eax 635: 64 emms 65 popl %ebx 66 popl %ecx 67 popl %esi 68 popl %ebp 69 ret 70 71