[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Asm or C (was: Re: New Web browser for MiNT)



On Wed, 1 Apr 1998, Konrad Kokoszkiewicz wrote:

> problem. At least, not for C programmers. But this gave me occasion to
> notice once more that C programmers become nervous when you prefer other
> stuff (speed, compactness) over portability and if you use the magic
> phrase "pure assembler". OK. Perhaps assembler is not the One and Only
> Programming Language, but C is neither, is it?

*Ahem* I knew assembler before I knew C... as this would have any
difference.

Some people seem to have gotten the idea I suddenly think nothing should
be written in assembler. Blah.

> 
> The fact is that the development time for asembler programs is longer,
> because of hand optimization. 

It's not just because of this either. It's because with C you don't have
to do every little minor thing and you've got piles of C code everywhere
on the net that you can use.

>  But it is also a fact, that assembler
> programs are faster than anything else, and no sophisticated argumentation
> can change this fact. If C compilers would be really so good in
> optimizations, as you argue, the demoscene would use C. But they all use
> assembler for some strange reason (let me guess: speed?).

OTOH game coders, database coders, simulation coders etc. etc. all use C
(or some high-level language) so I guess the speed difference isn't always
that great after all (of course this is often on faster processors than
the m68k and possibly better cmopilers - who knows). I have never said
that you could not get faster with assembler and it's fairly obvious that
demos should be coded in that (it is the natural way to access
hardware-specific stuff anyway). My only claim is that some applications
gain more from portability, extensibility and actually being completed
(for some reason many coders who start stuff in asm have problems ever
completing it..) than what they would by using lots of extra time for
optimizing parts that only affect a few percent of the application speed.


> I can give an example. With C source code. If you will be able to make it
> at least two times slower, than my asm equivalent, I will be pleased to
> give all honours back. :)

If nothing else, the compiler can be updated to compile the particular
code better. This is what is commonly the practise nowadays.

> Of course, I easily believe, that C compiler is able to create a
> reasonable good code, if you use proper syntax in your source file. But do
> you all think that, following Andreas' example:
> 
> 	a = ((i << 8) | (i >> (8)));
> 
> is really easier and less cryptic than rol.w d0 ?

Possibly not, but then again the following is clearer in C than what it
would be in asm:

char a[20]="hello ", b[]="world";

strcat(a, b);


The more complex the data, the easier it is in C in comparison to asm.
Naturally it all falls back to assembler in the end so strcat is really
doing the same thing, but you have piles of ready stuff in C so it makes
things a lot easier. Also if one wanted an example that simply relies on C
syntax instead of extra functions it would probably be quite easy to
conjure up an example based on handling structures and arrays that would
become quite complex looking in asm.

Simple tiny operations aren't necessarily clearer in C (like rolling or
whatever). They're so simple that differences can only be minor. The
differences come when you have a C program split into a dozen files, with
thousands of lines of code, using many header files and libraries.. The
world is full of C coders who could easily continue that. I have yet to
see anyone extend a really really large program completely written in
assembler - especially after a year or so since it was written ;-)
 
(it's quite natural that some bitwise operations are cryptic in C. The
purpose of C is to create a language with a simple, generic syntax. They
*could* add operators for every possible bitwise operation, but that would
add quite a lot to the complexity of the language).

         -     ---------- = = ---------//--+
         |    /     Kristoffer Lawson      |    www.fishpool.com
         +-> |    setok@fishpool.com       |  - - --+
             |-- Fishpool Creations Ltd - /         |
             +-------- = - - - = ---------      /~setok/