🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.2bsd
Article #59

C compiler (/lib/c1) u_char improvement (#77)

#59
From: Steven M. Schultz
Date: Wed, 02 Sep 1992 20:52
89 lines
2029 bytes
Subject: C compiler (/lib/c1) u_char improvement   (#77)
Index:	lib/ccom/optable 2.11BSD

Description:
	The C compiler doesn't know it can use the same 'bitb' instructions
	for u_char as it can for char.  This results in extra instructions
	being generated to promote the u_char to int before doing a 'bit'.

	This type of construct occurs fairly frequently in the networking
	code because various flag fields are u_char in type.

Repeat-By:

	Compile the test program (using "cc -O -S"):

		char	*b;
		unsigned char *c;
	main()
		{
		if	((b[1] & 4) == 0)
			exit(2);
		if	((c[1] & 4) == 0)
			exit(1);
		}

	Note that the code reads:

	.comm	_b,2
	.comm	_c,2
	.globl	_main
	.text
_main:
~~main:
	jsr	r5,csv
	mov	_b,r0
	bitb	$4,1(r0)
	jne	L4
	mov	$2,(sp)
	jsr	pc,*$_exit
L4:	mov	_c,r0
	movb	1(r0),r0	/* XXX */
	bic	$!377,r0	/* XXX */
	bit	$4,r0
	jne	L3
	mov	$1,(sp)
	jsr	pc,*$_exit
L3:	jmp	cret
	.globl
	.data

  Instead of:

	.comm	_b,2
	.comm	_c,2
	.globl	_main
	.text
_main:
~~main:
	jsr	r5,csv
	mov	_b,r0
	bitb	$4,1(r0)
	jne	L4
	mov	$2,(sp)
	jsr	pc,*$_exit
L4:	mov	_c,r0
	bitb	$4,1(r0)
	jne	L3
	mov	$1,(sp)
	jsr	pc,*$_exit
L3:	jmp	cret
	.globl
	.data

Fix:
	Apply the patch below and reinstall 'c1'.
==============================cut here==============================
*** /usr/src/lib/ccom/optable.old	Wed Oct 23 07:02:57 1991
--- /usr/src/lib/ccom/optable	Tue Jul 28 09:35:00 1992
***************
*** 1839,1844 ****
--- 1839,1846 ----
  	IBE	R,A1
  
  %n*,a
+ %nu*,a
+ %nub*,a
  %	[move6]
  
  %n,a
Technical Details
Message-ID: <1992Sep2.205246.21262@wlbr.iipo.gtegsc.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!awds.imsd.contel.com!wlbr!sms

Show Full Headers
Complete Article Headers
Newsgroups: comp.bugs.2bsd
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!awds.imsd.contel.com!wlbr!sms
From: sms@WLV.IIPO.GTEGSC.COM (Steven M. Schultz)
Subject: C compiler (/lib/c1) u_char improvement    (#77)
Message-ID: <1992Sep2.205246.21262@wlbr.iipo.gtegsc.com>
Sender: news@wlbr.iipo.gtegsc.com (news)
Nntp-Posting-Host: wlv.iipo.gtegsc.com
Organization: GTE Government Systems
Date: Wed, 2 Sep 92 20:52:46 GMT
Lines: 89