;
; divide.sh
;
; Various routines of a division-related nature (MDW/TMA)
;
;  1994-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's Sapphire library.
;
; Sapphire is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; Sapphire is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Sapphire.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

;----- Overview -------------------------------------------------------------
;
; Functions provided:
;
;  divide
;  div_unsigned
;  div10
;  div_round
;  div_u64x32

		[	:LNOT::DEF:divide__dfn
		GBLL	divide__dfn

; --- divide ---
;
; On entry:	R0 == dividend
; 		R1 == divisor
;
; On exit:	R0 == quotient
;		R1 == remainder
;
; Use:		A standard divide routine.  Fairly speedy, hopefully.
;		The results are always such that
;
;			|quotient| <= |(divisor/dividend)|,
;
;			|remainder| < |divisor|
;
;		and
;
;			quotient * divisor + remainder == dividend

		IMPORT	divide

; --- div_unsigned ---
;
; On entry:	R0 == dividend
; 		R1 == divisor
;
; On exit:	R0 == quotient
;		R1 == remainder
;
; Use:		As for divide, except that it considers its operands to be
;		unsigned.

		IMPORT	div_unsigned

; --- div10 ---
;
; On entry:	R0 == integer to divide
;
; On exit:	R0 == quotient after division by 10
;		R1 == remainder after division by 10
;
; Use:		Divides an integer very quickly by 10.
;
; [Generated by Straylight divc]

		IMPORT	div10

; --- div_round ---
;
; On entry:	R0 == dividend
;		R1 == divisor
;
; On exit:	R0 == quotient, rounded to nearest integer
;		R1 == remainder
;
; Use:		Calculates a rounded-to-nearest quotient, rather than one
;		rounded towards zero, which is what divide returns you.
;
;		The remainder is fiddled during this process, so that the
;		properties
;
;			quotient * divisor + remainder == dividend
;
;		and
;
;			|remainder| < |divisor|
;
;		still hold (so the remainder's sign may well change).

		IMPORT	div_round

; --- div_u64x32 ---
;
; On entry:	R0,R1 == dividend (high word in R1)
;		R2 == divisor
;
; On exit:	R0 == quotient
;		R1 == remainder
;
; Use:		Divides a 64-bit unsigned value by a 32-bit unsigned value
;		yielding 32-bit unsigned quotient and remainder.  If there
;		are more than 32 bits of quotient, the return values are
;		undefined.

		IMPORT	div_u64x32

		]

;----- That's all, folks ----------------------------------------------------

		END
