1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #define halt .long 0
49
50
51
52
53 #define mask $0
54 #define divisor $1
55 #define compare $28
56
57 #ifdef DIV
58 #define func(x) __div##x
59 #define modulus $2
60 #define quotient $27
61 #define GETSIGN(x) xor $24,$25,x
62 #else
63 #define func(x) __rem##x
64 #define modulus $27
65 #define quotient $2
66 #define GETSIGN(x) bis $24,$24,x
67 #endif
68
69
70
71
72 #ifdef INTSIZE
73 #define ufunction func(lu)
74 #define sfunction func(l)
75 #define LONGIFY(x) zapnot x,15,x
76 #define SLONGIFY(x) addl x,0,x
77 #else
78 #define ufunction func(qu)
79 #define sfunction func(q)
80 #define LONGIFY(x)
81 #define SLONGIFY(x)
82 #endif
83
84 .set noat
85 .globl ufunction
86 .ent ufunction
87 ufunction:
88 subq $30,32,$30
89 stq $0, 0($30)
90 stq $1, 8($30)
91 stq $2,16($30)
92
93 bis $25,$25,divisor
94 bis $24,$24,modulus
95 bis $31,$31,quotient
96 LONGIFY(divisor)
97 LONGIFY(modulus)
98 beq divisor, 9f
99 bis $31,1,mask
100
101
102 1: cmpult divisor,modulus,compare
103 blt divisor, 3f
104 addq divisor,divisor,divisor
105 addq mask,mask,mask
106 bne compare,1b
107
108
109 2: srl divisor,1,divisor
110 beq mask,9f
111 srl mask,1,mask
112 3: cmpule divisor,modulus,compare
113 beq compare,2b
114 addq quotient,mask,quotient
115 beq mask,9f
116 subq modulus,divisor,modulus
117 br 2b
118
119 9: ldq $0, 0($30)
120 ldq $1, 8($30)
121 ldq $2, 16($30)
122 addq $30,32,$30
123 ret $31,($23),1
124 .end ufunction
125
126
127
128
129
130
131
132
133
134
135
136 .globl sfunction
137 .ent sfunction
138 sfunction:
139 bis $24,$25,$28
140 SLONGIFY($28)
141 bge $28,ufunction
142 subq $30,32,$30
143 stq $23,0($30)
144 stq $24,8($30)
145 stq $25,16($30)
146 subq $31,$24,$28
147 cmovlt $24,$28,$24
148 subq $31,$25,$28
149 cmovlt $25,$28,$25
150 bsr $23,ufunction
151 ldq $23,0($30)
152 ldq $24,8($30)
153 ldq $25,16($30)
154 addq $30,32,$30
155 GETSIGN($28)
156 SLONGIFY($28)
157 bge $28,1f
158 subq $31,$27,$27
159 1: ret $31,($23),1
160 .end sfunction