News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Line function

Started by Farabi, March 30, 2008, 12:52:54 PM

Previous topic - Next topic

Farabi

Hai, this time I want to show you my line function. Got any idea to optimize it?


GetDeltaXY proc x:dword,y:dword,x2:dword,y2:dword

mov edx,x2
sub edx,x
mov eax,y2
sub eax,y

ret
GetDeltaXY endp ; Result on edx:eax

GetHypotenusa proc nDX:dword,nDY:dword
LOCAL res:dword

xor edx,edx
mov eax,nDY
mul eax

mov res,eax

xor edx,edx
mov eax,nDX
mul eax

add res,eax
fild res
fsqrt
fistp res
; invoke GetSqrt,res
mov eax,res

ret
GetHypotenusa endp ;

GetPosLine proc nDX:dword,nDY:dword,hyp:dword,nPos:dword
LOCAL x,y:dword

; fild nDX
; fidiv hyp
; fimul nPos
; fistp x

; (nPos*nDX)/hyp
xor edx,edx ; 1
xor eax,eax ; 1

mov eax,nDX ; 1
imul nPos ; 42
idiv hyp ; 42
mov x,eax ; 1

; fild nDY
; fidiv hyp
; fimul nPos
; fistp y

; (nPos*nDY)/hyp

xor edx,edx ; 1
xor eax,eax ; 1

mov eax,nDY ; 1
imul nPos ; 42
idiv hyp ; 42
mov y,eax ; 1

mov edx,x
mov eax,y

ret
GetPosLine endp ; Result on edx:eax

Line proc uses esi edi x:dword,y:dword,x2:dword,y2:dword,color:dword
LOCAL nDX,nDY,hyp:dword


invoke GetDeltaXY,x,y,x2,y2
mov nDX,edx
mov nDY,eax
invoke GetHypotenusa,nDX,nDY
mov hyp,eax

cmp hyp,0
jle brs

mov ecx,hyp

@@:
push ecx
invoke GetPosLine,nDX,nDY,hyp,ecx
add edx,x
add eax,y
invoke frbPixelPut,edx,eax,color
pop ecx
dec ecx
jnz @b

brs:


ret
Line endp
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

daydreamer

I dont understand why you need to make use of SQR, hypotenusa for a linedrawing function?
find out which is biggest lenght of line is in x or y and step along this axis
big speedup is to not have calculation of pixeladress in innerloop, but simplified to add ebx,lPitch when increment Y happens and add ebx,-lPitch if you decrement Y
the reason I want to use add in both places is I can simple initialize direction with NEG lPitch if nesserary
macro instead of proc for pixelplotting also great for speedup with no call/ret and its lousy branchprediction it has

Tedd

No snowflake in an avalanche feels responsible.

Farabi

Quote from: daydreamer on March 30, 2008, 03:52:50 PM
I dont understand why you need to make use of SQR, hypotenusa for a linedrawing function?
find out which is biggest lenght of line is in x or y and step along this axis
big speedup is to not have calculation of pixeladress in innerloop, but simplified to add ebx,lPitch when increment Y happens and add ebx,-lPitch if you decrement Y
the reason I want to use add in both places is I can simple initialize direction with NEG lPitch if nesserary
macro instead of proc for pixelplotting also great for speedup with no call/ret and its lousy branchprediction it has


Because I only understand it that  way. Anyway thanks for your answer.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"