chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sh / divide
1 ;
2 ; divide.sh
3 ;
4 ; Various routines of a division-related nature (MDW/TMA)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Overview -------------------------------------------------------------
28 ;
29 ; Functions provided:
30 ;
31 ;  divide
32 ;  div_unsigned
33 ;  div10
34 ;  div_round
35 ;  div_u64x32
36
37                 [       :LNOT::DEF:divide__dfn
38                 GBLL    divide__dfn
39
40 ; --- divide ---
41 ;
42 ; On entry:     R0 == dividend
43 ;               R1 == divisor
44 ;
45 ; On exit:      R0 == quotient
46 ;               R1 == remainder
47 ;
48 ; Use:          A standard divide routine.  Fairly speedy, hopefully.
49 ;               The results are always such that
50 ;
51 ;                       |quotient| <= |(divisor/dividend)|,
52 ;
53 ;                       |remainder| < |divisor|
54 ;
55 ;               and
56 ;
57 ;                       quotient * divisor + remainder == dividend
58
59                 IMPORT  divide
60
61 ; --- div_unsigned ---
62 ;
63 ; On entry:     R0 == dividend
64 ;               R1 == divisor
65 ;
66 ; On exit:      R0 == quotient
67 ;               R1 == remainder
68 ;
69 ; Use:          As for divide, except that it considers its operands to be
70 ;               unsigned.
71
72                 IMPORT  div_unsigned
73
74 ; --- div10 ---
75 ;
76 ; On entry:     R0 == integer to divide
77 ;
78 ; On exit:      R0 == quotient after division by 10
79 ;               R1 == remainder after division by 10
80 ;
81 ; Use:          Divides an integer very quickly by 10.
82 ;
83 ; [Generated by Straylight divc]
84
85                 IMPORT  div10
86
87 ; --- div_round ---
88 ;
89 ; On entry:     R0 == dividend
90 ;               R1 == divisor
91 ;
92 ; On exit:      R0 == quotient, rounded to nearest integer
93 ;               R1 == remainder
94 ;
95 ; Use:          Calculates a rounded-to-nearest quotient, rather than one
96 ;               rounded towards zero, which is what divide returns you.
97 ;
98 ;               The remainder is fiddled during this process, so that the
99 ;               properties
100 ;
101 ;                       quotient * divisor + remainder == dividend
102 ;
103 ;               and
104 ;
105 ;                       |remainder| < |divisor|
106 ;
107 ;               still hold (so the remainder's sign may well change).
108
109                 IMPORT  div_round
110
111 ; --- div_u64x32 ---
112 ;
113 ; On entry:     R0,R1 == dividend (high word in R1)
114 ;               R2 == divisor
115 ;
116 ; On exit:      R0 == quotient
117 ;               R1 == remainder
118 ;
119 ; Use:          Divides a 64-bit unsigned value by a 32-bit unsigned value
120 ;               yielding 32-bit unsigned quotient and remainder.  If there
121 ;               are more than 32 bits of quotient, the return values are
122 ;               undefined.
123
124                 IMPORT  div_u64x32
125
126                 ]
127
128 ;----- That's all, folks ----------------------------------------------------
129
130                 END