* tiny
[mascara-docs.git] / compilers / bcc / linux86-0.16.17 / libc / i386fp / fperror.x
blob04f3f74be8367a5cd3c199292292f00059eeb1e9
1 ! bcc 386 floating point routines (version 2)
2 ! --- fpdenormal, fperror, fpinfinity, fpNaN, fpoverflow, fpunderflow,fpdivzero
3 ! author: Bruce Evans
5 #include "fperr.h"
6 #include "fplib.h"
8         .extern _fperr
10 ! Cause a denormal-operand exception
11 ! Preserves all general registers if signal handler returns
13         .globl  fpdenormal
14         .align  ALIGNMENT
15 fpdenormal:
16 #if 0
17         push    eax
18         mov     eax,#EFDENORMAL
19         call    fperror
20         pop     eax
21 #endif
22         ret
24 ! Cause an exception with error code eax, preserving all genregs except eax
26         .globl  fperror
27         .align  ALIGNMENT
28 fperror:
29         push    ebp             ! set up usual frame ...
30         mov     ebp,esp         ! ... for debugging
31         push    edx             ! save default
32         push    ecx
33         push    eax             ! error code is arg to C routine
34         call    _fperr
35         add     esp,#GENREG_SIZE
36         pop     ecx             ! restore default
37         pop     edx
38         pop     ebp
39         ret
41         .align  ALIGNMENT
42 fphuge:
43         mov     ecx,#D_HUGE_LOW ! prepare number +-HUGEVAL
44         or      edx,#D_HUGE_HIGH        ! ... in case signal handler returns
45         jmp     fperror
47 ! Cause an infinite-operand exception
48 ! Return +-HUGEVAL in edx:ecx with sign from edx
50         .globl  fpinfinity
51         .align  ALIGNMENT
52 fpinfinity:
53         mov     eax,#EFINFINITY
54         jmp     fphuge          ! almost right
56 ! Cause an NaN-operand exception
57 ! Return +-HUGEVAL in edx:ecx with sign from edx
59         .globl  fpNaN
60         .align  ALIGNMENT
61 fpNaN:
62         mov     eax,#EFNAN      ! there are different types of NaNs but...
63         jmp     fphuge          ! WRONG
65 ! Cause an overflow exception
66 ! Return +-HUGEVAL in edx:ecx with sign from edx
68         .globl  fpoverflow
69         .align  ALIGNMENT
70 fpoverflow:
71         mov     eax,#EFOVERFLOW
72         jmp     fphuge          ! almost right
74 ! Cause an underflow exception (actually assume it is masked for now)
75 ! Return denormal or 0.0 in edx:ecx
76 ! XXX - this should cause a denormal exception or none for the denormal case
77 ! Args: sign in edx, fraction in esi:eax, right shift in edi
78 ! Returns: denormalized number in edx:eax
80         .globl  fpunderflow
81         .align  ALIGNMENT
82 fpunderflow:
83 #if 0
84         mov     eax,#EFUNDERFLOW
85         jmp     fperror
86 #endif
87         cmp     edi,#REG_BIT
88         jb      denormalize1
89         mov     eax,esi
90         sub     esi,esi
91         sub     edi,#REG_BIT
92         cmp     edi,#REG_BIT
93         jb      denormalize1
94 denormalize_underflow:
95 #if 0
96         mov     eax,#EFUNDERFLOW
97         jmp     fperror
98 #endif
99         sub     eax,eax
100         mov     edx,eax
101         ret
103         .align  ALIGNMENT
104 denormalize1:
105         mov     ecx,edi
106         shrd    eax,esi,cl
107         shr     esi,cl
108         mov     ecx,esi
109         or      ecx,eax
110         jz      denormalize_underflow
111         and     edx,#D_SIGN_MASK
112         or      edx,esi
113         ret
115 ! Cause an fp division by zero exception
116 ! Return +-HUGEVAL in edx:ecx with sign from edx
118         .globl  fpdivzero
119         .align  ALIGNMENT
120 fpdivzero:
121         mov     eax,#EFDIVZERO
122         test    edx,#D_EXP_MASK
123         jnz     fphuge          ! almost right
124         sub     ecx,ecx
125         mov     edx,ecx
126         jmp     fperror