Long Longs

Chris Torek chris at umcp-cs.UUCP
Sat Mar 1 12:36:22 AEST 1986


In article <491 at faron.UUCP> bs at faron.UUCP (Bob Silverman) writes:

>Does anyone have a good solution [to getting (b*c)/d and (b*c)%d
>done with double-length instructions]?

and also mentions that one can

>write an assembler routine to do such arithmetic.  However, if one
>does such computations frequently (e.g. millions of times) the cost
>of calling a routine to do it is prohibitive.

One method, used in the 4BSD kernel and in Franz Lisp, is to write
a `sed' script, and run the output of the compiler through this.
Thus what looks like a function call is actually expanded in-line:

	# foo.e - sed script to expand various routines in line
	#
	# Usage: /lib/cpp file.c | /lib/ccom | sed -f foo.e | /lib/c2 | \
	#	as -o file.o
	# (or use .s files if your `as' cannot read pipes).
	#
	# Change calls to `foo' to a `bar' instruction.
	# Foo takes two arguments and presents a return
	# value in r0.
	/calls	$2,_foo/s//movl	(sp)+,r0\
		movl	(sp)+,r1\
		bar	r1,r0/

This costs a few redundant stack operations; these can be avoided
by using the 4.3BSD `inline' program---if you have it---in place
of sed.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list