Efficientness of Compiler Generated Code
Michael "Ford" Ditto
ditto at cbmvax.UUCP
Sun Feb 19 06:49:05 AEST 1989
In article <7756 at ihlpf.ATT.COM> pcl at ihlpf.UUCP (pcl) writes:
>Anyway, the following C program generates the corresponding 8086 and 68k
>instructions which seem quite inefficient. Any optimization suggestions?
>
>********* C ***********
>
>struct DHDR {
> unsigned short gfi: 4;
> unsigned short lci:12;
> unsigned short pr : 3;
> unsigned short m : 1;
> unsigned short ps : 3;
> unsigned short x : 1;
>};
>
>char pktbuf[1024];
>struct DHDR *dhp;
>main()
>{
> dhp = (struct DHDR *)pktbuf;
> dhp->pr++;
> dhp->ps++;
>}
> [ really awful compiler output deleted ]
The 68020 has bit field instructions which help quite a bit.
Here's the 68020 code that GCC generates:
(using GCC v1.19: gcc -m68020 -fomit-frame-pointer -O -S T.c)
text
even
global main
main:
mov.l &pktbuf,dhp
bfextu pktbuf+2{&0:&3},%d0
add.l &1,%d0
bfins %d0,pktbuf+2{&0:&3}
bfextu pktbuf+2{&4:&3},%d0
add.l &1,%d0
bfins %d0,pktbuf+2{&4:&3}
rts
comm dhp,4
comm pktbuf,1024
--
-=] Ford [=-
"The number of Unix installations (In Real Life: Mike Ditto)
has grown to 10, with more expected." ford at kenobi.cts.com
- The Unix Programmer's Manual, ...!sdcsvax!crash!kenobi!ford
2nd Edition, June, 1972. ditto at cbmvax.commodore.com
More information about the Comp.lang.c
mailing list