1 %************************************************************************
3 \section[GhcConstants]{Constants known by C code {\em and} by the compiler (hsc)}
5 %************************************************************************
7 Multi-slurp protection (start):
10 #define GHCCONSTANTS_H
13 /* OLD: #include "platform.h" */
17 % BECAUSE THIS FILE IS INCLUDED INTO HASKELL FILES, THERE MUST BE NO C
18 % COMMENTS IN THE ``CODE'' BITS.
20 This file defines constants that are common to diverse parts of the
21 Glasgow Haskell compilation system. For example, both the compiler
22 proper and some magic runtime-system bits need to know the minimum
23 size of an updatable closure.
25 %************************************************************************
27 \subsection[updatable-closure-size]{Size of Updatable Closures}
29 %************************************************************************
31 We define the minimum size for updatable closures. This must be at
32 least 2, to allow for cons cells and linked indirections. All updates
33 will be performed on closures of this size. For non-updatable closures
34 the minimum size is 1 to allow for a forwarding pointer.
37 #define MIN_UPD_SIZE 2
38 #define MIN_NONUPD_SIZE 1
41 ToDo: @MIN_STATIC_NONUPD_SIZE@ ???
43 %************************************************************************
45 \subsection[double-etc-size]{Sizes of various types}
47 %************************************************************************
49 The size of an StgDouble, in StgWords.
59 The size of an Stg{Int,Word}64, in StgWords.
71 Sizes of gmp objects, in StgWords
74 #define MP_STRUCT_SIZE 3
75 #define MIN_MP_INT_SIZE 16
78 %************************************************************************
80 \subsection[spec-closure-constraints]{What can be declared as a @SPEC@ closure}
82 %************************************************************************
84 The following define what closure layouts can be declared as @SPEC@
88 #define MAX_SPEC_ALL_PTRS 12
89 #define MAX_SPEC_ALL_NONPTRS 5
90 #define MAX_SPEC_OTHER_SIZE 3
93 The highest-numbered selectee field that we can do magic on (i.e.,
94 do the selection at GC time):
96 #define MAX_SPEC_SELECTEE_SIZE 12
99 %************************************************************************
101 \subsection[stg-reg-counts]{How many STG registers are there}
103 %************************************************************************
106 #define MAX_VANILLA_REG 8
107 #define MAX_FLOAT_REG 4
108 #define MAX_DOUBLE_REG 2
109 #define MAX_LONG_REG 2
112 %************************************************************************
114 \subsection[vectored-return]{What number of data type cases can use vectored returns}
116 %************************************************************************
118 @MAX_VECTORED_RTN@ defines the largest number of constructors that a
119 data type can have and still use a vectored return.
121 #define MAX_VECTORED_RTN 8
124 %************************************************************************
126 \subsection[intlike-range]{Range of int-like closures}
128 %************************************************************************
130 Range of built-in table of static small int-like closures.
133 #define MAX_INTLIKE (16)
134 #define MIN_INTLIKE (-16)
137 %************************************************************************
139 \subsection[update-frame-size]{Update frame size}
141 %************************************************************************
143 The update frames are described in \tr{SMupdate.lh}. All the compiler
144 needs to ``know'' is the size of the different frames.
146 First we define update frame sizes for the compiler. These may vary at
147 runtime depending what type of code is being generated so we also
148 define the parts which can be put together.
150 ****************************************************************
151 *** NB: These update-frame sizes INCLUDE the return address. ***
152 ****************************************************************
155 The update frame sizes when cost centres are not being used are:
157 #define NOSCC_STD_UF_SIZE 4
158 #define NOSCC_CON_UF_SIZE 2
161 If cost-centres are being used we have to add to the above sizes:
163 #define SCC_STD_UF_SIZE 5
164 #define SCC_CON_UF_SIZE 3
167 If we are compiling C code the use of cost centres is determined at
168 compile time so we use conditional macro definitions.
170 #if defined(PROFILING)
171 #define STD_UF_SIZE SCC_STD_UF_SIZE
172 #define CON_UF_SIZE SCC_CON_UF_SIZE
174 #define STD_UF_SIZE NOSCC_STD_UF_SIZE
175 #define CON_UF_SIZE NOSCC_CON_UF_SIZE
179 Sorry. but we can't comment these if's and else's !
181 Offsets relative to a pointer to the top word (return address) of frame...
183 Notes: (1)~GC looks at the @UF_RET@ word to determine frame type. (2)
184 GC requires that @UF_SUB@ be the same offset in all frames, no matter
192 #define UF_COST_CENTRE 4
195 %************************************************************************
197 \subsection[semi-tagging-constants]{Constants for semi-tagging}
199 %************************************************************************
201 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
202 normal-form values of algebraic data types will have tags 0, 1, ...
204 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
205 how often we bang into indirection nodes; that's all. (WDP 95/11)
208 #define INFO_OTHER_TAG (-1)
209 #define INFO_IND_TAG (-2)
210 #define INFO_FIRST_TAG 0
213 %************************************************************************
215 \subsection[liveness-masks]{Liveness masks for calling GC}
217 %************************************************************************
219 We often have to tell the RTS (usually: garbage-collector) what STG
220 registers have ``followable'' pointers in them. We used to just say
221 {\em how many} there were; but this doesn't work in a semi-tagged
222 world---part of the point of semi-tagging is to avoid loading up
223 registers needlessly; but if you don't load a register and then you
224 tell the GC that it has followable contents....
226 So we use a {\em liveness mask} (one word) instead. This is probably
227 neater anyway. The layout is:
229 --------------------------
230 ... | Rn | ... | R2 | R1 |
231 --------------------------
234 The \tr{LIVENESS_<reg>} macros are used both in Haskell and C. The
235 \tr{IS_LIVE_<reg>} macros (``is this register live according to this
236 mask?'') are used only in C [obviously].
238 #define NO_LIVENESS 0
239 #define LIVENESS_R1 1
240 #define LIVENESS_R2 2
241 #define LIVENESS_R3 4
242 #define LIVENESS_R4 8
243 #define LIVENESS_R5 16
244 #define LIVENESS_R6 32
245 #define LIVENESS_R7 64
246 #define LIVENESS_R8 128
248 #define IS_LIVE_R1(mask) (((mask) & LIVENESS_R1) != 0)
249 #define IS_LIVE_R2(mask) (((mask) & LIVENESS_R2) != 0)
250 #define IS_LIVE_R3(mask) (((mask) & LIVENESS_R3) != 0)
251 #define IS_LIVE_R4(mask) (((mask) & LIVENESS_R4) != 0)
252 #define IS_LIVE_R5(mask) (((mask) & LIVENESS_R5) != 0)
253 #define IS_LIVE_R6(mask) (((mask) & LIVENESS_R6) != 0)
254 #define IS_LIVE_R7(mask) (((mask) & LIVENESS_R7) != 0)
255 #define IS_LIVE_R8(mask) (((mask) & LIVENESS_R8) != 0)
258 Some extra stuff will probably be needed for ``shift bits off the end
259 and stop when zero,'' which would be quicker. Later.
261 Multi-slurp protection (end-of-file):