lkml.org 
[lkml]   [2003]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: nasm over gas?
From
Date
insecure <insecure@mail.od.ua> writes:

> On Friday 05 September 2003 15:59, Michael Frank wrote:
> > Just got another reply to this thread which helps to explain what I meant
> > by "better coders in 98+% of applications"
> >
> > On Friday 05 September 2003 19:42, Jörn Engel wrote:
> > > How big is the .text of the asm and c variant? If the text of yours
> > > is much bigger, you just traded 2fish performance for general
> > > performance. Everything else will suffer from cache misses. Forget
> > > your microbenchmark, your variant will make the machine slower.
>
> A random example form one small unrelated program (gcc 3.2):
>
> main:
> pushl %ebp
> pushl %edi
> pushl %esi
> pushl %ebx
> subl $32, %esp
> xorl %ebp, %ebp
> cmpl $1, 52(%esp)
> movl $0, 20(%esp)
> movl $1000000, %edi <----
> movl $1000000, 16(%esp) <----
> movl $0, 12(%esp)
> movl $.LC27, 8(%esp)
> je .L274
> movl $1, %esi
> cmpl 52(%esp), %esi
> jge .L272
>
> No sane human will do that.

>
> main:
> pushl %ebp
> pushl %edi
> pushl %esi
> pushl %ebx
> subl $32, %esp
> xorl %ebp, %ebp
> cmpl $1, 52(%esp)
> movl $0, 20(%esp)
> movl $1000000, %edi
> movl %edi, 16(%esp) <-- save 4 bytes
> movl %ebp, 12(%esp) <-- save 4 bytes
> movl $.LC27, 8(%esp)
> je .L274
> movl $1, %esi
> cmpl 52(%esp), %esi
> jge .L272
>
> And this is only from a cursory examination.

Actually it is no as simple as that. With the instruction that uses
%edi following immediately after the instruction that populates it you cannot
execute those two instructions in parallel. So the code may be slower. The
exact rules depend on the architecture of the cpu.

> What gives you an impression that anyone is going to rewrite linux in asm?
> I _only_ saying that compiler-generated asm is not 'good'. It's mediocre.
> Nothing more. I am not asm zealot.

I think I would agree with that statement most compiler-generated assembly
code is mediocre in general. At the same time I would add most human
generated assembly is poor, and a pain to maintain.

If you concentrate on those handful of places where you need to
optimize that is reasonable. Beyond that there simply are not the
developer resources to do good assembly. And things like algorithmic
transformations in assembly are an absolute nightmare. Where they are
quite simple in C.

And if the average generated code quality bothers you enough with C
the compiler can be fixed, or another compiler can be written that
does a better job, and the benefit applies to a lot more code.

Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:48    [W:0.126 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site