Efficientness of Compiler Generated Code

pcl pcl at ihlpf.ATT.COM
Sat Feb 18 09:32:05 AEST 1989


I wonder if any microprocessor supports HLL instruction such as:

incbf memloc,bf_offset,bf_len		/* increment a bit field */
setbf memloc,bf_offset,bf_len,immed	/* increment a bit field */

Or perhaps I am daydreaming!

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++;
}

********* 8086 ***********

_main	proc	near
;	?debug	L 14
	mov	word ptr DGROUP:_dhp,offset DGROUP:_pktbuf
;	?debug	L 15
	mov	bx,word ptr DGROUP:_dhp
	mov	ax,word ptr [bx+2]
	inc	ax
	and	ax,7
	and	word ptr [bx+2],-8
	or	word ptr [bx+2],ax
;	?debug	L 16
	mov	bx,word ptr DGROUP:_dhp
	mov	ax,word ptr [bx+2]
	add	ax,16
	and	ax,112
	and	word ptr [bx+2],-113
	or	word ptr [bx+2],ax
@1:
;	?debug	L 17
	ret	
_main	endp

********* 68000 ***********

main:
	link	%fp,$.F1
	moveml	<.RM1>,-(%sp)
	.ln	1
	.def	.bf;	.val	.;	.scl	101;	.type	0;	.line	1;	.endef
	.ln	2
/	line 14, file "x.c"
	movel	$pktbuf,dhp	/ assign 14
	.ln	3
/	line 15, file "x.c"
	movel	dhp,%a0	/ opltype 7
	clr	%d0
	moveb	2(%a0),%d0
	lsr 	$5,%d0
	/ fld 1
	add	$1,%d0	/ asg opsimp 1
	movel	dhp,%a0	/ opltype 7
	move	%d0,%d1
	lslb	$5,%d1
	andb	$0x1f,2(%a0)
	orb	%d1,2(%a0)	/ assign 9
	.ln	4
/	line 16, file "x.c"
	movel	dhp,%a0	/ opltype 7
	clr	%d0
	moveb	2(%a0),%d0
	lsr 	$1,%d0
	and 	$7,%d0
	/ fld 3
	add	$1,%d0	/ asg opsimp 1
	movel	dhp,%a0	/ opltype 7
	move	%d0,%d1
	lslb	$1,%d1
	andb	$0xe,%d1
	andb	$0xf1,2(%a0)
	orb	%d1,2(%a0)	/ assign 9
.46:
	.def	.ef;	.val	.;	.scl	101;	.type	0;	.line	5;	.endef
	.ln	5
	unlk	%fp
	rts



More information about the Comp.lang.c mailing list