[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / includes / GhcConstants.lh
1 %************************************************************************
2 %*                                                                      *
3 \section[GhcConstants]{Constants known by C code {\em and} by the compiler (hsc)}
4 %*                                                                      *
5 %************************************************************************
6
7 Multi-slurp protection (start):
8 \begin{code}
9 #ifndef GHCCONSTANTS_H
10 #define GHCCONSTANTS_H
11
12 #ifndef PLATFORM_H
13 #include "platform.h"
14 #endif
15 \end{code}
16
17 % BECAUSE THIS FILE IS INCLUDED INTO HASKELL FILES, THERE MUST BE NO C
18 % COMMENTS IN THE ``CODE'' BITS.
19
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.
24
25 %************************************************************************
26 %*                                                                      *
27 \subsection[updatable-closure-size]{Size of Updatable Closures}
28 %*                                                                      *
29 %************************************************************************
30
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.
35
36 \begin{code}
37 #define MIN_UPD_SIZE    2
38 #define MIN_NONUPD_SIZE 1
39 \end{code}
40
41 ToDo: @MIN_STATIC_NONUPD_SIZE@ ???
42
43 %************************************************************************
44 %*                                                                      *
45 \subsection[double-etc-size]{Sizes of various types}
46 %*                                                                      *
47 %************************************************************************
48
49 The size of an StgDouble, in StgWords.
50
51 \begin{code}
52 #if alpha_TARGET_ARCH
53 #define DOUBLE_SIZE     1
54 #else
55 #define DOUBLE_SIZE     2
56 #endif
57 \end{code}
58
59 Sizes of gmp objects, in StgWords
60
61 \begin{code}
62 #define MP_STRUCT_SIZE  3
63 #define MIN_MP_INT_SIZE 16
64 \end{code}
65
66 %************************************************************************
67 %*                                                                      *
68 \subsection[spec-closure-constraints]{What can be declared as a @SPEC@ closure}
69 %*                                                                      *
70 %************************************************************************
71
72 The following define what closure layouts can be declared as @SPEC@
73 closures.
74
75 \begin{code}
76 #define MAX_SPEC_ALL_PTRS 12
77 #define MAX_SPEC_ALL_NONPTRS 5
78 #define MAX_SPEC_OTHER_SIZE 3
79 \end{code}
80
81 The highest-numbered selectee field that we can do magic on (i.e.,
82 do the selection at GC time):
83 \begin{code}
84 #define MAX_SPEC_SELECTEE_SIZE 12
85 \end{code}
86
87 %************************************************************************
88 %*                                                                      *
89 \subsection[stg-reg-counts]{How many STG registers are there}
90 %*                                                                      *
91 %************************************************************************
92
93 \begin{code}
94 #define MAX_VANILLA_REG 8
95 #define MAX_FLOAT_REG 4
96 #define MAX_DOUBLE_REG 2
97 \end{code}
98
99 %************************************************************************
100 %*                                                                      *
101 \subsection[vectored-return]{What number of data type cases can use vectored returns}
102 %*                                                                      *
103 %************************************************************************
104
105 @MAX_VECTORED_RTN@ defines the largest number of constructors that a
106 data type can have and still use a vectored return.
107 \begin{code}
108 #define MAX_VECTORED_RTN 8
109 \end{code}
110
111 %************************************************************************
112 %*                                                                      *
113 \subsection[intlike-range]{Range of int-like closures}
114 %*                                                                      *
115 %************************************************************************
116
117 Range of built-in table of static small int-like closures.
118
119 \begin{code}
120 #define MAX_INTLIKE             (16)
121 #define MIN_INTLIKE             (-16)
122 \end{code}
123
124 %************************************************************************
125 %*                                                                      *
126 \subsection[update-frame-size]{Update frame size}
127 %*                                                                      *
128 %************************************************************************
129
130 The update frames are described in \tr{SMupdate.lh}. All the compiler
131 needs to ``know'' is the size of the different frames.
132
133 First we define update frame sizes for the compiler. These may vary at
134 runtime depending what type of code is being generated so we also
135 define the parts which can be put together.
136
137 ****************************************************************
138 *** NB: These update-frame sizes INCLUDE the return address. ***
139 ****************************************************************
140
141
142 The update frame sizes when cost centres are not being used are:
143 \begin{code}
144 #define NOSCC_STD_UF_SIZE       4
145 #define NOSCC_CON_UF_SIZE       2
146 \end{code}
147
148 If cost-centres are being used we have to add to the above sizes:
149 \begin{code}
150 #define SCC_STD_UF_SIZE         5
151 #define SCC_CON_UF_SIZE         3
152 \end{code}
153
154 If we are compiling C code the use of cost centres is determined at
155 compile time so we use conditional macro definitions.
156 \begin{code}
157 #if defined(PROFILING)
158 #define STD_UF_SIZE     SCC_STD_UF_SIZE
159 #define CON_UF_SIZE     SCC_CON_UF_SIZE
160 #else
161 #define STD_UF_SIZE     NOSCC_STD_UF_SIZE
162 #define CON_UF_SIZE     NOSCC_CON_UF_SIZE
163 #endif
164 \end{code}
165
166 Sorry. but we can't comment these if's and else's !
167
168 Offsets relative to a pointer to the top word (return address) of frame...
169
170 Notes: (1)~GC looks at the @UF_RET@ word to determine frame type.  (2)
171 GC requires that @UF_SUB@ be the same offset in all frames, no matter
172 what.
173
174 \begin{code}
175 #define UF_RET          0
176 #define UF_SUB          1
177 #define UF_SUA          2
178 #define UF_UPDATEE      3
179 #define UF_COST_CENTRE  4
180 \end{code}
181
182 %************************************************************************
183 %*                                                                      *
184 \subsection[semi-tagging-constants]{Constants for semi-tagging}
185 %*                                                                      *
186 %************************************************************************
187
188 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
189 normal-form values of algebraic data types will have tags 0, 1, ...
190
191 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
192 how often we bang into indirection nodes; that's all.  (WDP 95/11)
193
194 \begin{code}
195 #define INFO_OTHER_TAG          (-1)
196 #define INFO_IND_TAG            (-2)
197 #define INFO_FIRST_TAG          0
198 \end{code}
199
200 %************************************************************************
201 %*                                                                      *
202 \subsection[liveness-masks]{Liveness masks for calling GC}
203 %*                                                                      *
204 %************************************************************************
205
206 We often have to tell the RTS (usually: garbage-collector) what STG
207 registers have ``followable'' pointers in them.  We used to just say
208 {\em how many} there were; but this doesn't work in a semi-tagged
209 world---part of the point of semi-tagging is to avoid loading up
210 registers needlessly; but if you don't load a register and then you
211 tell the GC that it has followable contents....
212
213 So we use a {\em liveness mask} (one word) instead.  This is probably
214 neater anyway.  The layout is:
215 \begin{verbatim}
216 --------------------------
217 ... | Rn | ... | R2 | R1 |
218 --------------------------
219 \end{verbatim}
220
221 The \tr{LIVENESS_<reg>} macros are used both in Haskell and C.  The
222 \tr{IS_LIVE_<reg>} macros (``is this register live according to this
223 mask?'') are used only in C [obviously].
224 \begin{code}
225 #define NO_LIVENESS             0
226 #define LIVENESS_R1             1
227 #define LIVENESS_R2             2
228 #define LIVENESS_R3             4
229 #define LIVENESS_R4             8
230 #define LIVENESS_R5             16
231 #define LIVENESS_R6             32
232 #define LIVENESS_R7             64
233 #define LIVENESS_R8             128
234
235 #define IS_LIVE_R1(mask)        (((mask) & LIVENESS_R1) != 0)
236 #define IS_LIVE_R2(mask)        (((mask) & LIVENESS_R2) != 0)
237 #define IS_LIVE_R3(mask)        (((mask) & LIVENESS_R3) != 0)
238 #define IS_LIVE_R4(mask)        (((mask) & LIVENESS_R4) != 0)
239 #define IS_LIVE_R5(mask)        (((mask) & LIVENESS_R5) != 0)
240 #define IS_LIVE_R6(mask)        (((mask) & LIVENESS_R6) != 0)
241 #define IS_LIVE_R7(mask)        (((mask) & LIVENESS_R7) != 0)
242 #define IS_LIVE_R8(mask)        (((mask) & LIVENESS_R8) != 0)
243 \end{code}
244
245 Some extra stuff will probably be needed for ``shift bits off the end
246 and stop when zero,'' which would be quicker.  Later.
247
248 Multi-slurp protection (end-of-file):
249 \begin{code}
250 #endif
251 \end{code}