flat assembler
Message board for the users of flat assembler.

Index > Heap > Why do modern HLLs make code like this?


Why??
A good reason (please specify what this is)
0%
 0%  [ 0 ]
No reason or bad reason (HLLs just suck)
100%
 100%  [ 7 ]
Total Votes : 7

Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Code:
call func
mov esi,eax
...
//eax not even used below

func:
lea eax,[ecx+4]
ret    


Aren't they supposed to be matching or (or even surpassing) humans at code generation by now? So what is this? Why on Earth not just inline lea esi,[ecx+4]?

Heck even in Windows there is stuff like
Code:
func:
...
mov ebp,esp
...
mov something,[ebp+4]
...
mov something,[ebp+4]
...
mov something,[ebp+4]
...
mov something,[ebp+4]
...
//ebp never used for anything else in the entire function    



What gives? Why not just mov ebp,[esp+4] and use ebp directly all those times below?

_________________
Post 06 Jul 2010, 05:41
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
It's a result of generalization, x asm code to do x HLL operation. It has to fit without screwing stuff up, but can only be as customized as the compiler thinks it should be. It's a matter of analyzing a function to see what is necessary and what can be simplified, a logic I think would be very hard to program to function optimally, while never screwing something up. I'm not exscusing compiler makers for their suboptimal compilers, I'm just saying that it's not that simple.

If it bugs you, write a patch for whatever compiler you use to check for, and remove redundant or unused register changes. But when it outputs a buggy binary, you'll see why things are the way they are.
Post 06 Jul 2010, 06:25
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Tyler wrote:
It's a result of generalization, x asm code to do x HLL operation. It has to fit without screwing stuff up, but can only be as customized as the compiler thinks it should be. It's a matter of analyzing a function to see what is necessary and what can be simplified, a logic I think would be very hard to program to function optimally, while never screwing something up. I'm not exscusing compiler makers for their suboptimal compilers, I'm just saying that it's not that simple.

If it bugs you, write a patch for whatever compiler you use to check for, and remove redundant or unused register changes. But when it outputs a buggy binary, you'll see why things are the way they are.


What's so complicated about "If it's smaller than the call, inline" and "If a pointer is only used to get at one thing, just put that in it from the beginning"?

I'm not inclined to RTFB something I don't intend to use, so I'm going to have to decline your suggestion, sorry.

_________________
Post 06 Jul 2010, 06:32
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
There's your problem, you're using a closed source compiler. Smile

New instructions:
  • Get an open source compiler.
  • See if it has the same problem.
  • If no, you're done, if yes continue.
  • Write a patch.
  • Enjoy HLL. Wink

Or you could whine about the crappiness of your compiler... Razz

Just to be clear, I voted for "No reason...". There is no reason for imperfection, just excuses.
Post 06 Jul 2010, 06:43
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
There are probably so many other errors that it'd be easier to write one from scratch anyways. MSVC is the most used one on the planet, so the others can't suck that much less. Maybe 10 times less, but the point still stands.

Whining is more productive; at least it replaces other recreation, rather than being an entirely Sisyphean task.
Post 06 Jul 2010, 07:10
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 521
Location: ( . Y . )
ass0
Simple Marketing: Large code needs fast CPU and big storage.
You don't need to be a genius to see it.

So VS2020 will produce a "hello world" program in 1Mb. =)

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 06 Jul 2010, 07:13
View user's profile Send private message Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 521
Location: ( . Y . )
ass0
BTW. Did you ever seen the html output that MS Word makes when it does a DOC2HTML?

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 06 Jul 2010, 07:21
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Quote:

So VS2020 will produce a "hello world" program in 1Mb. =)

Lazarus gives 11.xxMB default.
Post 06 Jul 2010, 09:00
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
It simply SucksByDesign™! Just like you can't send a human do a machine's job, you can't send a machine do a human's job. Even the best compilers can't really use the best method and optimize code as a human would do. They're lacking sapience.

I was recently (loosely) converting a program written in C to assembly.
Every time I wanted to convert a routine, I first read the C code, wrote my assembly version and compared with the assembly output code of the compiler. Well, I was really: "WTF is that?" Not only did the code look bizarrely constructed and structured, but it also had many more instructions than mine for the same result.

Also, you always get bigger files when compiling a C program directly as opposed to using assembly and linking the object to the appropriate libraries. It's only a few Kb, but still.

And that's just C! I've never even considered something higher.
I understand assembly much better and think it's really the only logical language. All HLL have so many "quirks" and weird abstractions that it sometimes takes me a while to understand what a specific structure really means and then I say: "So this looked so complicated and in the end it was just <e.g. some kind of array>."


Azu wrote:
Heck even in Windows there is stuff like

Shocking, eh? Shocked Laughing

ass0 wrote:
BTW. Did you ever seen the html output that MS Word makes when it does a DOC2HTML?

Never seen anything prettier in my life. It beats obfuscation contests by far, muhahaha. Laughing
Post 06 Jul 2010, 09:57
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
When you guys speak of "modern HLL compilers", always say which compiler, which version, and what optimizations were used. Without that, any talk about result of meaningless.
Post 06 Jul 2010, 10:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
conjecture:

Code:
mov something,[ebp+4]    

is 1 byte shorter than
Code:
mov something,[esp+4]    

_________________
This is a block of text that can be added to posts you make.
Post 06 Jul 2010, 16:32
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
My Delphi 5 produced code like this:

Code:
mov eax,[ebp+x]
mov [ebp+y],eax
mov eax,[ebp+x]
mov [ebp+z],eax    

_________________
This is a block of text that can be added to posts you make.
Post 06 Jul 2010, 16:34
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
roboman



Joined: 03 Dec 2006
Posts: 122
Location: USA
roboman
Person X gets paid to write a function, not well or fast, just one more to put on the function list when they market it. Then persons a-b-c get in and throw extra stuff on top to kill a bug it causes some where else. What the heck, most of the software is really in the dll's of the os any way Smile
Post 06 Jul 2010, 18:54
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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.