Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpbas_fpu.c
blobe2682514656fcad8ae4f6877f9f89b7e577cb3a2
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/libcall.h>
7 #include <exec/types.h>
8 #include <proto/mathieeedoubbas.h>
9 #include <math.h>
10 #include <stdlib.h>
11 #include "mathieeedoubbas_intern.h"
13 #undef double
16 Problem (ONLY on Linux/M68K with binary compatibility turned on):
17 In order to get binary compatibility with the original Amiga OS
18 we have to return the value in D0/D1. This is NOT automatically
19 done by the compiler. The result would be returned in one of the
20 FPU registers instead. So we're using the trick with the QUADs.
21 See below.
25 !!! Fixme !!!
26 Problem on i386 etc:
27 The functions in the *.arch file (integer-emulation of double
28 operations) return QUADs. The protos however say that these functions
29 are returning doubles. Unfortunately doubles are not returned like
30 QUADs!
32 //#define UseRegisterArgs 1
33 #if UseRegisterArgs
34 #define RETURN_TYPE QUAD /* For Linux/M68k & AmigaOS w/ bin. compat. */
35 #else
36 #define RETURN_TYPE double /* for the rest */
37 #endif
39 AROS_LHQUAD1(LONG, FPU_IEEEDPFix,
40 AROS_LHAQUAD(double, y, D0, D1),
41 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 5, MathIeeeDoubBas
44 AROS_LIBFUNC_INIT
45 return (LONG)y;
46 AROS_LIBFUNC_EXIT
47 } /* FPU_IEEEDPFix */
49 AROS_LHQUAD1(RETURN_TYPE, FPU_IEEEDPFlt,
50 AROS_LHAQUAD(LONG, y, D0, D1),
51 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 6, MathIeeeDoubBas
54 AROS_LIBFUNC_INIT
55 #if UseRegisterArgs
56 double d;
57 QUAD * Res = (QUAD *)&d; /* this forces the returned value to be in D0/D1 */
58 d = (double)y;
59 return * Res;
60 #else
61 return (double)y;
62 #endif
63 AROS_LIBFUNC_EXIT
64 } /* FPU_IEEEDPFlt */
66 AROS_LHQUAD2(LONG, FPU_IEEEDPCmp,
67 AROS_LHAQUAD(double, y, D0, D1),
68 AROS_LHAQUAD(double, z, D2, D3),
69 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 7, MathIeeeDoubBas
72 AROS_LIBFUNC_INIT
74 if (y == z) return 0;
75 if (y > z) return 1;
76 return -1;
78 AROS_LIBFUNC_EXIT
79 } /* FPU_IEEEDPCmp */
81 AROS_LHQUAD1(LONG, FPU_IEEEDPTst,
82 AROS_LHAQUAD(double, y, D0, D1),
83 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 8, MathIeeeDoubBas
86 AROS_LIBFUNC_INIT
88 if (0.0 == y) return 0;
89 if (y > 0) return 1;
90 return -1;
92 AROS_LIBFUNC_EXIT
93 } /* FPU_IEEEDPTst */
95 AROS_LHQUAD1(RETURN_TYPE, FPU_IEEEDPAbs,
96 AROS_LHAQUAD(double, y, D0, D1),
97 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 9, MathIeeeDoubBas
100 AROS_LIBFUNC_INIT
102 #if UseRegisterArgs
103 QUAD * Res = (QUAD *)&y; /* this forces the returned value to be in D0/D1 */
104 y=abs(y);
105 return * Res;
106 #else
107 return abs(y);
108 #endif
110 AROS_LIBFUNC_EXIT
111 } /* FPU_IEEEDPAbs */
113 AROS_LHQUAD1(RETURN_TYPE, FPU_IEEEDPNeg,
114 AROS_LHAQUAD(double, y, D0, D1),
115 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 10, MathIeeeDoubBas)
117 AROS_LIBFUNC_INIT
118 #if UseRegisterArgs
119 QUAD * Res = (QUAD *)&y; /* this forces the returned value to be in D0/D1 */
120 y = -y;
121 return * Res;
122 #else
123 return -y;
124 #endif
125 AROS_LIBFUNC_EXIT
126 } /* FPU_IEEEDPNeg */
128 AROS_LHQUAD2(RETURN_TYPE, FPU_IEEEDPAdd,
129 AROS_LHAQUAD(double, y, D0, D1),
130 AROS_LHAQUAD(double, z, D2, D3),
131 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 11, MathIeeeDoubBas
134 AROS_LIBFUNC_INIT
135 #if UseRegisterArgs
136 QUAD * Res = (QUAD *)&y; /* this forces the returned value to be in D0/D1 */
137 y=y+z;
138 return * Res;
139 #else
140 return (y+z);
141 #endif
142 AROS_LIBFUNC_EXIT
143 } /* FPU_IEEEDPAdd */
145 AROS_LHQUAD2(RETURN_TYPE, FPU_IEEEDPSub,
146 AROS_LHAQUAD(double, y, D0, D1),
147 AROS_LHAQUAD(double, z, D2, D3),
148 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 12, MathIeeeDoubBas)
150 AROS_LIBFUNC_INIT
151 #if UseRegisterArgs
152 QUAD * Res = (QUAD *)&y; /* this forces the returned value to be in D0/D1 */
153 y=y-z;
154 return * Res;
155 #else
156 return (y-z);
157 #endif
158 AROS_LIBFUNC_EXIT
159 } /* FPU_IEEEDPSub */
161 AROS_LHQUAD2(RETURN_TYPE, FPU_IEEEDPMul,
162 AROS_LHAQUAD(double, y, D0, D1),
163 AROS_LHAQUAD(double, z, D2, D3),
164 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 13, MathIeeeDoubBas
167 AROS_LIBFUNC_INIT
168 #if UseRegisterArgs
169 QUAD * Res = (QUAD *)&y; /* this forces the returned value to be in D0/D1 */
170 y=y*z;
171 return * Res;
172 #else
173 return y*z;
174 #endif
175 AROS_LIBFUNC_EXIT
176 } /* FPU_IEEEDPMul */
178 AROS_LHQUAD2(RETURN_TYPE, FPU_IEEEDPDiv,
179 AROS_LHAQUAD(double, y, D0, D1),
180 AROS_LHAQUAD(double, z, D2, D3),
181 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 14, MathIeeeDoubBas
184 AROS_LIBFUNC_INIT
185 #if UseRegisterArgs
186 QUAD * Res = (QUAD *)&y; /* this forces the returned value to be in D0/D1 */
187 y = y/z;
188 return * Res;
189 #else
190 return (y/z);
191 #endif
192 AROS_LIBFUNC_EXIT
193 } /* FPU_IEEEDPDiv */
195 AROS_LHQUAD1(RETURN_TYPE, FPU_IEEEDPFloor,
196 AROS_LHAQUAD(double, y, D0, D1),
197 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 15, MathIeeeDoubBas
200 AROS_LIBFUNC_INIT
201 /* return floor(y); */
202 return 0xbadc0deULL;
203 AROS_LIBFUNC_EXIT
204 } /* FPU_IEEEDPFloor */
206 AROS_LHQUAD1(RETURN_TYPE, FPU_IEEEDPCeil,
207 AROS_LHAQUAD(double, y, D0, D1),
208 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 16, MathIeeeDoubBas
211 AROS_LIBFUNC_INIT
212 /* return ceil(y); */
213 return 0xbadc0deULL;
214 AROS_LIBFUNC_EXIT
215 } /* FPU_IEEEDPCeil */