Remove the implementation of gmp primops from the rts
[ghc.git] / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2004
4 *
5 * Top-level include file for the RTS itself
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #ifndef RTS_H
10 #define RTS_H
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #ifndef IN_STG_CODE
17 #define IN_STG_CODE 0
18 #endif
19 #include "Stg.h"
20
21 // ToDo: move RtsExternal stuff elsewhere
22 #include "RtsExternal.h"
23
24 // Turn off inlining when debugging - it obfuscates things
25 #ifdef DEBUG
26 # undef STATIC_INLINE
27 # define STATIC_INLINE static
28 #endif
29
30 #include "RtsTypes.h"
31
32 #if __GNUC__ >= 3
33 /* Assume that a flexible array member at the end of a struct
34 * can be defined thus: T arr[]; */
35 #define FLEXIBLE_ARRAY
36 #else
37 /* Assume that it must be defined thus: T arr[0]; */
38 #define FLEXIBLE_ARRAY 0
39 #endif
40
41 #if __GNUC__ >= 3
42 #define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
43 #else
44 #define ATTRIBUTE_ALIGNED(n) /*nothing*/
45 #endif
46
47 /* Fix for mingw stat problem (done here so it's early enough) */
48 #ifdef mingw32_HOST_OS
49 #define __MSVCRT__ 1
50 #endif
51
52 /* Needed to get the macro version of errno on some OSs, and also to
53 get prototypes for the _r versions of C library functions. */
54 #define _REENTRANT 1
55
56 /*
57 * We often want to know the size of something in units of an
58 * StgWord... (rounded up, of course!)
59 */
60 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + sizeof(W_) - 1) / sizeof(W_))
61
62 #define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
63
64 /*
65 * It's nice to be able to grep for casts
66 */
67 #define stgCast(ty,e) ((ty)(e))
68
69 /* -----------------------------------------------------------------------------
70 Assertions and Debuggery
71 -------------------------------------------------------------------------- */
72
73 #ifndef DEBUG
74 #define ASSERT(predicate) /* nothing */
75 #else
76
77 extern void _assertFail (const char *, unsigned int);
78
79 #define ASSERT(predicate) \
80 if (predicate) \
81 /*null*/; \
82 else \
83 _assertFail(__FILE__, __LINE__)
84 #endif /* DEBUG */
85
86 /*
87 * Use this on the RHS of macros which expand to nothing
88 * to make sure that the macro can be used in a context which
89 * demands a non-empty statement.
90 */
91
92 #define doNothing() do { } while (0)
93
94 #ifdef DEBUG
95 #define USED_IF_DEBUG
96 #define USED_IF_NOT_DEBUG STG_UNUSED
97 #else
98 #define USED_IF_DEBUG STG_UNUSED
99 #define USED_IF_NOT_DEBUG
100 #endif
101
102 #ifdef THREADED_RTS
103 #define USED_IF_THREADS
104 #define USED_IF_NOT_THREADS STG_UNUSED
105 #else
106 #define USED_IF_THREADS STG_UNUSED
107 #define USED_IF_NOT_THREADS
108 #endif
109
110 /*
111 * Getting printf formats right for platform-dependent typedefs
112 */
113 #if SIZEOF_LONG == 8
114 #define FMT_Word64 "lu"
115 #define FMT_Int64 "ld"
116 #else
117 #define FMT_Word64 "llu"
118 #define FMT_Int64 "lld"
119 #endif
120
121 /*
122 * Macros for untagging and retagging closure pointers
123 * For more information look at the comments in Cmm.h
124 */
125
126 static inline StgWord
127 GET_CLOSURE_TAG(StgClosure * p)
128 {
129 return (StgWord)p & TAG_MASK;
130 }
131
132 static inline StgClosure *
133 UNTAG_CLOSURE(StgClosure * p)
134 {
135 return (StgClosure*)((StgWord)p & ~TAG_MASK);
136 }
137
138 static inline StgClosure *
139 TAG_CLOSURE(StgWord tag,StgClosure * p)
140 {
141 return (StgClosure*)((StgWord)p | tag);
142 }
143
144 /* -----------------------------------------------------------------------------
145 Include everything STG-ish
146 -------------------------------------------------------------------------- */
147
148 /* System headers: stdlib.h is eeded so that we can use NULL. It must
149 * come after MachRegs.h, because stdlib.h might define some inline
150 * functions which may only be defined after register variables have
151 * been declared.
152 */
153 #include <stdlib.h>
154
155 /* Global constaints */
156 #include "Constants.h"
157
158 /* Profiling information */
159 #include "StgProf.h"
160 #include "StgLdvProf.h"
161
162 /* Storage format definitions */
163 #include "StgFun.h"
164 #include "Closures.h"
165 #include "Liveness.h"
166 #include "ClosureTypes.h"
167 #include "InfoTables.h"
168 #include "TSO.h"
169
170 /* Info tables, closures & code fragments defined in the RTS */
171 #include "StgMiscClosures.h"
172
173 /* Parallel information */
174 #include "OSThreads.h"
175 #include "SMPClosureOps.h"
176 #include "SpinLock.h"
177
178 /* GNU mp library */
179 #if defined(HAVE_FRAMEWORK_GMP)
180 #include <GMP/gmp.h>
181 #else
182 #include "gmp.h"
183 #endif
184
185 /* Macros for STG/C code */
186 #include "Block.h"
187 #include "ClosureMacros.h"
188
189 /* Runtime-system hooks */
190 #include "Hooks.h"
191 #include "RtsMessages.h"
192
193 /* for StablePtr/getStablePtr/deRefStablePtr */
194 #include "Storage.h"
195 #include "Stable.h"
196
197 #include "ieee-flpt.h"
198
199 #include "Signals.h"
200
201 /* Misc stuff without a home */
202 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
203 DLL_IMPORT_RTS extern int prog_argc;
204 DLL_IMPORT_RTS extern char *prog_name;
205
206 extern void stackOverflow(void);
207
208 extern void __decodeDouble_2Int (I_ *man_sign, W_ *man_high, W_ *man_low, I_ *exp, StgDouble dbl);
209 extern void __decodeFloat_Int (I_ *man, I_ *exp, StgFloat flt);
210
211 #if defined(WANT_DOTNET_SUPPORT)
212 #include "DNInvoke.h"
213 #endif
214
215 /* Initialising the whole adjustor thunk machinery. */
216 extern void initAdjustor(void);
217
218 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
219
220 /* -----------------------------------------------------------------------------
221 RTS Exit codes
222 -------------------------------------------------------------------------- */
223
224 /* 255 is allegedly used by dynamic linkers to report linking failure */
225 #define EXIT_INTERNAL_ERROR 254
226 #define EXIT_DEADLOCK 253
227 #define EXIT_INTERRUPTED 252
228 #define EXIT_HEAPOVERFLOW 251
229 #define EXIT_KILLED 250
230
231 /* -----------------------------------------------------------------------------
232 Miscellaneous garbage
233 -------------------------------------------------------------------------- */
234
235 /* declarations for runtime flags/values */
236 #define MAX_RTS_ARGS 32
237
238 #ifdef DEBUG
239 #define TICK_VAR(arity) \
240 extern StgInt SLOW_CALLS_##arity; \
241 extern StgInt RIGHT_ARITY_##arity; \
242 extern StgInt TAGGED_PTR_##arity;
243
244 #define TICK_VAR_INI(arity) \
245 StgInt SLOW_CALLS_##arity = 1; \
246 StgInt RIGHT_ARITY_##arity = 1; \
247 StgInt TAGGED_PTR_##arity = 0;
248
249 extern StgInt TOTAL_CALLS;
250
251 TICK_VAR(1)
252 TICK_VAR(2)
253 #endif
254
255 /* -----------------------------------------------------------------------------
256 Assertions and Debuggery
257 -------------------------------------------------------------------------- */
258
259 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
260
261 /* -----------------------------------------------------------------------------
262 Assertions and Debuggery
263 -------------------------------------------------------------------------- */
264
265 #ifdef DEBUG
266 #if IN_STG_CODE
267 #define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
268 #else
269 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
270 #endif
271 #else
272 #define IF_DEBUG(c,s) doNothing()
273 #endif
274
275 #ifdef DEBUG
276 #define DEBUG_ONLY(s) s
277 #else
278 #define DEBUG_ONLY(s) doNothing()
279 #endif
280
281 /* -----------------------------------------------------------------------------
282 Useful macros and inline functions
283 -------------------------------------------------------------------------- */
284
285 #if defined(__GNUC__)
286 #define SUPPORTS_TYPEOF
287 #endif
288
289 #if defined(SUPPORTS_TYPEOF)
290 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
291 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
292 #else
293 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
294 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
295 #endif
296
297 /* -------------------------------------------------------------------------- */
298
299 #ifdef __cplusplus
300 }
301 #endif
302
303
304 /* krc: I put this here because I don't think
305 it needs to be visible externally.
306 It used to be in StgTicky.h, but I got rid
307 of that. */
308
309 /* -----------------------------------------------------------------------------
310 The StgEntCounter type - needed regardless of TICKY_TICKY
311 -------------------------------------------------------------------------- */
312
313 typedef struct _StgEntCounter {
314 /* Using StgWord for everything, becuase both the C and asm code
315 generators make trouble if you try to pack things tighter */
316 StgWord registeredp; /* 0 == no, 1 == yes */
317 StgInt arity; /* arity (static info) */
318 StgInt stk_args; /* # of args off stack */
319 /* (rest of args are in registers) */
320 char *str; /* name of the thing */
321 char *arg_kinds; /* info about the args types */
322 StgInt entry_count; /* Trips to fast entry code */
323 StgInt allocs; /* number of allocations by this fun */
324 struct _StgEntCounter *link;/* link to chain them all together */
325 } StgEntCounter;
326
327
328 #endif /* RTS_H */