|
|
Up |
  |
Author: Randy YatesRandy Yates Date: Jul 28, 2007 07:18
There may come a day when a compiled language can consistently beat a
good assembly programmer, but that language will never be C. It will
be a new language that has a radically new, high level way of specifying the
algorithm to the compiler, and that has complete control over the generated
code, including data structures.
To make my point, take a simple example.
Consider a fictitious processor that has an architecture with an indirect
addressing mode. That is, the address can be loaded in a register, and
that register be used to generate the address for data used in other instructions.
Now let's also posit that the processor can post-increment-by-one the
address registers used for indirect mode for free, but post-increment
by-two (or other higher values) is not free - i.e., it cost more
cycles.
Now let's say the algorithm to be coded is to sum the real and imaginary
parts of a complex array.
Our programmer, being ignorant of the processor architecture details,
writes the following code:
|
| Show full article (2.54Kb) |
| 122 Comments |
|
  |
Author: ()() Date: Jul 28, 2007 08:12
Check Intel's marketing for its C/C++ compiler.
I'm sure in there somewhere is how it detects
SOA/AOS requirements and reorders data, and
vectors it all using SSE2/3/4 for best effect.
I'm almost as sure that MS/VS will do the same.
All this even without #pragma hints. Since so
few will ever know asm well enough to beat a
current compiler, guru code (potentially) being
better than compiler code is pretty much moot.
Besides, this is more about knowing how to order
data, not a compiler/assembler thing. Had to yawn
|
| Show full article (1.03Kb) |
| no comments |
|
  |
Author: Brad GriffisBrad Griffis Date: Jul 28, 2007 08:16
Randy Yates wrote:
> Also note that if the programmer were to realize this is a problem and
> manually reorganize the data structure, then the resulting code
> becomes SPECIFIC TO THE PROCESSOR. Targeting the code for another
> processor using this new data structure may not be optimal.
>
> Also note that requiring the programmer to know the processor architecture
> defeats, at least in part, the point of a high-level-language since time
> is spent learning things that ideally would be handled by the compiler.
>
> Note that this is absolutely irrefutable. The C language (and every other
> computer language that I know of) is not capable of optimizing this BECAUSE
> IT DOESN'T HAVE CONTROL OVER DATA ALIGNMENT AND STRUCTURE.
Randy,
I think that this debate can actually be thought of in a slightly more
general way. That is, rather than being the "C vs assembly debate" I
think you could think of this as the "Optimization vs Portability
debate". This would encompass not only C vs assembly, but also things
like drivers vs "integrated" code or OS vs simple scheduling (ISRs).
|
| Show full article (2.00Kb) |
| no comments |
|
  |
Author: Tim PrinceTim Prince Date: Jul 28, 2007 09:47
> Check Intel's marketing for its C/C++ compiler.
> I'm sure in there somewhere is how it detects
> SOA/AOS requirements and reorders data, and
> vectors it all using SSE2/3/4 for best effect.
> I'm almost as sure that MS/VS will do the same.
If you checked the marketing, you might have seen that Intel C++
implements complex data type auto-vectorization for SSE3, but requires
C99 syntax for that. Since you are cross-posting to c.l.f, you might
consider that some people would prefer to use Fortran rather than less
optimal asm hacks. Sorry if you are put off by flashbacks to the days
when people called Fortran functions from COBOL rather than do asm.
Beats me why people would rather use asm than embed C99 in C++ or C89.
Don't know whether you consider the
|
| Show full article (0.82Kb) |
| 3 Comments |
|
  |
Date: Jul 28, 2007 13:25
On Jul 29, 2:18 am, Randy Yates ieee.org> wrote:
> There may come a day when a compiled language can consistently beat a
> good assembly programmer, but that language will never be C. It will
> be a new language that has a radically new, high level way of specifying the
> algorithm to the compiler, and that has complete control over the generated
> code, including data structures.
>
> To make my point, take a simple example.
>
> Consider a fictitious processor that has an architecture with an indirect
> addressing mode. That is, the address can be loaded in a register, and
> that register be used to generate the address for data used in other instructions.
>
> Now let's also posit that the processor can post-increment-by-one the
> address registers used for indirect mode for free, but post-increment
> by-two (or other higher values) is not free - i.e., it cost more
> cycles.
>
> Now let's say the algorithm to be coded is to sum the real and imaginary
> parts of a complex array. ...
|
| Show full article (2.85Kb) |
| no comments |
|
  |
Author: Jerry AvinsJerry Avins Date: Jul 28, 2007 13:50
> On Jul 29, 2:18 am, Randy Yates ieee.org> wrote:
>> There may come a day when a compiled language can consistently beat a
>> good assembly programmer, but that language will never be C. It will
>> be a new language that has a radically new, high level way of specifying the
>> algorithm to the compiler, and that has complete control over the generated
>> code, including data structures.
>>
>> To make my point, take a simple example.
>>
>> Consider a fictitious processor that has an architecture with an indirect
>> addressing mode. That is, the address can be loaded in a register, and
>> that register be used to generate the address for data used in other instructions.
>>
>> Now let's also posit that the processor can post-increment-by-one the
>> address registers used for indirect mode for free, but post-increment
>> by-two (or other higher values) is not free - i.e., it cost more
>> cycles.
>>
>> Now let's say the algorithm to be coded is to sum the real and imaginary ...
|
| Show full article (3.33Kb) |
| no comments |
|
  |
Author: christian.bauchristian.bau Date: Jul 28, 2007 14:51
On Jul 28, 3:18 pm, Randy Yates ieee.org> wrote:
> There may come a day when a compiled language can consistently beat a
> good assembly programmer, but that language will never be C. It will
> be a new language that has a radically new, high level way of specifying the
> algorithm to the compiler, and that has complete control over the generated
> code, including data structures.
One mistake that people often make is trying to compare for example
the efficiency of C code vs. assembler code for the same problem. This
is not the right comparison. You have to compare C vs. assembler code,
assuming that two equally competent programmers spend the same amount
of time writing the code.
I can write assembler code that is faster than equivalent C code. If
it takes me one day to write the C code, it takes me a week to write
the assembler code. In that week, I could have written much faster C
code. In two months, I could write equivalent assembler code that is
faster. In the same two months, I could write faster C code.
> To make my point, take a simple example.
>
> Consider a fictitious processor that has an architecture with an indirect
> addressing mode. That is, the address can be loaded in a register, and
> that...
|
| Show full article (2.58Kb) |
| no comments |
|
  |
Author: Logan ShawLogan Shaw Date: Jul 28, 2007 19:36
Jerry Avins wrote:
> Until processors routinely execute and n instructions in parallel, all
> code will be executed sequentially. You might as well write it that way.
n had been 1 for decades. For most new hardware, it's now 2, and it's
already starting to change to 4.
- Logan
|
| |
| no comments |
|
  |
Author: robert bristow-johnsonrobert bristow-johnson Date: Jul 28, 2007 19:51
On Jul 28, 4:50 pm, Jerry Avins ieee.org> wrote:
> Until processors routinely execute and n instructions in parallel, all
> code will be executed sequentially. You might as well write it that way.
and if instructions have conditionals in them, those would have to be
executed sequentially, despite the brawn, no?
r b-j
|
| |
| no comments |
|
  |
Author: Jerry AvinsJerry Avins Date: Jul 28, 2007 21:27
Jerry Avins wrote:
...
> Until processors routinely execute and n instructions in parallel ...
Until processors routinely execute any n instructions in parallel ...
^
Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
| |
| no comments |
|
RELATED THREADS |
  |
|
|
|
|
|