[net.arch] Integer divide

rshepherd@euroies.UUCP (02/05/86)

At INMOS we had to make decisions about the definition of
integer division and remainder.  We had a language, occam, to
design, and a processor, the transputer, to specify.  We were
aware that there was a choice to be made and considered both
the posibilities which have been discussed in this newsgroup.
We were also aware of other possibilities, such as a version of
integer division which give the nearest integer to the
quotient (I know of one machine which implements this - and
there are some good reasons for doing this).
 
We eventually defined the remainder operator in occam to give
the sign of a non-zero remainder equaling the sign of the
dividend (what some people seem to regard as the
mathematically incorrect version).  We did this for a number
of reasons, one of them being that it was what most other
machines did, and was also what other languages tended to do
(those that bother to define division and remainder for
negative numbers), another being the fact that computer
scientists (if not number theorists) find the identity
 
                |a|/|b| = |a/b|
 
irresitable.  The consistancy was important as it would ease
the implementation of occam on other other computers, and
ease the implementation of other languages on the transputer.
(Incidentally, I seem to recall that ADA provides both
remainder and modulo operators (ie both definitions)).
 
There are some other points that I think are worth noting
about the transputer instruction set as people have
mentioned related matters in this newsgroup. (Sorry, no
references).
 
Firstly we actually have separate DIVide and REMainder
instructions. This follows from the philosophy of providing
instructions which correspond to operations provided in high level languages.
 
There is, however, one place where divide with remainder is
very useful and that is in the implementation of long
division. For that purpose the transputer has a LONG DIVide
instruction. This instruction takes a double length UNSIGNED
integer and divides it by a single length UNSIGNED integer,
returning the single length quotient and remainder.
 
As to the implementation costs of the two different definitions
of integer division, I'm sure that they're not very
different.  We found the direct implementation of a non-restoring
SIGNED division rather expensive.  Our DIVision and REMainder
micro-code unsigns the operands (remembering their signs),
performs the division (generating both quotient and
remainder) and then generates the appropriately signed
quotient or remainder.  With this method it makes little
difference which division rule you choose.
 
Hope this is of interest,
 
Roger Shepherd, INMOS Ltd, Bristol], UK
 
INMOS and occam are trademarks of the INMOS group of
companies.
ADA is a trademark of the DOD.
-- 
Roger Shepherd, INMOS Ltd, Whitefriars, Lewins Mead, Bristol, BS1 2NP, UK
Tel: +44 272 290861
UUCP: ...!mcvax!euroies!rshepherd