[comp.arch] divrem- what's the problem?

baum@Apple.COM (Allen J. Baum) (07/27/89)

[]
Forgive me if this was discussed earlier, but here is my summary of the
divrem issue:

1. Its easy to get both results in hardware, simultaneously. (for integers,
   at least)
2. Languages don't support returning both arguments.
3. Hardware doesn't support it very well (MIPs excepted possibly)

It seems to me that the MIPs approach, or a modification thereof, solves the
problem quite nicely. If my program has:
 q= a/b;
 r= a mod b;

then the compiler will produce
 div a,b
 mov hi,q
 div a,b
 mov lo,r
which should be common-subexpression-eliminated to:
 div a,b
 mov hi,q
 mov lo,r

A slight modification, where the divide is a true 3 operand operation, and
the remainder is kept in a special register, would yield:
 div a,b,q
 mov lo,r

Now, did I miss this in the discussion? The language doesn't have to handle
it, if the optimizer does.

--
		  baum@apple.com		(408)974-3385
{decwrl,hplabs}!amdahl!apple!baum