The need for D-scussion (was Re: D Wishlist)

William Sommerfeld wesommer at athena.mit.edu
Mon Mar 14 10:49:15 AEST 1988


In article <3732 at bloom-beacon.MIT.EDU> tada at athena.mit.edu (Michael Zehr) writes:
>a function the returns both a % b and a / b at the same time.
>
>I know I've had to call those routines with the same values consecutively
>in code that needed to run fast, and if i understand the library right,

What library?  If you've got a CISC processor with integer divide in
microcode (such as the VAX), divide is a single instruction.  Modulo
might be, too.

On just about any reasonable processor, if you're computing someething
% or / a power of two, you can turn the operation into an `and' (with
(2**n)-1) or `shift right' (by n), respectively, which _is_ in
hardware

>they
>both compute the pair of values, but a different one is returned.  Why not
>give the option of getting them both at the same time?

Well, the VAX has this `ediv' instruction which does both a divide and
a modulo..  A good compiler would notice the `common subexpression':

	c = a / b;
	d = a % b;

and generate the one hairy instruction or function call.  I think
there's some support in the GNU C compiler for this, but it's turned
off on the VAX because `ediv' is apparantly a real turkey of an
instruction.

					- Bill


	



More information about the Comp.lang.c mailing list