419ad7df82eebcdb3ad578f64b514d06f630f637
[ghc-hetmet.git] / ghc / includes / StgMacros.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgMacros.h,v 1.11 1999/05/13 17:31:07 simonm Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Macros used for writing STG-ish C code.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef STGMACROS_H
11 #define STGMACROS_H
12
13 /* -----------------------------------------------------------------------------
14   The following macros create function headers.
15
16   Each basic block is represented by a C function with no arguments.
17   We therefore always begin with either
18
19   extern F_ f(void)
20
21   or
22   
23   static F_ f(void)
24
25   The macros can be used either to define the function itself, or to provide
26   prototypes (by following with a ';').
27
28   Note: the various I*_ shorthands in the second block below are used to
29   declare forward references to local symbols. These shorthands *have* to
30   use the 'extern' type specifier and not 'static'. The reason for this is
31   that 'static' declares a reference as being a static/local variable,
32   and *not* as a forward reference to a static variable.
33
34   This might seem obvious, but it had me stumped as to why my info tables
35   were suddenly all filled with 0s.
36
37     -- sof 1/99 
38
39   --------------------------------------------------------------------------- */
40
41 #define STGFUN(f)       StgFunPtr f(void)
42 #define EXTFUN(f)       extern StgFunPtr f(void)
43 #define EXTFUN_RTS(f)   extern DLL_IMPORT_RTS StgFunPtr f(void)
44 #define FN_(f)          F_ f(void)
45 #define IFN_(f)         static F_ f(void)
46 #define IF_(f)          static F_ f(void)
47 #define EF_(f)          extern F_ f(void)
48 #define EDF_(f)         extern DLLIMPORT F_ f(void)
49
50 #define ED_             extern
51 #define EDD_            extern DLLIMPORT 
52 #define ED_RO_          extern const
53 #define ID_             extern
54 #define ID_RO_          extern const
55 #define EI_             extern INFO_TBL_CONST StgInfoTable
56 #define EDI_            extern DLLIMPORT INFO_TBL_CONST StgInfoTable
57 #define II_             extern INFO_TBL_CONST StgInfoTable
58 #define EC_             extern StgClosure
59 #define EDC_            extern DLLIMPORT StgClosure
60 #define IC_             extern StgClosure
61 #define ECP_(x)         extern const StgClosure *(x)[]
62 #define EDCP_(x)        extern DLLIMPORT StgClosure *(x)[]
63 #define ICP_(x)         extern const StgClosure *(x)[]
64
65 /* -----------------------------------------------------------------------------
66    Stack Tagging.
67
68    For a  block of non-pointer words on the stack, we precede the
69    block with a small-integer tag giving the number of non-pointer
70    words in the block.
71    -------------------------------------------------------------------------- */
72
73 #ifndef DEBUG_EXTRA
74 #define ARGTAG_MAX 16           /* probably arbitrary */
75 #define ARG_TAG(n)  (n)
76 #define ARG_SIZE(n) stgCast(StgWord,n)
77
78 typedef enum {
79     REALWORLD_TAG = 0,
80     INT_TAG    = sizeofW(StgInt), 
81     INT64_TAG  = sizeofW(StgInt64), 
82     WORD_TAG   = sizeofW(StgWord), 
83     ADDR_TAG   = sizeofW(StgAddr), 
84     CHAR_TAG   = sizeofW(StgChar),
85     FLOAT_TAG  = sizeofW(StgFloat), 
86     DOUBLE_TAG = sizeofW(StgDouble), 
87     STABLE_TAG = sizeofW(StgWord), 
88 } StackTag;
89
90 #else /* DEBUG_EXTRA */
91
92 typedef enum {
93     ILLEGAL_TAG,
94     REALWORLD_TAG,
95     INT_TAG    ,
96     INT64_TAG  ,
97     WORD_TAG   ,
98     ADDR_TAG   ,
99     CHAR_TAG   ,
100     FLOAT_TAG  ,
101     DOUBLE_TAG ,
102     STABLE_TAG ,
103     ARGTAG_MAX = DOUBLE_TAG
104 } StackTag;
105
106 /* putting this in a .h file generates many copies - but its only a 
107  * debugging build.
108  */
109 static StgWord stg_arg_size[] = {
110     [REALWORLD_TAG] = 0,
111     [INT_TAG   ] = sizeofW(StgInt), 
112     [INT64_TAG ] = sizeofW(StgInt64), 
113     [WORD_TAG  ] = sizeofW(StgWord), 
114     [ADDR_TAG  ] = sizeofW(StgAddr), 
115     [CHAR_TAG  ] = sizeofW(StgChar),
116     [FLOAT_TAG ] = sizeofW(StgFloat), 
117     [DOUBLE_TAG] = sizeofW(StgDouble),
118     [STABLE_TAG] = sizeofW(StgWord)
119 };
120
121 #define ARG_SIZE(tag) stg_arg_size[stgCast(StgWord,tag)]
122
123 #endif /* DEBUG_EXTRA */
124
125 static inline int IS_ARG_TAG( StgWord p );
126 static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
127
128 /* -----------------------------------------------------------------------------
129    Argument checks.
130    
131    If (Sp + <n_args>) > Su { JMP_(stg_update_PAP); }
132    
133    Sp points to the topmost used word on the stack, and Su points to
134    the most recently pushed update frame.
135
136    Remember that <n_args> must include any tagging of unboxed values.
137
138    ARGS_CHK_LOAD_NODE is for top-level functions, whose entry
139    convention doesn't require that Node is loaded with a pointer to
140    the closure.  Thus we must load node before calling stg_updatePAP if
141    the argument check fails. 
142    -------------------------------------------------------------------------- */
143
144 #define ARGS_CHK(n)                             \
145         if ((P_)(Sp + (n)) > (P_)Su) {          \
146                 JMP_(stg_update_PAP);           \
147         }
148
149 #define ARGS_CHK_LOAD_NODE(n,closure)           \
150         if ((P_)(Sp + (n)) > (P_)Su) {          \
151                 R1.p = (P_)closure;             \
152                 JMP_(stg_update_PAP);           \
153         }
154
155 /* -----------------------------------------------------------------------------
156    Heap/Stack Checks.
157
158    When failing a check, we save a return address on the stack and
159    jump to a pre-compiled code fragment that saves the live registers
160    and returns to the scheduler.
161
162    The return address in most cases will be the beginning of the basic
163    block in which the check resides, since we need to perform the check
164    again on re-entry because someone else might have stolen the resource
165    in the meantime.
166    ------------------------------------------------------------------------- */
167
168 #define STK_CHK(headroom,ret,r,layout,tag_assts)                \
169         if (Sp - headroom < SpLim) {                            \
170             EXTFUN_RTS(stg_chk_##layout);                       \
171             tag_assts                                           \
172             (r) = (P_)ret;                                      \
173             JMP_(stg_chk_##layout);                             \
174         }
175        
176 #define HP_CHK(headroom,ret,r,layout,tag_assts)                 \
177         if ((Hp += headroom) > HpLim) {                         \
178             EXTFUN_RTS(stg_chk_##layout);                       \
179             tag_assts                                           \
180             (r) = (P_)ret;                                      \
181             JMP_(stg_chk_##layout);                             \
182         }                                                       \
183         TICK_ALLOC_HEAP(headroom);
184
185 #define HP_STK_CHK(stk_headroom,hp_headroom,ret,r,layout,tag_assts) \
186         if (Sp - stk_headroom < SpLim || (Hp += hp_headroom) > HpLim) { \
187             EXTFUN_RTS(stg_chk_##layout);                       \
188             tag_assts                                           \
189             (r) = (P_)ret;                                      \
190             JMP_(stg_chk_##layout);                             \
191         }                                                       \
192         TICK_ALLOC_HEAP(hp_headroom);
193
194 /* -----------------------------------------------------------------------------
195    A Heap Check in a case alternative are much simpler: everything is
196    on the stack and covered by a liveness mask already, and there is
197    even a return address with an SRT info table there as well.  
198
199    Just push R1 and return to the scheduler saying 'EnterGHC'
200
201    {STK,HP,HP_STK}_CHK_NP are the various checking macros for
202    bog-standard case alternatives, thunks, and non-top-level
203    functions.  In all these cases, node points to a closure that we
204    can just enter to restart the heap check (the NP stands for 'node points').
205
206    HpLim points to the LAST WORD of valid allocation space.
207    -------------------------------------------------------------------------- */
208
209 #define STK_CHK_NP(headroom,ptrs,tag_assts)                     \
210         if ((Sp - (headroom)) < SpLim) {                        \
211             EXTFUN_RTS(stg_gc_enter_##ptrs);                    \
212             tag_assts                                           \
213             JMP_(stg_gc_enter_##ptrs);                          \
214         }
215
216 #define HP_CHK_NP(headroom,ptrs,tag_assts)                      \
217         if ((Hp += (headroom)) > HpLim) {                       \
218             EXTFUN_RTS(stg_gc_enter_##ptrs);                    \
219             tag_assts                                           \
220             JMP_(stg_gc_enter_##ptrs);                          \
221         }                                                       \
222         TICK_ALLOC_HEAP(headroom);
223
224 #define HP_CHK_SEQ_NP(headroom,ptrs,tag_assts)                  \
225         if ((Hp += (headroom)) > HpLim) {                       \
226             EXTFUN_RTS(stg_gc_seq_##ptrs);                      \
227             tag_assts                                           \
228             JMP_(stg_gc_seq_##ptrs);                            \
229         }                                                       \
230         TICK_ALLOC_HEAP(headroom);
231
232 #define HP_STK_CHK_NP(stk_headroom, hp_headroom, ptrs, tag_assts) \
233         if ((Sp - (stk_headroom)) < SpLim || (Hp += (hp_headroom)) > HpLim) { \
234             EXTFUN_RTS(stg_gc_enter_##ptrs);                    \
235             tag_assts                                           \
236             JMP_(stg_gc_enter_##ptrs);                          \
237         }                                                       \
238         TICK_ALLOC_HEAP(hp_headroom);
239
240 /* Heap checks for branches of a primitive case / unboxed tuple return */
241
242 #define GEN_HP_CHK_ALT(headroom,lbl,tag_assts)                  \
243         if ((Hp += (headroom)) > HpLim) {                       \
244             EXTFUN_RTS(lbl);                                    \
245             tag_assts                                           \
246             JMP_(lbl);                                          \
247         }                                                       \
248         TICK_ALLOC_HEAP(headroom);
249
250 #define HP_CHK_NOREGS(headroom,tag_assts) \
251     GEN_HP_CHK_ALT(headroom,stg_gc_noregs,tag_assts);
252 #define HP_CHK_UNPT_R1(headroom,tag_assts)  \
253     GEN_HP_CHK_ALT(headroom,stg_gc_unpt_r1,tag_assts);
254 #define HP_CHK_UNBX_R1(headroom,tag_assts)  \
255     GEN_HP_CHK_ALT(headroom,stg_gc_unbx_r1,tag_assts);
256 #define HP_CHK_F1(headroom,tag_assts)       \
257     GEN_HP_CHK_ALT(headroom,stg_gc_f1,tag_assts);
258 #define HP_CHK_D1(headroom,tag_assts)       \
259     GEN_HP_CHK_ALT(headroom,stg_gc_d1,tag_assts);
260
261 #define HP_CHK_L1(headroom,tag_assts)       \
262     GEN_HP_CHK_ALT(headroom,stg_gc_d1,tag_assts);
263
264 #define HP_CHK_UT_ALT(headroom, ptrs, nptrs, r, ret, tag_assts) \
265     GEN_HP_CHK_ALT(headroom, stg_gc_ut_##ptrs##_##nptrs, \
266                      tag_assts r = (P_)ret;)
267
268 /* -----------------------------------------------------------------------------
269    Generic Heap checks.
270
271    These are slow, but have the advantage of being usable in a variety
272    of situations.  
273
274    The one restriction is that any relevant SRTs must already be pointed
275    to from the stack.  The return address doesn't need to have an info
276    table attached: hence it can be any old code pointer.
277
278    The liveness mask is a logical 'XOR' of NO_PTRS and zero or more
279    Rn_PTR constants defined below.  All registers will be saved, but
280    the garbage collector needs to know which ones contain pointers.
281
282    Good places to use a generic heap check: 
283
284         - case alternatives (the return address with an SRT is already
285           on the stack).
286
287         - primitives (no SRT required).
288
289    The stack layout is like this:
290
291           DblReg1-2
292           FltReg1-4
293           R1-8
294           return address
295           liveness mask
296           stg_gen_chk_info
297
298    so the liveness mask depends on the size of an StgDouble (FltRegs
299    and R<n> are guaranteed to be 1 word in size).
300
301    -------------------------------------------------------------------------- */
302
303 /* VERY MAGIC CONSTANTS! 
304  * must agree with code in HeapStackCheck.c, stg_gen_chk
305  */
306
307 #if SIZEOF_DOUBLE > SIZEOF_VOID_P
308 #define ALL_NON_PTRS   0xffff
309 #else /* SIZEOF_DOUBLE == SIZEOF_VOID_P */
310 #define ALL_NON_PTRS   0x3fff
311 #endif
312
313 #define LIVENESS_MASK(ptr_regs)  (ALL_NON_PTRS ^ (ptr_regs))
314
315 #define NO_PTRS   0
316 #define R1_PTR    1<<0
317 #define R2_PTR    1<<1
318 #define R3_PTR    1<<2
319 #define R4_PTR    1<<3
320 #define R5_PTR    1<<4
321 #define R6_PTR    1<<5
322 #define R7_PTR    1<<6
323 #define R8_PTR    1<<7
324
325 #define HP_CHK_GEN(headroom,liveness,reentry,tag_assts) \
326    if ((Hp += (headroom)) > HpLim ) {                   \
327         EF_(stg_gen_chk);                               \
328         tag_assts                                       \
329         R9.w = (W_)LIVENESS_MASK(liveness);             \
330         R10.w = (W_)reentry;                            \
331         JMP_(stg_gen_chk);                              \
332    }                                                    \
333    TICK_ALLOC_HEAP(headroom);
334
335 #define STK_CHK_GEN(headroom,liveness,reentry,tag_assts)        \
336    if ((Sp - (headroom)) < SpLim) {                             \
337         EF_(stg_gen_chk);                                       \
338         tag_assts                                               \
339         R9.w = (W_)LIVENESS_MASK(liveness);                     \
340         R10.w = (W_)reentry;                                    \
341         JMP_(stg_gen_chk);                                      \
342    }
343
344 #define MAYBE_GC(liveness,reentry)              \
345    if (doYouWantToGC()) {                       \
346         EF_(stg_gen_hp);                        \
347         R9.w = (W_)LIVENESS_MASK(liveness);     \
348         R10.w = (W_)reentry;                    \
349         JMP_(stg_gen_hp);                       \
350    }
351
352 /* -----------------------------------------------------------------------------
353    Voluntary Yields/Blocks
354
355    We only have a generic version of this at the moment - if it turns
356    out to be slowing us down we can make specialised ones.
357    -------------------------------------------------------------------------- */
358
359 EF_(stg_gen_yield);
360 EF_(stg_gen_block);
361
362 #define YIELD(liveness,reentry)                 \
363   {                                             \
364    R9.w  = (W_)LIVENESS_MASK(liveness);         \
365    R10.w = (W_)reentry;                         \
366    JMP_(stg_gen_yield);                         \
367   }
368
369 #define BLOCK(liveness,reentry)                 \
370   {                                             \
371    R9.w  = (W_)LIVENESS_MASK(liveness);         \
372    R10.w = (W_)reentry;                         \
373    JMP_(stg_gen_block);                         \
374   }
375
376 #define BLOCK_NP(ptrs)                          \
377   {                                             \
378     EF_(stg_block_##ptrs);                      \
379     JMP_(stg_block_##ptrs);                     \
380   }
381
382 /* -----------------------------------------------------------------------------
383    CCall_GC needs to push a dummy stack frame containing the contents
384    of volatile registers and variables.  
385
386    We use a RET_DYN frame the same as for a dynamic heap check.
387    ------------------------------------------------------------------------- */
388
389 #if COMPILING_RTS
390 EI_(stg_gen_chk_info);
391 #else
392 EDI_(stg_gen_chk_info);
393 #endif
394 /* -----------------------------------------------------------------------------
395    Vectored Returns
396
397    RETVEC(p,t) where 'p' is a pointer to the info table for a
398    vectored return address, returns the address of the return code for
399    tag 't'.
400
401    Return vectors are placed in *reverse order* immediately before the info
402    table for the return address.  Hence the formula for computing the
403    actual return address is (addr - sizeof(InfoTable) - tag - 1).
404    The extra subtraction of one word is because tags start at zero.
405    -------------------------------------------------------------------------- */
406
407 #ifdef USE_MINIINTERPRETER
408 #define RET_VEC(p,t) (((StgInfoTable *)p)->vector[t])
409 #else
410 #define RET_VEC(p,t) (*((P_)(p) - sizeofW(StgInfoTable) - t - 1))
411 #endif
412
413 /* -----------------------------------------------------------------------------
414    Misc
415    -------------------------------------------------------------------------- */
416
417 /* set the tag register (if we have one) */
418 #define SET_TAG(t)  /* nothing */
419
420 #ifdef EAGER_BLACKHOLING
421 #  define UPD_BH_UPDATABLE(thunk)                        \
422         TICK_UPD_BH_UPDATABLE();                         \
423         SET_INFO((StgClosure *)thunk,&BLACKHOLE_info)
424 #  define UPD_BH_SINGLE_ENTRY(thunk)                     \
425         TICK_UPD_BH_SINGLE_ENTRY();                      \
426         SET_INFO((StgClosure *)thunk,&SE_BLACKHOLE_info)
427 #else /* !EAGER_BLACKHOLING */
428 #  define UPD_BH_UPDATABLE(thunk)    /* nothing */
429 #  define UPD_BH_SINGLE_ENTRY(thunk) /* nothing */
430 #endif /* EAGER_BLACKHOLING */
431
432 /* -----------------------------------------------------------------------------
433    Moving Floats and Doubles
434
435    ASSIGN_FLT is for assigning a float to memory (usually the
436               stack/heap).  The memory address is guaranteed to be
437               StgWord aligned (currently == sizeof(long)).
438
439    PK_FLT     is for pulling a float out of memory.  The memory is
440               guaranteed to be StgWord aligned.
441    -------------------------------------------------------------------------- */
442
443 static inline void        ASSIGN_FLT (W_ [], StgFloat);
444 static inline StgFloat    PK_FLT     (W_ []);
445
446 #if ALIGNMENT_FLOAT <= ALIGNMENT_LONG
447
448 static inline void     ASSIGN_FLT(W_ p_dest[], StgFloat src) { *(StgFloat *)p_dest = src; }
449 static inline StgFloat PK_FLT    (W_ p_src[])                { return *(StgFloat *)p_src; }
450
451 #else  /* ALIGNMENT_FLOAT > ALIGNMENT_UNSIGNED_INT */
452
453 static inline void ASSIGN_FLT(W_ p_dest[], StgFloat src)
454 {
455     float_thing y;
456     y.f = src;
457     *p_dest = y.fu;
458 }
459
460 static inline StgFloat PK_FLT(W_ p_src[])
461 {
462     float_thing y;
463     y.fu = *p_src;
464     return(y.f);
465 }
466
467 #endif /* ALIGNMENT_FLOAT > ALIGNMENT_LONG */
468
469 #if ALIGNMENT_DOUBLE <= ALIGNMENT_LONG
470
471 static inline void        ASSIGN_DBL (W_ [], StgDouble);
472 static inline StgDouble   PK_DBL     (W_ []);
473
474 static inline void      ASSIGN_DBL(W_ p_dest[], StgDouble src) { *(StgDouble *)p_dest = src; }
475 static inline StgDouble PK_DBL    (W_ p_src[])                 { return *(StgDouble *)p_src; }
476
477 #else   /* ALIGNMENT_DOUBLE > ALIGNMENT_LONG */
478
479 /* Sparc uses two floating point registers to hold a double.  We can
480  * write ASSIGN_DBL and PK_DBL by directly accessing the registers
481  * independently - unfortunately this code isn't writable in C, we
482  * have to use inline assembler.
483  */
484 #if sparc_TARGET_ARCH
485
486 #define ASSIGN_DBL(dst0,src) \
487     { StgPtr dst = (StgPtr)(dst0); \
488       __asm__("st %2,%0\n\tst %R2,%1" : "=m" (((P_)(dst))[0]), \
489         "=m" (((P_)(dst))[1]) : "f" (src)); \
490     }
491
492 #define PK_DBL(src0) \
493     ( { StgPtr src = (StgPtr)(src0); \
494         register double d; \
495       __asm__("ld %1,%0\n\tld %2,%R0" : "=f" (d) : \
496         "m" (((P_)(src))[0]), "m" (((P_)(src))[1])); d; \
497     } )
498
499 #else /* ! sparc_TARGET_ARCH */
500
501 static inline void        ASSIGN_DBL (W_ [], StgDouble);
502 static inline StgDouble   PK_DBL     (W_ []);
503
504 typedef struct
505   { StgWord dhi;
506     StgWord dlo;
507   } unpacked_double;
508
509 typedef union
510   { StgDouble d;
511     unpacked_double du;
512   } double_thing;
513
514 static inline void ASSIGN_DBL(W_ p_dest[], StgDouble src)
515 {
516     double_thing y;
517     y.d = src;
518     p_dest[0] = y.du.dhi;
519     p_dest[1] = y.du.dlo;
520 }
521
522 /* GCC also works with this version, but it generates
523    the same code as the previous one, and is not ANSI
524
525 #define ASSIGN_DBL( p_dest, src ) \
526         *p_dest = ((double_thing) src).du.dhi; \
527         *(p_dest+1) = ((double_thing) src).du.dlo \
528 */
529
530 static inline StgDouble PK_DBL(W_ p_src[])
531 {
532     double_thing y;
533     y.du.dhi = p_src[0];
534     y.du.dlo = p_src[1];
535     return(y.d);
536 }
537
538 #endif /* ! sparc_TARGET_ARCH */
539
540 #endif /* ALIGNMENT_DOUBLE > ALIGNMENT_UNSIGNED_INT */
541
542 #ifdef SUPPORT_LONG_LONGS
543
544 typedef struct
545   { StgWord dhi;
546     StgWord dlo;
547   } unpacked_double_word;
548
549 typedef union
550   { StgInt64 i;
551     unpacked_double_word iu;
552   } int64_thing;
553
554 typedef union
555   { StgWord64 w;
556     unpacked_double_word wu;
557   } word64_thing;
558
559 static inline void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
560 {
561     word64_thing y;
562     y.w = src;
563     p_dest[0] = y.wu.dhi;
564     p_dest[1] = y.wu.dlo;
565 }
566
567 static inline StgWord64 PK_Word64(W_ p_src[])
568 {
569     word64_thing y;
570     y.wu.dhi = p_src[0];
571     y.wu.dlo = p_src[1];
572     return(y.w);
573 }
574
575 static inline void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
576 {
577     int64_thing y;
578     y.i = src;
579     p_dest[0] = y.iu.dhi;
580     p_dest[1] = y.iu.dlo;
581 }
582
583 static inline StgInt64 PK_Int64(W_ p_src[])
584 {
585     int64_thing y;
586     y.iu.dhi = p_src[0];
587     y.iu.dlo = p_src[1];
588     return(y.i);
589 }
590 #endif
591
592 /* -----------------------------------------------------------------------------
593    Catch frames
594    -------------------------------------------------------------------------- */
595
596 extern DLL_IMPORT_DATA const StgPolyInfoTable catch_frame_info;
597
598 /* -----------------------------------------------------------------------------
599    Seq frames
600
601    A seq frame is very like an update frame, except that it doesn't do
602    an update...
603    -------------------------------------------------------------------------- */
604
605 extern DLL_IMPORT_DATA const StgPolyInfoTable seq_frame_info;
606
607 #define PUSH_SEQ_FRAME(sp)                                      \
608         {                                                       \
609                 StgSeqFrame *__frame;                           \
610                 TICK_SEQF_PUSHED();                             \
611                 __frame = (StgSeqFrame *)(sp);                  \
612                 SET_HDR_(__frame,&seq_frame_info,CCCS);         \
613                 __frame->link = Su;                             \
614                 Su = (StgUpdateFrame *)__frame;                 \
615         }
616
617 /* -----------------------------------------------------------------------------
618    Split markers
619    -------------------------------------------------------------------------- */
620
621 #if defined(USE_SPLIT_MARKERS)
622 #define __STG_SPLIT_MARKER(n) FN_(__stg_split_marker##n) { }
623 #else
624 #define __STG_SPLIT_MARKER(n) /* nothing */
625 #endif
626
627 /* -----------------------------------------------------------------------------
628    Closure and Info Macros with casting.
629
630    We don't want to mess around with casts in the generated C code, so
631    we use these casting versions of the closure/info tables macros.
632    -------------------------------------------------------------------------- */
633
634 #define SET_HDR_(c,info,ccs) \
635    SET_HDR((StgClosure *)(c),(StgInfoTable *)(info),ccs)
636
637 /* -----------------------------------------------------------------------------
638    Saving context for exit from the STG world, and loading up context
639    on entry to STG code.
640
641    We save all the STG registers (that is, the ones that are mapped to
642    machine registers) in their places in the TSO.  
643
644    The stack registers go into the current stack object, and the heap
645    registers are saved in global locations.
646    -------------------------------------------------------------------------- */
647
648 static __inline__ void
649 SaveThreadState(void)
650 {
651   /* Don't need to save REG_Base, it won't have changed. */
652
653   CurrentTSO->sp       = Sp;
654   CurrentTSO->su       = Su;
655   CurrentTSO->splim    = SpLim;
656   CloseNursery(Hp);
657
658 #if defined(PROFILING)
659   CurrentTSO->prof.CCCS = CCCS;
660 #endif
661 }
662
663 static __inline__ void 
664 LoadThreadState (void)
665 {
666 #ifdef REG_Base
667   BaseReg = (StgRegTable*)&MainRegTable;
668 #endif
669
670   Sp    = CurrentTSO->sp;
671   Su    = CurrentTSO->su;
672   SpLim = CurrentTSO->splim;
673   OpenNursery(Hp,HpLim);
674
675 # if defined(PROFILING)
676   CCCS = CurrentTSO->prof.CCCS;
677 # endif
678 }
679
680 #endif /* STGMACROS_H */
681