<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Sat, 16 Jul 1994 18:20:10 EST
From   : Stephen Quan <quan@...>
Subject: Re: Assembler vs C

Hi, just my comments on C and assembly.

If you are using a C compiler, and you have never tried the -S switch,
then give it a go.  For instance

    % gcc -O -S emulator.c

Then you should see a file in your directory called emulator.s.
I had a cursory glance at the assembly code my compiler and I must
admit it was quite good.  Also, the GNU compiler on our Sparc 2
makes better optimisations than the standard Sun Sparc compiler.

As far as I see it, if you can design your C code well enough, the
compiler will do all/most the assembly code optimisations for you.
Since C is translated to assembly code, C can never be faster than
assembly.  However, I suspect that if the C compiler and your C code
is good enough, then the result you get should be very close to equal
performance.

For cases when you know that the C compiler will not make the
optimisations that you see are obvious, you can have stuff like

        #ifdef MSDOS
           _asm mov ax,57
        #endif
        #ifdef SPARC
           _asm mov 57,%o1
        #endif

ie. you can embed the appropriate assembly code right in your C
programs, and you can have some macros (MSDOS SPARC ...) that control
which assembly code is appropriate for the machine your are compiling
your emulator on.


While we are on performance, I am still trying to match those scores
for the 256^3 loops but am failing miserably!  I can only beat it if
I am running it on a 486DX2-66, then I get 600,000 instr/second.
Otherwise on a plain 386DX-40 it is still 182,000 instr/second.

  /* Sample program I used for bench-testing the emulator. */

               a9 00         LDA #0
               a2 00         LDX #0
               a0 00  .loop2 LDY #0
               88     .loop  DEY
               d0 fd         BNE loop
               ca            DEX
               d0 fa         BNE loop
               ab            TAY
               88            DEY
               9b            TYA
               d0 f3         BNE loop2
               60            RTS
-- 
Stephen Quan (quan@...                 ), SysAdmin, Analyst/Programmer.
Centre for Spatial Information Studies, University of Tasmania, Hobart.
GPO BOX 252C, Australia, 7001.  Local Tel: (002) 202898 Fax: (002) 240282
International Callers use +6102 instead of (002).
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>