Faster C

Russell Kent kent at tifsie.UUCP
Tue Feb 9 10:52:20 AEST 1988


in article <473 at aati.UUCP>, fish at aati.UUCP (William G. Fish) says:
> I wish to make the following C code run as fast as possible under 4.1 BSD 
> on a VAX 11/750.  I've seen VAX instructions such as movc3 and cmpc3 make
> code run 10 to 50 times faster.  Are there any CISC instructions that can
> be used in this case?
    [ code fragment deleted - RAK ]
> Bill Fish                       Analysis & Technology
> 321 River Road                  153 Williams Street
> Mystic, CT 06355                New London, CT 06320
> (203) 536-3301 (evenings)       (203) 444-7722 (days)
> (203) 536-0137 (2nd line)       ihnp4!{hsi,rayssd}!aati!fish

Using suggestions from David Keppel, Chris Torek, and Thomas Truscott, as
well as generous use of a 1981 vintage VAX Architecture Handbook, and
Ultrix cc's "-S" option, I was able to handcraft this assembler routine.
PLEASE be very careful to check that it does what you _really_ think
you want (I have been known to mis-interpret C code fragments :-).
"``Interpret??'' Hey Mo, I thought C was a compiled language, nyuck nyuck"

The cute little "jump" opcodes (you mean you've never used a jgeq opcode
on a VAX??) are the compiler's love notes to the optimizer.

Write this into a file ending with ".s" and feed it to your compiler.
Caveat emptor.

Russell Kent
(Beware the signature at the bottom)
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---
LL0:
	.data
	.text
	.align	2
	.globl	_scan

/* 			    scan(in, out, c, C, S)
       				register short *in;
       				register float *out;
       				register c;
       				int C, S;
*/
_scan:
	.word	0x0FC0		/* save r11-r6 */
/*
    				register sample;
    				register peak;
    				register s;
*/
	jbr 	L14		/* cause possible page fault */
L15:
	movl	4(ap),r11       /* load "in"      into r11 */
	movl	8(ap),r10	/* load "out"     into r10 */
	movl	12(ap),r9	/* load "c"       into r9  */
    				/*      "sample"  isin r8  */
    				/*      "peak"    isin r7  */
    				/*      "s"       isin r6  */
			
	movl	20(ap),r6	/* s = S+1;            */
	incl	r6
	jbr	L17		/* use sobgtr at bottom */
L18:
	cvtwl	(r11)[r9],r8	/* sample = in[c]      */
	cvtlf	r8,(r10)+	/* *out++ = sample     */
		/* this will set the condition bits so no "test" is needed */
	jgeq	L19		/* if (sample < 0)     */
	mnegl	r8,r8		/*     sample= -sample */
L19:
	cmpl	r7,r8		/* if (peak < sample)  */
	jgeq	L16
	movl	r8,r7		/*     peak = sample   */
L16:
	addl2	16(ap),r9	/*       c += C        */
L17:
	sobgtr	r6,L18		/* bottom of loop      */
	movl	r7,r0		/* return peak;        */
	ret
L14:
	jbr 	L15
	.data
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---
-- 
Russell Kent                    Phone: +1 214 995 3501
Texas Instruments               UUCP address:
P.O. Box 655012   MS 3635       ...!convex!smu!tifsie!kent
Dallas, TX 75265                ...!ut-sally!im4u!ti-csl!tifsie!kent



More information about the Comp.unix.wizards mailing list