Assembly code snippets
Details
Title | NonUniformAverages |
---|---|
Author | bitRAKE |
Submitted by: | bitRAKE |
Date added: | 2002-02-17 20:35:36 |
Date modified: | 2002-02-17 21:26:53 |
Comments
Array of foating point values are resampled (linear interpolation) to a smaller array.
Requires: [link15:fpc macro]
Snippet
; arrDest Pointer to buffer of size lenDest*4. This buffer will hold an
; array of REAL4 values returned from proceedure.
; arrSrc Pointer to buffer of size lenSrc*4. This buffer holds lenSrc REAL4
; values to be averaged by the proceedure.
;
NonUniformAverages PROC uses esi edi, arrDest:DWORD, arrSrc:DWORD, lenDest:DWORD, lenSrc:DWORD
LOCAL fTemp:QWORD
mov edx,lenDest
mov esi,arrSrc
mov edi,arrDest
cmp edx,lenSrc
jge Error
fild lenDest
fidiv lenSrc
xor eax,eax
and DWORD PTR [fTemp+4],0
fld st
; 1 / 2^32
fdivr fpc(0.000000000232830643653869628906250)
div lenSrc
fldz ; init
Main:
add edx,eax
jc @F
fadd REAL4 PTR [esi]
add esi,4
jmp Main
@@:
fadd REAL4 PTR [esi]
mov DWORD PTR [fTemp],edx
fild fTemp
fmul st(0),st(2)
fmul REAL4 PTR [esi]
fxch st(1)
fsub st(0),st(1)
fmul st(0),st(3)
fstp REAL4 PTR [edi]
add esi,4
add edi,4
dec lenDest
jne Main
fstp st(0)
fstp st(0)
fstp st(0)
ret
Error:
jne @F
; this isn't exactly an error
mov ecx,edx
rep movsd
or eax,-1
ret
@@:
xor eax,eax ; error checking isn't a bad thing
ret
NonUniformAverages ENDP
; array of REAL4 values returned from proceedure.
; arrSrc Pointer to buffer of size lenSrc*4. This buffer holds lenSrc REAL4
; values to be averaged by the proceedure.
;
NonUniformAverages PROC uses esi edi, arrDest:DWORD, arrSrc:DWORD, lenDest:DWORD, lenSrc:DWORD
LOCAL fTemp:QWORD
mov edx,lenDest
mov esi,arrSrc
mov edi,arrDest
cmp edx,lenSrc
jge Error
fild lenDest
fidiv lenSrc
xor eax,eax
and DWORD PTR [fTemp+4],0
fld st
; 1 / 2^32
fdivr fpc(0.000000000232830643653869628906250)
div lenSrc
fldz ; init
Main:
add edx,eax
jc @F
fadd REAL4 PTR [esi]
add esi,4
jmp Main
@@:
fadd REAL4 PTR [esi]
mov DWORD PTR [fTemp],edx
fild fTemp
fmul st(0),st(2)
fmul REAL4 PTR [esi]
fxch st(1)
fsub st(0),st(1)
fmul st(0),st(3)
fstp REAL4 PTR [edi]
add esi,4
add edi,4
dec lenDest
jne Main
fstp st(0)
fstp st(0)
fstp st(0)
ret
Error:
jne @F
; this isn't exactly an error
mov ecx,edx
rep movsd
or eax,-1
ret
@@:
xor eax,eax ; error checking isn't a bad thing
ret
NonUniformAverages ENDP