[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] TCC as portable module compiler
From: |
Basile STARYNKEVITCH |
Subject: |
Re: [Tinycc-devel] TCC as portable module compiler |
Date: |
Tue, 18 Mar 2008 08:56:39 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.9 (X11/20080109) |
Kenneth Forsbäck wrote:
Doesn't TCC output optimized x86 code? Or do you mean any additional
optimisation...?
Last time I looked at the generated code (more than a year ago), tinycc
spilled very simplistic and suboptimal code (similar in quality to the
-O0 option of gcc). For example,
here is a simple C source file
########### ess.c
extern int a, b;
int
f (int x, int y)
{
if (x > y)
return a * x + y;
if (a > 0)
{
int z = b * y;
while (x > 0)
{
x -= a;
z += x;
};
return z;
}
else
return x - b * y;
}
######################
Here is the disassembly (with objdump -d) of the ess-tcc.o generated by tcc
ess-tcc.o: file format elf32-i386
Disassembly of section .text:
00000000 <f>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 81 ec 04 00 00 00 sub $0x4,%esp
9: 8b 45 08 mov 0x8(%ebp),%eax
c: 8b 4d 0c mov 0xc(%ebp),%ecx
f: 39 c8 cmp %ecx,%eax
11: 0f 8e 16 00 00 00 jle 2d <f+0x2d>
17: 8b 05 00 00 00 00 mov 0x0,%eax
1d: 8b 4d 08 mov 0x8(%ebp),%ecx
20: 0f af c1 imul %ecx,%eax
23: 8b 4d 0c mov 0xc(%ebp),%ecx
26: 01 c8 add %ecx,%eax
28: e9 6a 00 00 00 jmp 97 <f+0x97>
2d: 8b 05 00 00 00 00 mov 0x0,%eax
33: 83 f8 00 cmp $0x0,%eax
36: 0f 8e 43 00 00 00 jle 7f <f+0x7f>
3c: 8b 05 00 00 00 00 mov 0x0,%eax
42: 8b 4d 0c mov 0xc(%ebp),%ecx
45: 0f af c1 imul %ecx,%eax
48: 89 45 fc mov %eax,-0x4(%ebp)
4b: 8b 45 08 mov 0x8(%ebp),%eax
4e: 83 f8 00 cmp $0x0,%eax
51: 0f 8e 1b 00 00 00 jle 72 <f+0x72>
57: 8b 45 08 mov 0x8(%ebp),%eax
5a: 8b 0d 00 00 00 00 mov 0x0,%ecx
60: 29 c8 sub %ecx,%eax
62: 89 45 08 mov %eax,0x8(%ebp)
65: 8b 45 fc mov -0x4(%ebp),%eax
68: 8b 4d 08 mov 0x8(%ebp),%ecx
6b: 01 c8 add %ecx,%eax
6d: 89 45 fc mov %eax,-0x4(%ebp)
70: eb d9 jmp 4b <f+0x4b>
72: 8b 45 fc mov -0x4(%ebp),%eax
75: e9 1d 00 00 00 jmp 97 <f+0x97>
7a: e9 18 00 00 00 jmp 97 <f+0x97>
7f: 8b 05 00 00 00 00 mov 0x0,%eax
85: 8b 4d 0c mov 0xc(%ebp),%ecx
88: 0f af c1 imul %ecx,%eax
8b: 8b 4d 08 mov 0x8(%ebp),%ecx
8e: 29 c1 sub %eax,%ecx
90: 89 c8 mov %ecx,%eax
92: e9 00 00 00 00 jmp 97 <f+0x97>
97: c9 leave
98: c3 ret
################
Here is the disassembly of the ess-gcc01.o generated by gcc -O1
ess-gcc01.o: file format elf32-i386
Disassembly of section .text:
00000000 <f>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 0c sub $0xc,%esp
6: 89 1c 24 mov %ebx,(%esp)
9: 89 74 24 04 mov %esi,0x4(%esp)
d: 89 7c 24 08 mov %edi,0x8(%esp)
11: 8b 7d 08 mov 0x8(%ebp),%edi
14: 8b 55 0c mov 0xc(%ebp),%edx
17: 39 d7 cmp %edx,%edi
19: 7e 0e jle 29 <f+0x29>
1b: 89 f8 mov %edi,%eax
1d: 0f af 05 00 00 00 00 imul 0x0,%eax
24: 8d 0c 10 lea (%eax,%edx,1),%ecx
27: eb 39 jmp 62 <f+0x62>
29: 8b 1d 00 00 00 00 mov 0x0,%ebx
2f: 85 db test %ebx,%ebx
31: 7e 22 jle 55 <f+0x55>
33: 89 d1 mov %edx,%ecx
35: 0f af 0d 00 00 00 00 imul 0x0,%ecx
3c: 85 ff test %edi,%edi
3e: 7e 22 jle 62 <f+0x62>
40: 89 de mov %ebx,%esi
42: f7 de neg %esi
44: 89 fa mov %edi,%edx
46: 29 da sub %ebx,%edx
48: 01 d1 add %edx,%ecx
4a: 01 f2 add %esi,%edx
4c: 8d 04 1a lea (%edx,%ebx,1),%eax
4f: 85 c0 test %eax,%eax
51: 7e 0f jle 62 <f+0x62>
53: eb f3 jmp 48 <f+0x48>
55: 89 d0 mov %edx,%eax
57: 0f af 05 00 00 00 00 imul 0x0,%eax
5e: 89 f9 mov %edi,%ecx
60: 29 c1 sub %eax,%ecx
62: 89 c8 mov %ecx,%eax
64: 8b 1c 24 mov (%esp),%ebx
67: 8b 74 24 04 mov 0x4(%esp),%esi
6b: 8b 7c 24 08 mov 0x8(%esp),%edi
6f: 89 ec mov %ebp,%esp
71: 5d pop %ebp
72: c3 ret
########
As you can see, gcc -O1 generates (of course slowly) a code which is
more optimized (less registers spills & reload, less instructions) than
the code generated (very quickly) by tinycc.
########
So tcc generating optimized code is really a myth. Tinycc generates very
quickly bad machine code.
People disliking gcc might also have a look at llvm http://llvm.org
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
Re: [Tinycc-devel] TCC as portable module compiler, Alexander Gladysh, 2008/03/18