C language hacking

Geoff Kuenning geoff at desint.UUCP
Thu Nov 15 07:14:34 AEST 1984


In article <5715 at brl-tgr.ARPA> Doug Gwyn <gwyn at brl-tgr.ARPA> writes:

>I find that frequently I need both the quotient and remainder of
>two integers:	a / b	a % b
>Since most (maybe all) machine architectures compute these at the
>same time, it sure would be nice to be able to get both results
>rather than wastefully reexecuting precisely the same instructions
>a second time.  This becomes particularly bothersome when "a" & "b"
>are fairly complicated expressions.  I have no idea what a good
>syntax for such an operation would be.

This is the business of the optimizer, not the programmer.  Even a peephole
optimizer should be able to handle:

	x = a / b;
	y = a % b;

and any optimizer that can handle common subexpressions can take care of this
even when a and b are complex expressions.

C already has too many "features" that are basically ways for the
programmer to compensate for poor optimizers.  Let's move into the 20th
century here.

>It would also be nice if sin( x ) and cos( x ) could be computed
>simultaneously with reduced cost.  I doubt if this is possible
>but would like to know if it is.

It is.  The obvious way is to make use of the identity

    sin (x) == sqrt (1 - cos (x) * cos (x))

which can be computed slightly faster than sin(x) on some architectures.
I think that there are also numerical algorithms that generate both
functions at once, though I am out of my field here.  I know I have run into
a routine (in the Evans and Sutherland Picture System library?) named 'sincos',
which returned both values at once for use in rotation calculations, but it
may have been fixed-point.
-- 

	Geoff Kuenning
	First Systems Corporation
	...!ihnp4!trwrb!desint!geoff



More information about the Comp.lang.c mailing list