;PIII ROUTINES : GETMAX from a 4/8/12... word array
;MASM 6.15.8803 & LINK 5.12 & MASM32 7
;Author Valery CLAUDEPIERRE, 2002

;one day I had to retrieve the index of the min of a (at most) 12-byte array, whose values changed recursively.
;So I put indexes 0 to 11 in the lsb of a 12-word array, to handle them through MMX

;#############################################################################

.686
.mmx
.xmm
.model flat,stdcall
option casemap :none ; case sensitive


include c:\masm32\include\profile.inc
include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\masm32.inc
include c:\masm32\include\debug.inc

includelib c:\masm32\lib\masm32.lib
includelib c:\masm32\lib\debug.lib
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\user32.lib

;#############################################################################

align 16
.data
string dq 2703290223012500h,1807120614051604h,380b320a34093608h

;#############################################################################

.code
jmp start

align 16
getmax12:
movq MM0,qword ptr
pminsw MM0,qword ptr
pminsw MM0,qword ptr

pshufw MM1,MM0,01bh
pminsw MM0,MM1
pshufw MM1,MM0,0b1h
pminsw MM0,MM1
pextrw eax,MM0,0 ;or 1 or 2 or 3 : all the same, it is the min

;resulting idx is in al, and min in ah
ret

start:

PROFILE getmax12
PrintDword PROFILECYCLES
;PrintDword PROFILECYCLES+4
PrintHex eax

ret

end start
Posted on 2002-09-05 06:59:46 by valy