Mail Archives: djgpp/1997/04/14/13:04:45
Anthony.Appleyard wrote:
>
> What happens if a switch(i){...} contains `case 0:' and also `case 0xffff:'?
> Does it make a jump table 0x10000 elements long, occupying 0x40000 bytes of
> program memory? Or if a jump table would be too big does djgpp use tests and
> jumps?
You can get the answer yourself for all the questions, by creating
a small source file with all the interesting cases and compile
it with
gcc -S test.c
Then you can look at the created test.s and all you questions
are answered.
(You will see, that gcc will optimize the switch in most
cases as good as you can imagine for speed and size.
Example:
/* file test.c */
int test(int val)
{
switch(val)
{
case 0:
return 0;
case 0xffff:
return 0xffff;
}
}
/* end of file test.c */
/* file test.s after gcc -O -S test.c */
.file "test.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 2
.globl _test
_test:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
testl %eax,%eax
je L3
cmpl $65535,%eax
je L4
leave
ret
.align 2,0x90
L3:
xorl %eax,%eax
leave
ret
.align 2,0x90
L4:
movl $65535,%eax
leave
ret
/* end of file test.s */
Robert
--
*****************************************************************
* Robert Hoehne, Fakultaet fuer Mathematik, TU-Chemnitz-Zwickau *
* Post: Am Berg 3, D-09573 Dittmannsdorf *
* e-Mail: Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE *
* WWW: http://www.tu-chemnitz.de/~rho *
*****************************************************************
- Raw text -