flat assembler
Message board for the users of flat assembler.

Index > Main > HLL compilers generate better code than hand written asm?

Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 8906
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
JohnFound wrote:

What is your opinion?

well, my opinion is like this,

there are a few question,
1. could machine/application/OS self-debug? find bug, apply fix?

2. if in the end of the days, it would still require a human to go and read assembly code to debug, which assembly code is easier to digest? the machine generated? or human hand written?

3. could "creativity" exists in compiler? using a whole new strategy that never been programmed into it to solve a problem? bug? faster execution? forsee or prediction of unknown choice by programmer?

imo, it is like 2 chefs,
compiler chef can cook good food at superb speed, near perfect awesome, but your stomach hardly digest his food.

manual code chef cook so so food, depend on situation, but your stomach most probably could digest his food.
Post 03 Feb 2013, 19:29
View user's profile Send private message Reply with quote
ASM-Man



Joined: 11 Jan 2013
Posts: 65
ASM-Man
Humans win becaus they make the compilers.

IMHO,a human may not win when the source code is too large. He still can be able to make the optimizations,but what about if the code is too large? it will make it tired. Also,they still need to make the code human-readable for he and other computers programmmers -- compilers don't,so,them are free to make optmization on optimization and so on sure that still understand complex assembly code.

In HLL languages,is commun the peoples prefer make the code a bit more readable instead of a black-magic-optmization. I seen this pratice in source code of compilers,to my surprise.

_________________
I'm not a native speaker of the english language. So, if you find any mistake what I have written, you are free to fix for me or tell me on. Smile
Post 03 Feb 2013, 21:13
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I think writting only ASM thinking HLLs generate bad code is being closed-minded.

Good C++ compilers can optimize the code really well.

I think we should focus on writting better ALGORITHMS instead of worrying with code generation. A bad sorting algorithm for example will be very slow. And HLLs make writting/using pre-coded algorithms easier.
Post 03 Feb 2013, 23:32
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8906
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
good code
readable
optimize
expandable
manageable

it is good code (HLL or hand code asm), if it fulfill above criteria.

HLL tends to introduce layer and more layers, it backs to perception,
Post 04 Feb 2013, 00:05
View user's profile Send private message Reply with quote
Asm++



Joined: 04 Feb 2013
Posts: 24
Location: On a Chip!
Asm++
Hi everybody, this is my first contribution in FASM forum.

Well, for the question, it's hard to tell an exact answer,
because your question is SO WIDE, there are dozens of different HLLs, created for different purposes, also "better" is not defined Confused .

So for example, VB.net(with all of respect to VB.net programmers), can NOT generate a better code than assembly hand written, in respect of size or speed.

_________________
Binary is nice, but Assembly is better!
Post 04 Feb 2013, 01:53
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
HaHaAnonymous wrote:
I personally don't trust in these "tests" since I saw some C compilers being optimized with SSE4 while others were using SSE-SSE2 and maybe others not being optimized at all. I don't know if it's a fair comparison. Razz

Fair point, and I'm not really sure either; a full-on inline assembly block is definitely unfair, whereas use of SSE intrinsics is somewhere in the (darker) gray zone - the compiler is still doing register allocation and stuff. IMHO such benchmarks should stick to standard core language (perhaps allowing #pragmas for parallelization/vectorization).

What's fair to include in such a benchmark, anywyay? Allowing use of standard library functions might give some platforms a huge advantage over others... but at the same time, not allowing stdlib usage is not a good representation of real-life performance of the platform as a whole Smile

_________________
Image - carpe noctem
Post 04 Feb 2013, 23:44
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:43; edited 1 time in total
Post 04 Feb 2013, 23:50
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
OzzY wrote:
I think we should focus on writting better ALGORITHMS instead of worrying with code generation. A bad sorting algorithm for example will be very slow. And HLLs make writting/using pre-coded algorithms easier.

I don't think anybody disagrees that algorithms and data structures is the most important thing to get right...

But once you've got the algorithm right, code generation also matters - even two implementations are both O(n^2), there's going to be quite a runtime difference if one implementation takes 500 cycles per iteration and the other takes 1000 Smile

_________________
Image - carpe noctem
Post 04 Feb 2013, 23:53
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:42; edited 1 time in total
Post 05 Feb 2013, 00:09
View user's profile Send private message Reply with quote
Asm++



Joined: 04 Feb 2013
Posts: 24
Location: On a Chip!
Asm++
HaHaAnonymous wrote:
Asm++ wrote:
Hi everybody, this is my first contribution in FASM forum.

