The MASM Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?
February 09, 2010, 08:19:49 am

Login with username, password and session length
Search:     Advanced search
101243 Posts in 12650 Topics by 1721 Members
Latest Member: yakovm
* Home Help Search Login Register
+  The MASM Forum
|-+  General Forums
| |-+  The Workshop
| | |-+  Why ML always use LEAVE but not ENTER?
« previous next »
Pages: [1] 2 Print
Author Topic: Why ML always use LEAVE but not ENTER?  (Read 2013 times)
Mark Jones
Drifting in the Abstract
Member
*****
Posts: 2303


=- Stargate Atlantis -=


Why ML always use LEAVE but not ENTER?
« on: June 09, 2006, 05:37:08 pm »

In every proc, the stack frame is created by PUSH EBP and MOV EBP,ESP instead of ENTER. Why is this?

Code:
myProc PROC USES ESI EDI
; nothing in here...
myProc ENDP

Quote from: OllyDbg
00405910  /.  55            PUSH EBP
00405911  |.  8BEC         MOV EBP,ESP
00405913  |.  56            PUSH ESI
00405914  |.  57            PUSH EDI                                ;  ntdll.7C910738
00405915  |.  5F            POP EDI                                  ;  kernel32.7C816D4F
00405916  |.  5E            POP ESI                                  ;  kernel32.7C816D4F
00405917  |.  C9            LEAVE
00405918  \.  C2 0800     RETN 8
Logged

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08
bushpilot
I'd rather be fishing...
Member
*****
Gender: Male
Posts: 105



Re: Why ML always use LEAVE but not ENTER?
« Reply #1 on: June 09, 2006, 06:10:03 pm »

Well, I can't answer ... but I do know that the AMD optimization manual recommends the use of leave, but does not recommend using enter.  I too have wondered why.

Greg
Logged

"All men desire peace, but very few desire those things that make for peace."
THOMAS À KEMPIS (C. 1380–1471)
arafel
Member
*****
Gender: Male
Posts: 177


Lord of the Drinks


Re: Why ML always use LEAVE but not ENTER?
« Reply #2 on: June 09, 2006, 06:30:52 pm »

