source: trunk/minix/lib/i86/em/em_fp8087.s@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 7.2 KB
Line 
1.define .adf4, .adf8, .sbf4, .sbf8, .mlf4, .mlf8, .dvf4, .dvf8
2.define .ngf4, .ngf8, .fif4, .fif8, .fef4, .fef8
3.define .cif4, .cif8, .cuf4, .cuf8, .cfi, .cfu, .cff4, .cff8
4.define .cmf4, .cmf8
5.sect .text; .sect .rom; .sect .data; .sect .bss
6
7! $Header: /cvsup/minix/src/lib/i86/em/em_fp8087.s,v 1.1.1.1 2005/04/21 14:56:13 beng Exp $
8
9! Implement interface to floating point package for Intel 8087
10
11 .sect .rom
12one:
13 .data2 1
14two:
15 .data2 2
16bigmin:
17 .data2 0, -32768
18
19 .sect .text
20.adf4:
21 mov bx,sp
22 wait
23 flds 2(bx)
24 wait
25 fadds 6(bx)
26 wait
27 fstps 6(bx)
28 wait
29 ret
30.adf8:
31 mov bx,sp
32 wait
33 fldd 2(bx)
34 wait
35 faddd 10(bx)
36 wait
37 fstpd 10(bx)
38 wait
39 ret
40
41.sbf4:
42 mov bx,sp
43 wait
44 flds 6(bx)
45 wait
46 fsubs 2(bx)
47 wait
48 fstps 6(bx)
49 wait
50 ret
51
52.sbf8:
53 mov bx,sp
54 wait
55 fldd 10(bx)
56 wait
57 fsubd 2(bx)
58 wait
59 fstpd 10(bx)
60 wait
61 ret
62
63.mlf4:
64 mov bx,sp
65 wait
66 flds 2(bx)
67 wait
68 fmuls 6(bx)
69 wait
70 fstps 6(bx)
71 wait
72 ret
73.mlf8:
74 mov bx,sp
75 wait
76 fldd 2(bx)
77 wait
78 fmuld 10(bx)
79 wait
80 fstpd 10(bx)
81 wait
82 ret
83
84.dvf4:
85 mov bx,sp
86 wait
87 flds 6(bx)
88 wait
89 fdivs 2(bx)
90 wait
91 fstps 6(bx)
92 wait
93 ret
94
95.dvf8:
96 mov bx,sp
97 wait
98 fldd 10(bx)
99 wait
100 fdivd 2(bx)
101 wait
102 fstpd 10(bx)
103 wait
104 ret
105
106.ngf4:
107 mov bx,sp
108 wait
109 flds 2(bx)
110 wait
111 fchs
112 wait
113 fstps 2(bx)
114 wait
115 ret
116
117.ngf8:
118 mov bx,sp
119 wait
120 fldd 2(bx)
121 wait
122 fchs
123 wait
124 fstpd 2(bx)
125 wait
126 ret
127
128.fif4:
129 mov bx,sp
130 push bx ! make room for FP status word
131 wait
132 flds 4(bx)
133 wait
134 fmuls 8(bx) ! multiply
135 wait
136 fld st ! copy result
137 wait
138 ftst ! test sign; handle negative separately
139 wait
140 fstsw -2(bx)
141 wait
142 mov ax,-2(bx)
143 sahf ! result of test in condition codes
144 jb 1f
145 frndint ! this one rounds (?)
146 wait
147 fcom st(1) ! compare with original; if <=, then OK
148 wait
149 fstsw -2(bx)
150 wait
151 mov ax,-2(bx)
152 sahf
153 jbe 2f
154 fisubs one ! else subtract 1
155 wait
156 jmp 2f
1571: ! here, negative case
158 frndint ! this one rounds (?)
159 wait
160 fcom st(1) ! compare with original; if >=, then OK
161 wait
162 fstsw -2(bx)
163 wait
164 mov ax,-2(bx)
165 sahf
166 jae 2f
167 fiadds one ! else add 1
168 wait
1692:
170 fsub st(1),st ! subtract integer part
171 wait
172 mov bx,2(bx)
173 fstps (bx)
174 wait
175 fstps 4(bx)
176 wait
177 pop bx
178 ret
179
180.fif8:
181 mov bx,sp
182 push bx ! make room for FP status word
183 wait
184 fldd 4(bx)
185 wait
186 fmuld 12(bx) ! multiply
187 wait
188 fld st ! and copy result
189 wait
190 ftst ! test sign; handle negative separately
191 wait
192 fstsw -2(bx)
193 wait
194 mov ax,-2(bx)
195 sahf ! result of test in condition codes
196 jb 1f
197 frndint ! this one rounds (?)
198 wait
199 fcom st(1) ! compare with original; if <=, then OK
200 wait
201 fstsw -2(bx)
202 wait
203 mov ax,-2(bx)
204 sahf
205 jbe 2f
206 fisubs one ! else subtract 1
207 wait
208 jmp 2f
2091: ! here, negative case
210 frndint ! this one rounds (?)
211 wait
212 fcom st(1) ! compare with original; if >=, then OK
213 wait
214 fstsw -2(bx)
215 wait
216 mov ax,-2(bx)
217 sahf
218 jae 2f
219 fiadds one ! else add 1
220 wait
2212:
222 fsub st(1),st ! subtract integer part
223 mov bx,2(bx)
224 fstpd (bx)
225 wait
226 fstpd 8(bx)
227 wait
228 pop bx
229 ret
230
231.fef4:
232 ! this could be simpler, if only the
233 ! fxtract instruction was emulated properly
234 mov bx,sp
235 mov ax,6(bx)
236 and ax,#077600
237 je 1f ! zero exponent
238 mov cx,#7
239 shr ax,cl
240 sub ax,#126
241 mov cx,ax ! exponent in cx
242 mov ax,6(bx)
243 and ax,#0100177
244 or ax,#0037400 ! load -1 exponent
245 mov dx,4(bx)
246 mov bx,2(bx)
247 mov 4(bx),ax
248 mov 2(bx),dx
249 mov (bx),cx
250 ret
2511: ! we get here on zero exp
252 mov ax,6(bx)
253 and ax,#0177
254 or ax,4(bx)
255 jne 1f ! zero result
256 xor ax,ax
257 mov bx,2(bx)
258 mov (bx),ax
259 mov 2(bx),ax
260 mov 4(bx),ax
261 ret
2621: ! otherwise unnormalized number
263 mov cx,6(bx)
264 and cx,#0100177
265 mov dx,cx
266 and cx,#0x8000
267 mov ax,#-125
2682:
269 test dx,#0x80
270 jne 1f
271 dec ax
272 shl 4(bx),#1
273 rcl dx,#1
274 or dx,cx
275 jmp 2b
2761:
277 mov cx,4(bx)
278 mov bx,2(bx)
279 mov (bx),ax
280 mov 2(bx),cx
281 and dx,#0100177
282 or dx,#0037400 ! load -1 exponent
283 mov 4(bx),dx
284 ret
285
286.fef8:
287 ! this could be simpler, if only the
288 ! fxtract instruction was emulated properly
289 mov bx,sp
290 mov ax,10(bx)
291 and ax,#077760
292 je 1f ! zero exponent
293 mov cx,#4
294 shr ax,cl
295 sub ax,#1022
296 mov cx,ax ! exponent in cx
297 mov ax,10(bx)
298 and ax,#0100017
299 or ax,#0037740 ! load -1 exponent
300 push 8(bx)
301 push 6(bx)
302 push 4(bx)
303 mov bx,2(bx)
304 pop 2(bx)
305 pop 4(bx)
306 pop 6(bx)
307 mov 8(bx),ax
308 mov (bx),cx
309 ret
3101: ! we get here on zero exp
311 mov ax,10(bx)
312 and ax,#017
313 or ax,8(bx)
314 or ax,6(bx)
315 or ax,4(bx)
316 jne 1f ! zero result
317 xor ax,ax
318 mov bx,2(bx)
319 mov (bx),ax
320 mov 2(bx),ax
321 mov 4(bx),ax
322 mov 6(bx),ax
323 mov 8(bx),ax
324 ret
3251: ! otherwise unnormalized number
326 mov cx,10(bx)
327 and cx,#0100017
328 mov dx,cx
329 and cx,#0x8000
330 mov ax,#-1021
3312:
332 test dx,#0x10
333 jne 1f
334 dec ax
335 shl 4(bx),#1
336 rcl 6(bx),#1
337 rcl 8(bx),#1
338 rcl dx,#1
339 or dx,cx
340 jmp 2b
3411:
342 and dx,#0100017
343 or dx,#0037740 ! load -1 exponent
344 mov cx,8(bx)
345 push 6(bx)
346 push 4(bx)
347 mov bx,2(bx)
348 mov (bx),ax
349 mov 8(bx),dx
350 mov 6(bx),cx
351 pop 2(bx)
352 pop 4(bx)
353 ret
354
355.cif4:
356 mov bx,sp
357 cmp 2(bx),#2
358 jne 1f
359 wait
360 filds 4(bx)
361 wait
362 fstps 2(bx)
363 wait
364 ret
3651:
366 wait
367 fildl 4(bx)
368 wait
369 fstps 4(bx)
370 wait
371 ret
372
373.cif8:
374 mov bx,sp
375 cmp 2(bx),#2
376 jne 1f
377 wait
378 filds 4(bx)
379 wait
380 fstpd 2(bx)
381 wait
382 ret
3831:
384 wait
385 fildl 4(bx)
386 wait
387 fstpd 2(bx)
388 wait
389 ret
390
391.cuf4:
392 mov bx,sp
393 cmp 2(bx),#2
394 jne 1f
395 mov ax,4(bx)
396 mov 2(bx),ax
397 mov 4(bx),#0
398 wait
399 fildl 2(bx)
400 wait
401 fstps 2(bx)
402 wait
403 ret
4041:
405 wait
406 fildl 4(bx)
407 wait
408 cmp 6(bx),#0
409 jge 1f
4102:
411 wait
412 fisubl bigmin
413 wait
414 fisubl bigmin
4151:
416 wait
417 fstps 4(bx)
418 wait
419 ret
420
421.cuf8:
422 mov bx,sp
423 cmp 2(bx),#2
424 jne 1f
425 mov 6(bx),#0
4261:
427 wait
428 fildl 4(bx)
429 wait
430 cmp 6(bx),#0
431 jge 1f
4322:
433 wait
434 fisubl bigmin
435 wait
436 fisubl bigmin
4371:
438 wait
439 fstpd 2(bx)
440 wait
441 ret
442
443.cfi:
444 mov bx,sp
445 push bx
446 wait
447 fstcw -2(bx)
448 wait
449 mov dx,-2(bx)
450 or -2(bx),#0xc00 ! truncating mode
451 wait
452 fldcw -2(bx)
453 pop ax
454 cmp 4(bx),#4
455 jne 2f
456 ! loc 4 loc ? cfi
457 wait
458 flds 6(bx)
459 wait
460 fistpl 6(bx)
461 wait
462 cmp 2(bx),#2
463 jne 1f
464 mov ax,6(bx)
4651:
466 mov 4(bx),dx
467 wait
468 fldcw 4(bx)
469 wait
470 ret
4712:
472 ! loc 8 loc ? cfi
473 wait
474 fldd 6(bx)
475 wait
476 fistpl 10(bx)
477 wait
478 cmp 2(bx),#2
479 jne 1b
480 mov ax,10(bx)
481 jmp 1b
482
483.cfu:
484 mov bx,sp
485 push bx
486 wait
487 fstcw -2(bx)
488 wait
489 mov dx,-2(bx)
490 and -2(bx),#0xf3ff
491 or -2(bx),#0x400 ! to -infinity
492 wait
493 fldcw -2(bx)
494 wait
495 pop ax
496 cmp 4(bx),#4
497 jne 2f
498 ! loc 4 loc ? cfu
499 flds 6(bx)
500 wait
501 fabs ! ???
502 wait
503 fiaddl bigmin
504 fistpl 6(bx)
505 wait
506 mov ax,8(bx)
507 sub ax,bigmin+2
508 mov 8(bx),ax
509 cmp 2(bx),#2
510 jne 1f
511 mov ax,6(bx)
5121:
513 mov 4(bx),dx
514 wait
515 fldcw 4(bx)
516 wait
517 ret
5182:
519 wait
520 ! loc 8 loc ? cfu
521 fldd 6(bx)
522 wait
523 fabs ! ???
524 wait
525 fiaddl bigmin
526 fistpl 10(bx)
527 wait
528 mov ax,12(bx)
529 sub ax,bigmin+2
530 mov 12(bx),ax
531 cmp 2(bx),#2
532 jne 1b
533 mov ax,10(bx)
534 jmp 1b
535
536.cff4:
537 mov bx,sp
538 wait
539 fldd 2(bx)
540 wait
541 fstcw 2(bx)
542 wait
543 mov dx,2(bx)
544 and 2(bx),#0xf3ff ! set to rounding mode
545 wait
546 fldcw 2(bx)
547 wait
548 fstps 6(bx)
549 mov 2(bx),dx
550 wait
551 fldcw 2(bx)
552 wait
553 ret
554
555.cff8:
556 mov bx,sp
557 wait
558 flds 2(bx)
559 wait
560 fstpd 2(bx)
561 wait
562 ret
563
564.cmf4:
565 mov bx,sp
566 push bx ! room for 8087 status word
567 xor cx,cx
568 wait
569 flds 6(bx)
570 wait
571 flds 2(bx)
572 wait
573 fcompp ! compare and pop operands
574 wait
575 fstsw -2(bx)
576 wait
577 mov ax,-2(bx)
578 sahf
579 je 1f
580 jb 2f
581 dec cx
582 jmp 1f
5832:
584 inc cx
5851:
586 mov ax,cx
587 pop bx
588 ret
589
590
591.cmf8:
592 mov bx,sp
593 push bx ! room for 8087 status word
594 xor cx,cx
595 wait
596 fldd 10(bx)
597 wait
598 fldd 2(bx)
599 wait
600 fcompp ! compare and pop operands
601 wait
602 fstsw -2(bx)
603 wait
604 mov ax,-2(bx)
605 sahf
606 je 1f
607 jb 2f
608 dec cx
609 jmp 1f
6102:
611 inc cx
6121:
613 mov ax,cx
614 pop bx
615 ret
Note: See TracBrowser for help on using the repository browser.