And I thought your first contribution was in this post --> http://board.flatassembler.net/topic.php?t=15058

Just an observation. Sorry if I hurt you (it wasn't my intention).


Hi HaHaAnonymous, actually that was just a Test, not a contribution.

_________________
Binary is nice, but Assembly is better!
Post 05 Feb 2013, 07:23
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Purely on code generation, HLL compilers may generate the latest and greatest ÜSSSE9001 instructions but I still haven't seen one actually use SIMD just a big list of scaler operations - SISD!. Simply changing this to parallel data is already several times faster even without other optimisations (plus it's half the size). This is made worse by the fact that the back end libraries, some written in ASM no less, also suffer from the same problem.

In general, I'd say it's about even for mundane code - the compiler picks up something I miss* and vice versa.

*It once realised there was no side effect to my program and correctly generated "ret" Laughing
Post 07 Feb 2013, 21:49
View user's profile Send private message Reply with quote
booter



Joined: 08 Dec 2006
Posts: 67
booter
I once ported my FASM program to C. The result was really ugly, but it worked. You have so much more flexibility in assembler that whole program and data structures could be optimized using solutions that generally unavailable in HLL (for example non-standard calling conventions). In ASM you can avoid excessive nesting, use the code tailored to your specific needs instead of calling general purpose libraries, etc. If you really proficient in the particular HLL (and know the compiler you use very well) you can write the code in a way that would allow compiler to perform optimization, though even in that case you don't really know for sure.
OzzY wrote:
Good C++ compilers can optimize the code really well.
C++ code? - Yes, they can make it really well, but ASM code with the same functionality can be written very differently and be much faster and much smaller than just C++ hand-translated to ASM.
Post 09 Feb 2013, 07:58
View user's profile Send private message Reply with quote
malpolud



Joined: 18 Jul 2011
Posts: 344
Location: Broken hippocampus
malpolud
OzzY wrote:
I think we should focus on writting better ALGORITHMS instead of worrying with code generation. A bad sorting algorithm for example will be very slow. And HLLs make writting/using pre-coded algorithms easier.
Well said.
booter wrote:
I once ported my FASM program to C. The result was really ugly, but it worked.
And it is not your fault but the compilers? Very Happy
booter wrote:
you can write the code in a way that would allow compiler to perform optimization, though even in that case you don't really know for sure.
A perfect way to write unreadable, incomprehensible and buggy code.
booter wrote:
Yes, they can make it really well, but ASM code with the same functionality can be written very differently and be much faster and much smaller than just C++ hand-translated to ASM.
And will lack all the OO features.

_________________
There's nothing special about it,
It's either there when you're born or not.
Post 09 Feb 2013, 09:46
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
This is quickly turning into one of those boring old discussions, rather than something that could have been more interesting.

booter wrote:
You have so much more flexibility in assembler that whole program and data structures could be optimized using solutions that generally unavailable in HLL (for example non-standard calling conventions)

True, but how much speed are you realistically going to get from different calling conventions? If it's something measurable, you're probably exposing units of work that are too small - and which should be inlined rather than called. Fortunately, compilers are able to inline Smile (and if you're calling small helper functions that are internal to a module, the compiler is free to inline or change calling conventions at will).
Post 09 Feb 2013, 13:45
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1412
Location: Toronto, Canada
AsmGuru62
As I always say: optimizing only needed when code deals with a lot of processing.
Otherwise, ASM and HLL both are ok to use to write the software.
"Religious" optimizing is a bad thing!
Post 09 Feb 2013, 15:41
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 20:53; edited 1 time in total
Post 09 May 2013, 19:18
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
HaHaAnonymous, how many times is the following code executed in the next ten years? Just an approximation. Also, we might look at distribution: for space costs. How many times is the code transmitted, copied, etc...? Some people try to simulate such things. Yet, out of context there is little we can honestly say.

_________________
¯\(°_o)/¯ unlicense.org
Post 09 May 2013, 19:40
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 20:52; edited 1 time in total
Post 09 May 2013, 19:52
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 20:52; edited 1 time in total
Post 09 May 2013, 20:54
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
HaHaAnonymous wrote:
(whose identity will be preserved)

Why? And why not post the original HLL snippet that generated the code?

_________________
Image - carpe noctem
Post 09 May 2013, 22:06
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:  
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next

< 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 YouTube, Twitter.

Website powered by rwasa.