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
49
50
51
52
53
54
55
56
57
58
59 #include <asm/export.h>
60 #define halt .long 0
61
62
63
64
65 #define mask $0
66 #define divisor $1
67 #define compare $28
68 #define tmp1 $3
69 #define tmp2 $4
70
71 #ifdef DIV
72 #define DIV_ONLY(x,y...) x,##y
73 #define MOD_ONLY(x,y...)
74 #define func(x) __div##x
75 #define modulus $2
76 #define quotient $27
77 #define GETSIGN(x) xor $24,$25,x
78 #define STACK 48
79 #else
80 #define DIV_ONLY(x,y...)
81 #define MOD_ONLY(x,y...) x,##y
82 #define func(x) __rem##x
83 #define modulus $27
84 #define quotient $2
85 #define GETSIGN(x) bis $24,$24,x
86 #define STACK 32
87 #endif
88
89
90
91
92 #ifdef INTSIZE
93 #define ufunction func(lu)
94 #define sfunction func(l)
95 #define LONGIFY(x) zapnot x,15,x
96 #define SLONGIFY(x) addl x,0,x
97 #else
98 #define ufunction func(qu)
99 #define sfunction func(q)
100 #define LONGIFY(x)
101 #define SLONGIFY(x)
102 #endif
103
104 .set noat
105 .align 4
106 .globl ufunction
107 .ent ufunction
108 ufunction:
109 subq $30,STACK,$30 # E :
110 .frame $30,STACK,$23
111 .prologue 0
112
113 7: stq $1, 0($30) # L :
114 bis $25,$25,divisor # E :
115 stq $2, 8($30) # L : L U L U
116
117 bis $24,$24,modulus # E :
118 stq $0,16($30) # L :
119 bis $31,$31,quotient # E :
120 LONGIFY(divisor) # E : U L L U
121
122 stq tmp1,24($30) # L :
123 LONGIFY(modulus) # E :
124 bis $31,1,mask # E :
125 DIV_ONLY(stq tmp2,32($30)) # L : L U U L
126
127 beq divisor, 9f
128
129
130
131
132
133
134 .align 4
135 #ifdef INTSIZE
136
137
138
139
140
141
142
143
144 1: cmpult divisor,modulus,compare # E :
145 s8addq divisor,$31,divisor # E :
146 s8addq mask,$31,mask # E :
147 bne compare,1b # U : U L U L
148 #else
149 1: cmpult divisor,modulus,compare # E :
150 nop # E :
151 nop # E :
152 blt divisor, 2f # U : U L U L
153
154 addq divisor,divisor,divisor # E :
155 addq mask,mask,mask # E :
156 unop # E :
157 bne compare,1b # U : U L U L
158 #endif
159
160
161 2:
162
163
164
165
166 #ifdef DIV
167 DIV_ONLY(addq quotient,mask,tmp2) # E :
168 #else
169 nop # E :
170 #endif
171 srl mask,1,mask # U :
172 cmpule divisor,modulus,compare # E :
173 subq modulus,divisor,tmp1 # E :
174
175 #ifdef DIV
176 DIV_ONLY(cmovne compare,tmp2,quotient) # E : Latency 2, extra map slot
177 nop # E : as part of the cmovne
178 srl divisor,1,divisor # U :
179 nop # E : L U L U
180
181 nop # E :
182 cmovne compare,tmp1,modulus # E : Latency 2, extra map slot
183 nop # E : as part of the cmovne
184 bne mask,2b # U : U L U L
185 #else
186 srl divisor,1,divisor # U :
187 cmovne compare,tmp1,modulus # E : Latency 2, extra map slot
188 nop # E : as part of the cmovne
189 bne mask,2b # U : U L L U
190 #endif
191
192 9: ldq $1, 0($30) # L :
193 ldq $2, 8($30) # L :
194 nop # E :
195 nop # E : U U L L
196
197 ldq $0,16($30) # L :
198 ldq tmp1,24($30) # L :
199 nop # E :
200 nop # E :
201
202 #ifdef DIV
203 DIV_ONLY(ldq tmp2,32($30)) # L :
204 #else
205 nop # E :
206 #endif
207 addq $30,STACK,$30 # E :
208 ret $31,($23),1 # L0 : L U U L
209 .end ufunction
210 EXPORT_SYMBOL(ufunction)
211
212
213
214
215
216
217
218
219
220
221
222 .align 4
223 .globl sfunction
224 .ent sfunction
225 sfunction:
226 subq $30,STACK,$30 # E :
227 .frame $30,STACK,$23
228 .prologue 0
229 bis $24,$25,$28 # E :
230 SLONGIFY($28) # E :
231 bge $28,7b # U :
232
233 stq $24,0($30) # L :
234 subq $31,$24,$28 # E :
235 stq $25,8($30) # L :
236 nop # E : U L U L
237
238 cmovlt $24,$28,$24 # E : Latency 2, extra map slot
239 nop # E : as part of the cmov
240 stq $23,16($30) # L :
241 subq $31,$25,$28 # E : U L U L
242
243 stq tmp1,24($30) # L :
244 cmovlt $25,$28,$25 # E : Latency 2, extra map slot
245 nop # E :
246 bsr $23,ufunction # L0: L U L U
247
248 ldq $24,0($30) # L :
249 ldq $25,8($30) # L :
250 GETSIGN($28) # E :
251 subq $31,$27,tmp1 # E : U U L L
252
253 SLONGIFY($28) # E :
254 ldq $23,16($30) # L :
255 cmovlt $28,tmp1,$27 # E : Latency 2, extra map slot
256 nop # E : U L L U : as part of the cmov
257
258 ldq tmp1,24($30) # L :
259 nop # E : as part of the cmov
260 addq $30,STACK,$30 # E :
261 ret $31,($23),1 # L0 : L U U L
262 .end sfunction
263 EXPORT_SYMBOL(sfunction)