Ok, in my code I have been using:



cmp eax, 0
je DoSometing

or

cmp eax, 1
je DoSomething

reading the MASM docs I read that using or produces smaller and faster code
or eax, eax
jz DoSomething

or

or eax, eax
jnz DoSomething


Well, I changed my code to or and shaved off quite a bit of bytes, is this the best way to test for something? Gonna read Agner's help file now to see what else I can learn....
Posted on 2003-01-02 21:25:45 by Gunner
test eax, eax
jz EAX_equals_zero


or


dec eax
jz EAX_equals_one
inc eax
Posted on 2003-01-02 21:53:09 by bitRAKE


Well, I changed my code to or and shaved off quite a bit of bytes, is this the best way to test for something? Gonna read Agner's help file now to see what else I can learn....


Hi

I use a little routine for measuring execution speed and paring off those bloated bytes that I put together from a few code examples from others on this board, so credit goes to those I scammed the information and syntax from ;). I don't know if a fully optimized RDTSC routine might be more precise, but this is at least more accurate than GetTickCount. The first time you run your code it won't be representative because of the cacheing effects Agner describes. I recently hardcoded my own lstrcpy/len/cat routines and found a big difference over the API versions. Hope this can help, maybe something like this could be put into the FAQ section?

Regards,
Kayaker


; =======================================
; Routine for measuring the execution speed of a proc
; =======================================

; include TickRoutine.asm
; INVOKE StartTick
; code to be measured
; INVOKE EndTick

include \masm32\include\masm32.inc ; for FloatToStr routine
includelib \masm32\lib\masm32.lib

StartTick proto
EndTick proto

;----------------------------------------------------

msgCaptionTicks db "Execution Speed in ms",0

lpPerformanceFrequency QWORD ?
CountsPerSec QWORD ?
lpPerformanceCount QWORD ?
StartCount QWORD ?
EndCount QWORD ?
ExecutionTime QWORD ?
msec DWORD ?

bufferTicks db 32 dup(?)

;===============StartTick Proc===================
StartTick proc

pushad
finit ; initialize FPU

; -------------------------------------------------------------
; Get the frequency of the high-resolution performance counter
; -------------------------------------------------------------

invoke QueryPerformanceFrequency, offset lpPerformanceFrequency

fld qword ptr [lpPerformanceFrequency]
; push result onto top of FPU stack st(0)
fstp qword ptr [CountsPerSec]
; store value in st(0) into variable

; -------------------------------------------------------------
; Get the starting tick value
; -------------------------------------------------------------

invoke QueryPerformanceCounter, offset lpPerformanceCount

fld qword ptr [lpPerformanceCount]
fstp qword ptr [StartCount]

popad
ret
StartTick endp
;===============End StartTick Proc===============


;===============EndTick Proc===================
EndTick proc

pushad
; -------------------------------------------------------------
; Get the ending tick value
; -------------------------------------------------------------

invoke QueryPerformanceCounter, offset lpPerformanceCount

fld qword ptr [lpPerformanceCount]
fstp qword ptr [EndCount]

; -------------------------------------------------------------
; The time in seconds between the two
; QueryPerformanceCounter calls is
; (EndCount - StartCount) / CountsPerSec
; -------------------------------------------------------------

fld qword ptr [EndCount] ; load EndCount to st(0)
fsub qword ptr [StartCount] ; sub StartCount from st(0)
fdiv qword ptr [CountsPerSec] ; divide result by CountsPerSec
mov msec, 1000 ; shift decimal place to milliseconds
fimul msec ; multiply result in st(0) by 1000
fstp qword ptr [ExecutionTime] ; store result in st(0) to variable

; -----------------------------------------------------------
; Convert floating point result to a string using
; masm32lib function FloatToStr
; -----------------------------------------------------------

invoke FloatToStr, qword ptr [ExecutionTime], offset bufferTicks

; --------------------------------------
; Display it
; --------------------------------------

invoke MessageBox, NULL, offset bufferTicks, offset msgCaptionTicks,\
MB_OK+MB_ICONINFORMATION+MB_TASKMODAL+MB_TOPMOST

finit ; reinitialize FPU

popad
ret
EndTick endp
;===============End EndTick Proc================
Posted on 2003-01-03 01:15:53 by Kayaker