[Top][All Lists]

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

Re: [Tinycc-devel] ASM Output?

From: Dave Dodge
Subject: Re: [Tinycc-devel] ASM Output?
Date: Tue, 16 Nov 2004 19:52:50 -0500
User-agent: Mutt/1.4.2i

On Wed, Nov 17, 2004 at 01:05:28AM +0100, Fabrice Bellard wrote:
> Another point is that there is no way to easily improve the TinyCC code 
> generator - it is a "dead end" and I knew it from the start.

While normally I'd say that gcc does better at optimizing code, I hit
this one curious test case the other night where tcc seems to beat it
easily and I don't understand why:

#include <stdio.h>
#include <stdint.h>

static inline uint8_t foo(uint8_t const x)
        static uint8_t table[16] = {
        return table[x % 0xfU];

int main(void)
        int ch;
        while((ch = getc(stdin)) != EOF)
        return 0;

Running 4M of data from /dev/urandom through this program, I get
times like this:

  gcc 3.4.3    real: 1.062s   user: 1.040s   sys: 0.020s
  tcc 0.9.22   real: 0.341s   user: 0.330s   sys: 0.010s

They generate the same data, but tcc's version does it much more
quickly.  This speed difference seems to hold for more complex
versions of that function foo and larger amounts of data.  I've done
this with 256-byte lookup tables and 10M of data and tcc's version
still runs 3x faster or better.

Perhaps even more interesting is that my initial discovery of this had
a switch statement instead of a lookup table.  gcc generated a single
jump table for the switch while tcc generated a long sequence of
compares and jumps.  tcc's version still ran 3x the speed of gcc's.

Perhaps there's something in the way the I/O code gets generated that
causes this?  I've glanced at the objdump output but nothing jumps
out at me.

                                                  -Dave Dodge

reply via email to

[Prev in Thread] Current Thread [Next in Thread]