According to Agner`s optimization manual on P4 ENTER has latency of 25 and takes 4uops. While "push ebp with mov ebp, esp" in cumulative have latency of 1.5 and take 2uops. On PIII ENTER seems to be slower as well. Perhaps this is the reason why masm avoids enter by default.
Logged

free cheese always goes to the second mouse
hutch--
Administrator
Member
*****
Posts: 8305


Mnemonic Driven API Grinder


Re: Why ML always use LEAVE but not ENTER?
« Reply #3 on: June 10, 2006, 09:03:09 pm »

For whatever reason, ENTER has been slow for a long time where LEAVE still performs OK on most of the later machines. It is shorter but it has probably retained its performance because many C compilers have used the LEAVE exit from a stack frames as well.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
P1
Global Moderator
Member
*****
Posts: 1174


Re: Why ML always use LEAVE but not ENTER?
« Reply #4 on: June 12, 2006, 03:59:47 pm »

The uP is female.  You always enter slowly, leave as quickly as possible.   lol

Regards,  P1  Cool
Logged
no-one
Guest


Email
Re: Why ML always use LEAVE but not ENTER?
« Reply #5 on: June 13, 2006, 05:32:28 am »

Hutch,
Go ahead and delete my posts but you cannot shut me up.  The above posing is appalling and you can not deny it.

Paul
Logged
hutch--
Administrator
Member
*****
Posts: 8305


Mnemonic Driven API Grinder


Re: Why ML always use LEAVE but not ENTER?
« Reply #6 on: June 13, 2006, 05:56:12 am »

Paul,

As you know I am an Australian and I live in a culture that has considerably more robust humour than you have seen here in this topic. If I told you some of the jokes that can be told in polite company here, your hair would curl. Now I suggest that the argument you have in mind is not one that should be placed in a technical forum where a member has asked a question but back in the direction that it came from which is not here.

We are not internet policemen in this forum and never will be and when there are differences between people which is outside of this forum in its origin, it is simply not our task to interfere in that business. What I would suggest is that personal issue be left out of this forum and be dealt with elsewhere as they have no place here.

Now I will ask this much of you, please leave this matter alone in this forum as it is simply not our business and please use your normal name account.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
no-one
Guest


Email
Re: Why ML always use LEAVE but not ENTER?
« Reply #7 on: June 13, 2006, 01:06:17 pm »

For you, I will do this.  But I am still considering leaving.

My culture, from Massachusetts, is Puritanical and as Puritans we are ultra-conservative and such things are just not allowed in decent communications.  I will not change who I am and if I am subjected to things that I find offensive, I will react to them.  Trying to justify this type of actions will just fall on deaf ears in my case as I will not pollute my thought processes with such things.  I am aware of the history of Australians.

Paul
Logged
savage
Macro-ologist
Member
****
Gender: Male
Posts: 78



Re: Why ML always use LEAVE but not ENTER?
« Reply #8 on: June 13, 2006, 04:10:38 pm »

So back to the topic...

Why did intel make it so friggin slow?

P.S.   Paul, I'm absolutely sure P1 means no harm by what he said.  And of course, he is definitely not serious, he's speaking with pure humor. I'm aware that many people are offended, but ALWAYS keep in mind that anything goes on the internet, so try not to take anything too personally.   ThumbsUp
Logged

Why is everyone always trying to get to point B?
hutch--
Administrator
Member
*****
Posts: 8305


Mnemonic Driven API Grinder


Re: Why ML always use LEAVE but not ENTER?
« Reply #9 on: June 13, 2006, 04:29:08 pm »

Savage,

Its usually the case with processor design that if an instruction is redundant, it gets shoved into much slower micro-code so that the more speed critical stuff can occupy the higher speed areas of direct silicon. The preferred instructions like MOV, ADD SUB CMP etc .... get used far more often so they get priority in terms of being more directly constructed on the silicon chip wafer.

With ENTER, its probably because a PUSH and a MOV are easier to perform as two fast direct silicon opcodes than wasting the space on an older design instruction which cannot be used for another purpose.

There is another factor that processors use a lower level set of internals that the original 8088 instruction set and this leans towards far simpler instructions that complex ones. There are a few exceptions which are hard coded into some Intel processors and these are special case circuitry with REP MOVSD/LODSD and perhaps a couple of others. The instructions are so commonly used that they have special case circuits in the processors to keep their speed up to other instructions.

In the case of LEAVE, it is probably becuase many C compiler as well as MASM use LEAVE that it still performs reasonably well.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
savage
Macro-ologist
Member
****
Gender: Male
Posts: 78



Re: Why ML always use LEAVE but not ENTER?
« Reply #10 on: June 13, 2006, 05:00:09 pm »

I know this sounds like a naive question, but can't they just make the processor interpret ENTER and translate it internally as the better version? Or anything like that?
Logged

Why is everyone always trying to get to point B?
Stan Hebben
Member
*****
Gender: Male
Posts: 211



Re: Why ML always use LEAVE but not ENTER?
« Reply #11 on: June 13, 2006, 05:26:31 pm »

That's what happens, but the process of conversion slows down the processor. (all vectorpath instructions are translated in micro-ops)
Logged
Ossa
EW RF/Microwave Engineer
Member
*****
Gender: Male
Posts: 272



Re: Why ML always use LEAVE but not ENTER?
« Reply #12 on: June 13, 2006, 05:31:22 pm »

Basically the more commonly used instructions are the ones that are given the greatest speed to make code overall faster. If the enter instruction were made faster, some other instructions will end up slower which would slow other code down... it's an engineering trade-off and they decided (rightly I think) that enter could be made quite slow.

Ossa
Logged

Website (very old): ossa.the-wot.co.uk
savage
Macro-ologist
Member
****
Gender: Male
Posts: 78



Re: Why ML always use LEAVE but not ENTER?
« Reply #13 on: June 13, 2006, 11:16:17 pm »

Ok, so....... if it's internally translated to the same thing, why is it slower overall from the stretched out version?
Logged

Why is everyone always trying to get to point B?
Stan Hebben
Member
*****
Gender: Male
Posts: 211



Re: Why ML always use LEAVE but not ENTER?
« Reply #14 on: June 15, 2006, 09:45:03 am »

Quote from: Intel optimization guide
Assembly/Compiler Coding Rule 40. (ML impact, M generality)

Avoid using complex instructions (for example, enter, leave, or loop) that have more than four μops and require multiple cycles to decode.
Use sequences of simple instructions instead.

Complex instructions may save architectural registers, but incur a penalty of 4 μops to set up parameters for the microcode ROM.

The decoding takes some time. Using simple instructions instead of complex ones avoids the decoding, and is faster.

Stan
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!