Assembly or ....

Herman Rubin cik at l.cc.purdue.edu
Fri Dec 2 00:26:08 AEST 1988


In article <7740 at boring.cwi.nl>, dik at cwi.nl (Dik T. Winter) writes:
> In article <21390 at apple.Apple.COM> desnoyer at Apple.COM (Peter Desnoyers) writes:
< < In article <1032 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
< < >
< < > For example, suppose we want to
< < >divide a by b, obtaining an integer result i and a remainder c.  I know
< < >of no machine with this instruction, and this is not that unusual an 
< < >instruction to demand.  
< < 
< < I can't think of a machine that doesn't. The only machine language
< < manuals on my desk (68000 and HPC16083) show this instruction.
< < If anyone knows of a machine that doesn't leave the remainder in
< < a register, I would be interested in knowing of it. Such a machine
< < either throws the remainder away or uses some algorithm besides
< < shift-and-subtract. (for instance hard-wired.)

The CDC6000s and its CYBER successors and the CYBER 205 (a totally different
architecture) do not even have integer division.  The CRAYs do not even have
division.  Certainly the VAX and the PYRAMID only have the above properties
if an EDIV rather than a DIV is used for division, and that had a few more
problems than one would expect because they do not use sign-magnitude.  It
takes two instructions even to do the sign extension.

> Well, if I remember right, the we32000 does that (the thing in a 3b2 and a
> tty5620).  It has a divide, quotient, remainder and modulus instruction
> like the ns32000, but unlike the ns32000 no instruction that gives you
> both.  This is (I think) an example of a machine for which the instructions
> are dictated by a HLL (C in this case), which Herman Rubin so deplores.
> On the other hand, this need not be wrong if the operations can be
> pipelined.  E.g. if i/j and i%j take 23 cycles each, but the second can
> start one cycle after the first you do not lose very much.

Can division be pipelined?  In scalar mode on the CYBER 205, division is not
subject for pipelining.  I believe that this is the case because too much of
the dividend must be retained throughout.

> In article <1034 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
< < I do not know if I made it clear in my initial posting, but the problem
< < arises if the types of a, b, and c are floating.  Not that the quote from
< < my paper specifically has i an integer.
> 
> Indeed you did not make that clear (seems evident :-)).
> I know no machines that gives you both quotient and remainder on a floating
> point division, stronger still, before the IEEE standard there was (I
> believe) no machine that would give you the remainder, only quotients
> allowed.  IEEE changed that and many machines now have floating point
> division and floating point remainder, but the result is floating point
> for both.  This explains also why not both are returned.  To obtain the
> (exact) remainder may require a larger number of steps than the
> (inexact) quotient.  I agree however that those machines could return the
> quotient when doing a remainder operation.  Note that IEEE did *not*
> mandate operations that return two results.  So no machine I know does
> return two results; even with sine and cosine, which is implemented on
> many (as an extension to IEEE?).  The CORDIC algorithm will give you fast
> both sine and cosine, but is only efficient in hardware.  But also here,
> pipelining may be a deciding point.
> -- 
> dik t. winter, cwi, amsterdam, nederland
> INTERNET   : dik at cwi.nl
> BITNET/EARN: dik at mcvax

The implementation of quotient and remainder should be a simple modification
of the fixed point algorithm.  Those machines which have floating point
remainder in hardware presumably do this.

Even if CORDIC is not used, returning the sine and cosine would be faster in
software than two function calls.  The corresponding function is in some of
the libraries I know, but I have not seen any other implementation than the
two calls.  This also holds for many other reasonable situations in software.
In software, pipelining is certainly not possible except in vector situations.
The lack of inclusion of a list to the left of the = in a replacement statement
should have been obvious to all HLL designers from day 1; mathematicians have
used functions returning a list for centuries.

-- 
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907
Phone: (317)494-6054
hrubin at l.cc.purdue.edu (Internet, bitnet, UUCP)



More information about the Comp.lang.c mailing list