1
2 .file "div_Xsig.S"
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 #include "exception.h"
32 #include "fpu_emu.h"
33
34
35 #define XsigLL(x) (x)
36 #define XsigL(x) 4(x)
37 #define XsigH(x) 8(x)
38
39
40 #ifndef NON_REENTRANT_FPU
41
42
43
44
45 #define FPU_accum_3 -4(%ebp)
46 #define FPU_accum_2 -8(%ebp)
47 #define FPU_accum_1 -12(%ebp)
48 #define FPU_accum_0 -16(%ebp)
49 #define FPU_result_3 -20(%ebp)
50 #define FPU_result_2 -24(%ebp)
51 #define FPU_result_1 -28(%ebp)
52
53 #else
54 .data
55
56
57
58
59 .align 4,0
60 FPU_accum_3:
61 .long 0
62 FPU_accum_2:
63 .long 0
64 FPU_accum_1:
65 .long 0
66 FPU_accum_0:
67 .long 0
68 FPU_result_3:
69 .long 0
70 FPU_result_2:
71 .long 0
72 FPU_result_1:
73 .long 0
74 #endif
75
76
77 .text
78 ENTRY(div_Xsig)
79 pushl %ebp
80 movl %esp,%ebp
81 #ifndef NON_REENTRANT_FPU
82 subl $28,%esp
83 #endif
84
85 pushl %esi
86 pushl %edi
87 pushl %ebx
88
89 movl PARAM1,%esi
90 movl PARAM2,%ebx
91
92 #ifdef PARANOID
93 testl $0x80000000, XsigH(%ebx)
94 je L_bugged
95 #endif
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 clc
116 movl XsigH(%esi),%eax
117 rcrl %eax
118 movl %eax,FPU_accum_3
119 movl XsigL(%esi),%eax
120 rcrl %eax
121 movl %eax,FPU_accum_2
122 movl XsigLL(%esi),%eax
123 rcrl %eax
124 movl %eax,FPU_accum_1
125 movl $0,%eax
126 rcrl %eax
127 movl %eax,FPU_accum_0
128
129 movl FPU_accum_2,%eax
130 movl FPU_accum_3,%edx
131
132
133
134
135
136
137 movl XsigH(%ebx),%ecx
138 addl $1,%ecx
139 jnc LFirst_div_not_1
140
141
142
143 mov %edx,%eax
144 jmp LFirst_div_done
145
146 LFirst_div_not_1:
147 divl %ecx
148
149
150 LFirst_div_done:
151 movl %eax,FPU_result_3
152
153 mull XsigH(%ebx)
154
155 subl %eax,FPU_accum_2
156 sbbl %edx,FPU_accum_3
157
158 movl FPU_result_3,%eax
159 mull XsigL(%ebx)
160
161 subl %eax,FPU_accum_1
162 sbbl %edx,FPU_accum_2
163 sbbl $0,FPU_accum_3
164 je LDo_2nd_32_bits
165
166 #ifdef PARANOID
167 jb L_bugged_1
168 #endif
169
170
171 incl FPU_result_3
172
173 movl XsigL(%ebx),%eax
174 movl XsigH(%ebx),%edx
175 subl %eax,FPU_accum_1
176 sbbl %edx,FPU_accum_2
177
178 #ifdef PARANOID
179 sbbl $0,FPU_accum_3
180 jne L_bugged_1
181 #endif
182
183
184
185
186
187 LDo_2nd_32_bits:
188 movl FPU_accum_2,%edx
189 movl FPU_accum_1,%eax
190
191
192 cmpl XsigH(%ebx),%edx
193 jb LDo_2nd_div
194 ja LPrevent_2nd_overflow
195
196 cmpl XsigL(%ebx),%eax
197 jb LDo_2nd_div
198
199 LPrevent_2nd_overflow:
200
201
202 subl XsigL(%ebx),%eax
203 sbbl XsigH(%ebx),%edx
204 movl %edx,FPU_accum_2
205 movl %eax,FPU_accum_1
206
207 incl FPU_result_3
208
209 #ifdef PARANOID
210 je L_bugged_2
211 #endif
212
213 LDo_2nd_div:
214 cmpl $0,%ecx
215 jnz LSecond_div_not_1
216
217
218 mov %edx,%eax
219 jmp LSecond_div_done
220
221 LSecond_div_not_1:
222 divl %ecx
223
224 LSecond_div_done:
225 movl %eax,FPU_result_2
226
227 mull XsigH(%ebx)
228
229 subl %eax,FPU_accum_1
230 sbbl %edx,FPU_accum_2
231
232 #ifdef PARANOID
233 jc L_bugged_2
234 #endif
235
236 movl FPU_result_2,%eax
237 mull XsigL(%ebx)
238
239 subl %eax,FPU_accum_0
240 sbbl %edx,FPU_accum_1
241 sbbl $0,FPU_accum_2
242
243 #ifdef PARANOID
244 jc L_bugged_2
245 #endif
246
247 jz LDo_3rd_32_bits
248
249 #ifdef PARANOID
250 cmpl $1,FPU_accum_2
251 jne L_bugged_2
252 #endif
253
254
255 movl XsigL(%ebx),%eax
256 movl XsigH(%ebx),%edx
257 subl %eax,FPU_accum_0
258 sbbl %edx,FPU_accum_1
259 sbbl $0,FPU_accum_2
260
261 #ifdef PARANOID
262 jc L_bugged_2
263 jne L_bugged_2
264 #endif
265
266 addl $1,FPU_result_2
267 adcl $0,FPU_result_3
268
269 #ifdef PARANOID
270 jc L_bugged_2
271 #endif
272
273
274
275
276
277 LDo_3rd_32_bits:
278
279
280
281
282 movl FPU_result_3,%eax
283 mull XsigLL(%ebx)
284
285 subl %edx,FPU_accum_1
286
287
288 jnb LTest_over
289
290 movl XsigH(%ebx),%edx
291 addl %edx,FPU_accum_1
292
293 subl $1,FPU_result_2
294 sbbl $0,FPU_result_3
295
296
297 movl FPU_accum_1,%edx
298 cmpl XsigH(%ebx),%edx
299 jb LDo_3rd_div
300
301 movl XsigH(%ebx),%edx
302 addl %edx,FPU_accum_1
303
304 subl $1,FPU_result_2
305 sbbl $0,FPU_result_3
306 jmp LDo_3rd_div
307
308 LTest_over:
309 movl FPU_accum_1,%edx
310
311
312 cmpl XsigH(%ebx),%edx
313 jb LDo_3rd_div
314
315
316 subl XsigH(%ebx),%edx
317 movl %edx,FPU_accum_1
318
319 addl $1,FPU_result_2
320 adcl $0,FPU_result_3
321
322 LDo_3rd_div:
323 movl FPU_accum_0,%eax
324 movl FPU_accum_1,%edx
325 divl XsigH(%ebx)
326
327 movl %eax,FPU_result_1
328
329 movl PARAM3,%esi
330
331 movl FPU_result_1,%eax
332 movl %eax,XsigLL(%esi)
333 movl FPU_result_2,%eax
334 movl %eax,XsigL(%esi)
335 movl FPU_result_3,%eax
336 movl %eax,XsigH(%esi)
337
338 L_exit:
339 popl %ebx
340 popl %edi
341 popl %esi
342
343 leave
344 ret
345
346
347 #ifdef PARANOID
348
349 L_bugged:
350 pushl EX_INTERNAL|0x240
351 call EXCEPTION
352 pop %ebx
353 jmp L_exit
354
355 L_bugged_1:
356 pushl EX_INTERNAL|0x241
357 call EXCEPTION
358 pop %ebx
359 jmp L_exit
360
361 L_bugged_2:
362 pushl EX_INTERNAL|0x242
363 call EXCEPTION
364 pop %ebx
365 jmp L_exit
366 #endif
367 ENDPROC(div_Xsig)