flat assembler
Message board for the users of flat assembler.

Index > Main > please help me to understand

Author
Thread Post new topic Reply to topic
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
Hi,
I don't understand, why:
Code:
.....
ret
lea      eax,[eax]
lebel1:
......
check something
je      lebel2
...
jmp     lebel1
lea      eax,[eax]
lebel2:
...    

is faster then:
Code:
.....
ret
align   4
lebel1:
...instuctions
check something
je        lebel2
...instuctions
jmp     lebel1
align   4
lebel2:
...instuctions    

the instruction lea eax,[eax] wasn't real used?
Post 24 Jan 2006, 20:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i think parts you omited (...) were important in this case. What is code for? Two codes you posted do different things, they are not functionaly equivalent
Post 24 Jan 2006, 20:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
And I thought the same as you...
When i create some proc or part from proc i tested with well-known program(see TSCTest32.zip)
When i saw this method(lea eax,[eax]), for the first time in "lzo" decompress algorithm, i did revision of my standart used procs, and the results ware very intresting, but i don't understand why this happens(in 90% of the cases - standart used("IO", str and other) procs and macros are faster, not only in my computer)


Description:
Download
Filename: TSCTest32.zip
Filesize: 1.81 KB
Downloaded: 100 Time(s)

Post 24 Jan 2006, 21:06
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
lea eax, [eax] doesn't do anything but it aligns the following label and so the processor can read it faster. That's one of the basic rules of optimization - alignment.

EDIT: Example:
Code:
; first code
00:   jmp  labe1
02: 
02: label1:
02:   nop

; second code
00:   jmp  label1
02:   lea  eax, [eax]
04:
04: label1:
04:   nop    
The code aligned to any miltiplication of 4 will be faster. If you want to use it, try 'align 4' fasm's directive as during coding you don't know what relative address there currently is.
Post 29 Jan 2006, 15:22
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.