Xref: utzoo comp.lang.c:16368 comp.sys.m68k:1104 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-lcc!pyramid!cbmvax!ditto From: ditto@cbmvax.UUCP (Michael "Ford" Ditto) Newsgroups: comp.lang.c,comp.sys.m68k Subject: Re: Efficientness of Compiler Generated Code Summary: GCC on 68020 is better Keywords: bit-fields operations; HLL instructions; m68000; i8086; C Message-ID: <6007@cbmvax.UUCP> Date: 18 Feb 89 20:49:05 GMT References: <7756@ihlpf.ATT.COM> Reply-To: ditto@cbmvax.UUCP (Michael "Ford" Ditto) Organization: Commodore Technology, West Chester, PA Lines: 53 In article <7756@ihlpf.ATT.COM> pcl@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@kenobi.cts.com - The Unix Programmer's Manual, ...!sdcsvax!crash!kenobi!ford 2nd Edition, June, 1972. ditto@cbmvax.commodore.com