comment out a bogus assertion
[ghc-hetmet.git] / includes / Cmm.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The University of Glasgow 2004
4  *
5  * This file is included at the top of all .cmm source files (and
6  * *only* .cmm files).  It defines a collection of useful macros for
7  * making .cmm code a bit less error-prone to write, and a bit easier
8  * on the eye for the reader.
9  *
10  * For the syntax of .cmm files, see the parser in ghc/compiler/cmm/CmmParse.y.
11  *
12  * If you're used to the old HC file syntax, here's a quick cheat sheet
13  * for converting HC code:
14  *
15  *       - Remove FB_/FE_
16  *       - Remove all type casts
17  *       - Remove '&'
18  *       - STGFUN(foo) { ... }  ==>  foo { ... }
19  *       - FN_(foo) { ... }  ==>  foo { ... }
20  *       - JMP_(e)  ==> jump e;
21  *       - Remove EXTFUN(foo)
22  *       - Sp[n]  ==>  Sp(n)
23  *       - Hp[n]  ==>  Hp(n)
24  *       - Sp += n  ==> Sp_adj(n)
25  *       - Hp += n  ==> Hp_adj(n)
26  *       - R1.i   ==>  R1   (similarly for R1.w, R1.cl etc.)
27  *       - You need to explicitly dereference variables; eg. 
28  *             context_switch   ==>  CInt[context_switch]
29  *       - convert all word offsets into byte offsets:
30  *              - e ==> WDS(e)
31  *       - sizeofW(StgFoo)  ==>  SIZEOF_StgFoo
32  *       - ENTRY_CODE(e)  ==>  %ENTRY_CODE(e)
33  *       - get_itbl(c)  ==>  %GET_STD_INFO(c)
34  *       - Change liveness masks in STK_CHK_GEN, HP_CHK_GEN:
35  *              R1_PTR | R2_PTR  ==>  R1_PTR & R2_PTR
36  *              (NOTE: | becomes &)
37  *       - Declarations like 'StgPtr p;' become just 'W_ p;'
38  *       - e->payload[n] ==> PAYLOAD(e,n)
39  *       - Be very careful with comparisons: the infix versions (>, >=, etc.)
40  *         are unsigned, so use %lt(a,b) to get signed less-than for example.
41  *
42  * Accessing fields of structures defined in the RTS header files is
43  * done via automatically-generated macros in DerivedConstants.h.  For
44  * example, where previously we used
45  *
46  *          CurrentTSO->what_next = x
47  *
48  * in C-- we now use
49  *
50  *          StgTSO_what_next(CurrentTSO) = x
51  *
52  * where the StgTSO_what_next() macro is automatically generated by
53  * mkDerivedConstnants.c.  If you need to access a field that doesn't
54  * already have a macro, edit that file (it's pretty self-explanatory).
55  *
56  * -------------------------------------------------------------------------- */
57
58 #ifndef CMM_H
59 #define CMM_H
60
61 /*
62  * In files that are included into both C and C-- (and perhaps
63  * Haskell) sources, we sometimes need to conditionally compile bits
64  * depending on the language.  CMINUSMINUS==1 in .cmm sources:
65  */
66 #define CMINUSMINUS 1
67
68 #include "ghcconfig.h"
69 #include "RtsConfig.h"
70
71 /* -----------------------------------------------------------------------------
72    Types 
73
74    The following synonyms for C-- types are declared here:
75
76      I8, I16, I32, I64    MachRep-style names for convenience
77
78      W_                   is shorthand for the word type (== StgWord)
79      F_                   shorthand for float  (F_ == StgFloat == C's float)
80      D_                   shorthand for double (D_ == StgDouble == C's double)
81
82      CInt                 has the same size as an int in C on this platform
83      CLong                has the same size as a long in C on this platform
84    
85   --------------------------------------------------------------------------- */
86
87 #define I8  bits8
88 #define I16 bits16
89 #define I32 bits32
90 #define I64 bits64
91
92 #if SIZEOF_VOID_P == 4
93 #define W_ bits32
94 /* Maybe it's better to include MachDeps.h */
95 #define TAG_BITS                2
96 #elif SIZEOF_VOID_P == 8
97 #define W_ bits64
98 /* Maybe it's better to include MachDeps.h */
99 #define TAG_BITS                3
100 #else
101 #error Unknown word size
102 #endif
103
104 /*
105  * The RTS must sometimes UNTAG a pointer before dereferencing it.
106  * See the wiki page Commentary/Rts/HaskellExecution/PointerTagging 
107  */
108 #define TAG_MASK ((1 << TAG_BITS) - 1)
109 #define UNTAG(p) (p & ~TAG_MASK)
110 #define GETTAG(p) (p & TAG_MASK)
111
112 #if SIZEOF_INT == 4
113 #define CInt bits32
114 #elif SIZEOF_INT == 8
115 #define CInt bits64
116 #else
117 #error Unknown int size
118 #endif
119
120 #if SIZEOF_LONG == 4
121 #define CLong bits32
122 #elif SIZEOF_LONG == 8
123 #define CLong bits64
124 #else
125 #error Unknown long size
126 #endif
127
128 #define F_ float32
129 #define D_ float64
130 #define L_ bits64
131
132 #define SIZEOF_StgDouble 8
133 #define SIZEOF_StgWord64 8
134
135 /* -----------------------------------------------------------------------------
136    Misc useful stuff
137    -------------------------------------------------------------------------- */
138
139 #define NULL (0::W_)
140
141 #define STRING(name,str)                        \
142   section "rodata" {                            \
143         name : bits8[] str;                     \
144   }                                             \
145
146 /* -----------------------------------------------------------------------------
147    Byte/word macros
148
149    Everything in C-- is in byte offsets (well, most things).  We use
150    some macros to allow us to express offsets in words and to try to
151    avoid byte/word confusion.
152    -------------------------------------------------------------------------- */
153
154 #define SIZEOF_W  SIZEOF_VOID_P
155 #define W_MASK    (SIZEOF_W-1)
156
157 #if SIZEOF_W == 4
158 #define W_SHIFT 2
159 #elif SIZEOF_W == 8
160 #define W_SHIFT 4
161 #endif
162
163 /* Converting quantities of words to bytes */
164 #define WDS(n) ((n)*SIZEOF_W)
165
166 /*
167  * Converting quantities of bytes to words
168  * NB. these work on *unsigned* values only
169  */
170 #define BYTES_TO_WDS(n) ((n) / SIZEOF_W)
171 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + SIZEOF_W - 1) / SIZEOF_W)
172
173 /* TO_W_(n) converts n to W_ type from a smaller type */
174 #if SIZEOF_W == 4
175 #define TO_W_(x) %sx32(x)
176 #define HALF_W_(x) %lobits16(x)
177 #elif SIZEOF_W == 8
178 #define TO_W_(x) %sx64(x)
179 #define HALF_W_(x) %lobits32(x)
180 #endif
181
182 #if SIZEOF_INT == 4 && SIZEOF_W == 8
183 #define W_TO_INT(x) %lobits32(x)
184 #elif SIZEOF_INT == SIZEOF_W
185 #define W_TO_INT(x) (x)
186 #endif
187
188 /* -----------------------------------------------------------------------------
189    Heap/stack access, and adjusting the heap/stack pointers.
190    -------------------------------------------------------------------------- */
191
192 #define Sp(n)  W_[Sp + WDS(n)]
193 #define Hp(n)  W_[Hp + WDS(n)]
194
195 #define Sp_adj(n) Sp = Sp + WDS(n)
196 #define Hp_adj(n) Hp = Hp + WDS(n)
197
198 /* -----------------------------------------------------------------------------
199    Assertions and Debuggery
200    -------------------------------------------------------------------------- */
201
202 #ifdef DEBUG
203 #define ASSERT(predicate)                       \
204         if (predicate) {                        \
205             /*null*/;                           \
206         } else {                                \
207             foreign "C" _assertFail(NULL, __LINE__); \
208         }
209 #else
210 #define ASSERT(p) /* nothing */
211 #endif
212
213 #ifdef DEBUG
214 #define DEBUG_ONLY(s) s
215 #else
216 #define DEBUG_ONLY(s) /* nothing */
217 #endif
218
219 /*
220  * The IF_DEBUG macro is useful for debug messages that depend on one
221  * of the RTS debug options.  For example:
222  * 
223  *   IF_DEBUG(RtsFlags_DebugFlags_apply,
224  *      foreign "C" fprintf(stderr, stg_ap_0_ret_str));
225  *
226  * Note the syntax is slightly different to the C version of this macro.
227  */
228 #ifdef DEBUG
229 #define IF_DEBUG(c,s)  if (RtsFlags_DebugFlags_##c(RtsFlags) != 0::I32) { s; }
230 #else
231 #define IF_DEBUG(c,s)  /* nothing */
232 #endif
233
234 /* -----------------------------------------------------------------------------
235    Entering 
236
237    It isn't safe to "enter" every closure.  Functions in particular
238    have no entry code as such; their entry point contains the code to
239    apply the function.
240
241    ToDo: range should end in N_CLOSURE_TYPES-1, not N_CLOSURE_TYPES,
242    but switch doesn't allow us to use exprs there yet.
243
244    If R1 points to a tagged object it points either to
245    * A constructor.
246    * A function with arity <= TAG_MASK.
247    In both cases the right thing to do is to return.
248    Note: it is rather lucky that we can use the tag bits to do this
249          for both objects. Maybe it points to a brittle design?
250
251    Indirections can contain tagged pointers, so their tag is checked.
252    -------------------------------------------------------------------------- */
253
254 #define ENTER()                                         \
255  again:                                                 \
256   W_ info;                                              \
257   if (GETTAG(R1) != 0) {                                \
258       jump %ENTRY_CODE(Sp(0));                          \
259   }                                                     \
260   info = %INFO_PTR(R1);                                 \
261   switch [INVALID_OBJECT .. N_CLOSURE_TYPES]            \
262          (TO_W_( %INFO_TYPE(%STD_INFO(info)) )) {       \
263   case                                                  \
264     IND,                                                \
265     IND_OLDGEN,                                         \
266     IND_PERM,                                           \
267     IND_OLDGEN_PERM,                                    \
268     IND_STATIC:                                         \
269    {                                                    \
270       R1 = StgInd_indirectee(R1);                       \
271       goto again;                                       \
272    }                                                    \
273   case                                                  \
274     FUN,                                                \
275     FUN_1_0,                                            \
276     FUN_0_1,                                            \
277     FUN_2_0,                                            \
278     FUN_1_1,                                            \
279     FUN_STATIC,                                         \
280     BCO,                                                \
281     PAP:                                                \
282    {                                                    \
283       jump %ENTRY_CODE(Sp(0));                          \
284    }                                                    \
285   default:                                              \
286    {                                                    \
287       jump %ENTRY_CODE(info);                           \
288    }                                                    \
289   }
290
291 // The FUN cases almost never happen: a pointer to a non-static FUN
292 // should always be tagged.  This unfortunately isn't true for the
293 // interpreter right now, which leaves untagged FUNs on the stack.
294
295 /* -----------------------------------------------------------------------------
296    Constants.
297    -------------------------------------------------------------------------- */
298
299 #include "Constants.h"
300 #include "DerivedConstants.h"
301 #include "ClosureTypes.h"
302 #include "StgFun.h"
303 #include "OSThreads.h"
304 #include "SMP.h"
305
306 /*
307  * Need MachRegs, because some of the RTS code is conditionally
308  * compiled based on REG_R1, REG_R2, etc.
309  */
310 #define STOLEN_X86_REGS 4
311 #include "MachRegs.h"
312
313 #include "Liveness.h"
314 #include "StgLdvProf.h"
315
316 #undef BLOCK_SIZE
317 #undef MBLOCK_SIZE
318 #include "Block.h"  /* For Bdescr() */
319
320
321 /* Can't think of a better place to put this. */
322 #if SIZEOF_mp_limb_t != SIZEOF_VOID_P
323 #error mp_limb_t != StgWord: assumptions in PrimOps.cmm are now false
324 #endif
325
326 #define MyCapability()  (BaseReg - OFFSET_Capability_r)
327
328 /* -------------------------------------------------------------------------
329    Allocation and garbage collection
330    ------------------------------------------------------------------------- */
331
332 /*
333  * ALLOC_PRIM is for allocating memory on the heap for a primitive
334  * object.  It is used all over PrimOps.cmm.
335  *
336  * We make the simplifying assumption that the "admin" part of a
337  * primitive closure is just the header when calculating sizes for
338  * ticky-ticky.  It's not clear whether eg. the size field of an array
339  * should be counted as "admin", or the various fields of a BCO.
340  */
341 #define ALLOC_PRIM(bytes,liveness,reentry)                      \
342    HP_CHK_GEN_TICKY(bytes,liveness,reentry);                    \
343    TICK_ALLOC_PRIM(SIZEOF_StgHeader,bytes-SIZEOF_StgHeader,0);  \
344    CCCS_ALLOC(bytes);
345
346 /* CCS_ALLOC wants the size in words, because ccs->mem_alloc is in words */
347 #define CCCS_ALLOC(__alloc) CCS_ALLOC(BYTES_TO_WDS(__alloc), W_[CCCS])
348
349 #define HP_CHK_GEN_TICKY(alloc,liveness,reentry)        \
350    HP_CHK_GEN(alloc,liveness,reentry);                  \
351    TICK_ALLOC_HEAP_NOCTR(alloc);
352
353 // allocateLocal() allocates from the nursery, so we check to see
354 // whether the nursery is nearly empty in any function that uses
355 // allocateLocal() - this includes many of the primops.
356 #define MAYBE_GC(liveness,reentry)                      \
357   if (bdescr_link(CurrentNursery) == NULL || CInt[alloc_blocks] >= CInt[alloc_blocks_lim]) {            \
358         R9  = liveness;                                 \
359         R10 = reentry;                                  \
360         HpAlloc = 0;                                    \
361         jump stg_gc_gen_hp;                             \
362    }
363
364 /* -----------------------------------------------------------------------------
365    Closure headers
366    -------------------------------------------------------------------------- */
367
368 /*
369  * This is really ugly, since we don't do the rest of StgHeader this
370  * way.  The problem is that values from DerivedConstants.h cannot be 
371  * dependent on the way (SMP, PROF etc.).  For SIZEOF_StgHeader we get
372  * the value from GHC, but it seems like too much trouble to do that
373  * for StgThunkHeader.
374  */
375 #define SIZEOF_StgThunkHeader SIZEOF_StgHeader+SIZEOF_StgSMPThunkHeader
376
377 #define StgThunk_payload(__ptr__,__ix__) \
378     W_[__ptr__+SIZEOF_StgThunkHeader+ WDS(__ix__)]
379
380 /* -----------------------------------------------------------------------------
381    Closures
382    -------------------------------------------------------------------------- */
383
384 /* The offset of the payload of an array */
385 #define BYTE_ARR_CTS(arr)  ((arr) + SIZEOF_StgArrWords)
386
387 /* Getting/setting the info pointer of a closure */
388 #define SET_INFO(p,info) StgHeader_info(p) = info
389 #define GET_INFO(p) StgHeader_info(p)
390
391 /* Determine the size of an ordinary closure from its info table */
392 #define sizeW_fromITBL(itbl) \
393   SIZEOF_StgHeader + WDS(%INFO_PTRS(itbl)) + WDS(%INFO_NPTRS(itbl))
394
395 /* NB. duplicated from InfoTables.h! */
396 #define BITMAP_SIZE(bitmap) ((bitmap) & BITMAP_SIZE_MASK)
397 #define BITMAP_BITS(bitmap) ((bitmap) >> BITMAP_BITS_SHIFT)
398
399 /* Debugging macros */
400 #define LOOKS_LIKE_INFO_PTR(p)                                  \
401    ((p) != NULL &&                                              \
402     LOOKS_LIKE_INFO_PTR_NOT_NULL(p))
403
404 #define LOOKS_LIKE_INFO_PTR_NOT_NULL(p)                         \
405    ( (TO_W_(%INFO_TYPE(%STD_INFO(p))) != INVALID_OBJECT) &&     \
406      (TO_W_(%INFO_TYPE(%STD_INFO(p))) <  N_CLOSURE_TYPES))
407
408 #define LOOKS_LIKE_CLOSURE_PTR(p) (LOOKS_LIKE_INFO_PTR(GET_INFO(UNTAG(p))))
409
410 /*
411  * The layout of the StgFunInfoExtra part of an info table changes
412  * depending on TABLES_NEXT_TO_CODE.  So we define field access
413  * macros which use the appropriate version here:
414  */
415 #ifdef TABLES_NEXT_TO_CODE
416 /*
417  * when TABLES_NEXT_TO_CODE, slow_apply is stored as an offset
418  * instead of the normal pointer.
419  */
420         
421 #define StgFunInfoExtra_slow_apply(fun_info)    \
422         (TO_W_(StgFunInfoExtraRev_slow_apply_offset(fun_info))    \
423                + (fun_info) + SIZEOF_StgFunInfoExtraRev + SIZEOF_StgInfoTable)
424
425 #define StgFunInfoExtra_fun_type(i)   StgFunInfoExtraRev_fun_type(i)
426 #define StgFunInfoExtra_arity(i)      StgFunInfoExtraRev_arity(i)
427 #define StgFunInfoExtra_bitmap(i)     StgFunInfoExtraRev_bitmap(i)
428 #else
429 #define StgFunInfoExtra_slow_apply(i) StgFunInfoExtraFwd_slow_apply(i)
430 #define StgFunInfoExtra_fun_type(i)   StgFunInfoExtraFwd_fun_type(i)
431 #define StgFunInfoExtra_arity(i)      StgFunInfoExtraFwd_arity(i)
432 #define StgFunInfoExtra_bitmap(i)     StgFunInfoExtraFwd_bitmap(i)
433 #endif
434
435 /* -----------------------------------------------------------------------------
436    Voluntary Yields/Blocks
437
438    We only have a generic version of this at the moment - if it turns
439    out to be slowing us down we can make specialised ones.
440    -------------------------------------------------------------------------- */
441
442 #define YIELD(liveness,reentry)                 \
443    R9  = liveness;                              \
444    R10 = reentry;                               \
445    jump stg_gen_yield;
446
447 #define BLOCK(liveness,reentry)                 \
448    R9  = liveness;                              \
449    R10 = reentry;                               \
450    jump stg_gen_block;
451
452 /* -----------------------------------------------------------------------------
453    Ticky macros 
454    -------------------------------------------------------------------------- */
455
456 #ifdef TICKY_TICKY
457 #define TICK_BUMP_BY(ctr,n) CLong[ctr] = CLong[ctr] + n
458 #else
459 #define TICK_BUMP_BY(ctr,n) /* nothing */
460 #endif
461
462 #define TICK_BUMP(ctr)      TICK_BUMP_BY(ctr,1)
463
464 #define TICK_ENT_DYN_IND()              TICK_BUMP(ENT_DYN_IND_ctr)
465 #define TICK_ENT_DYN_THK()              TICK_BUMP(ENT_DYN_THK_ctr)
466 #define TICK_ENT_VIA_NODE()             TICK_BUMP(ENT_VIA_NODE_ctr)
467 #define TICK_ENT_STATIC_IND()           TICK_BUMP(ENT_STATIC_IND_ctr)
468 #define TICK_ENT_PERM_IND()             TICK_BUMP(ENT_PERM_IND_ctr)
469 #define TICK_ENT_PAP()                  TICK_BUMP(ENT_PAP_ctr)
470 #define TICK_ENT_AP()                   TICK_BUMP(ENT_AP_ctr)
471 #define TICK_ENT_AP_STACK()             TICK_BUMP(ENT_AP_STACK_ctr)
472 #define TICK_ENT_BH()                   TICK_BUMP(ENT_BH_ctr)
473 #define TICK_UNKNOWN_CALL()             TICK_BUMP(UNKNOWN_CALL_ctr)
474 #define TICK_UPDF_PUSHED()              TICK_BUMP(UPDF_PUSHED_ctr)
475 #define TICK_CATCHF_PUSHED()            TICK_BUMP(CATCHF_PUSHED_ctr)
476 #define TICK_UPDF_OMITTED()             TICK_BUMP(UPDF_OMITTED_ctr)
477 #define TICK_UPD_NEW_IND()              TICK_BUMP(UPD_NEW_IND_ctr)
478 #define TICK_UPD_NEW_PERM_IND()         TICK_BUMP(UPD_NEW_PERM_IND_ctr)
479 #define TICK_UPD_OLD_IND()              TICK_BUMP(UPD_OLD_IND_ctr)
480 #define TICK_UPD_OLD_PERM_IND()         TICK_BUMP(UPD_OLD_PERM_IND_ctr)
481   
482 #define TICK_SLOW_CALL_FUN_TOO_FEW()    TICK_BUMP(SLOW_CALL_FUN_TOO_FEW_ctr)
483 #define TICK_SLOW_CALL_FUN_CORRECT()    TICK_BUMP(SLOW_CALL_FUN_CORRECT_ctr)
484 #define TICK_SLOW_CALL_FUN_TOO_MANY()   TICK_BUMP(SLOW_CALL_FUN_TOO_MANY_ctr)
485 #define TICK_SLOW_CALL_PAP_TOO_FEW()    TICK_BUMP(SLOW_CALL_PAP_TOO_FEW_ctr)
486 #define TICK_SLOW_CALL_PAP_CORRECT()    TICK_BUMP(SLOW_CALL_PAP_CORRECT_ctr)
487 #define TICK_SLOW_CALL_PAP_TOO_MANY()   TICK_BUMP(SLOW_CALL_PAP_TOO_MANY_ctr)
488
489 #define TICK_SLOW_CALL_v()              TICK_BUMP(SLOW_CALL_v_ctr)
490 #define TICK_SLOW_CALL_p()              TICK_BUMP(SLOW_CALL_p_ctr)
491 #define TICK_SLOW_CALL_pv()             TICK_BUMP(SLOW_CALL_pv_ctr)
492 #define TICK_SLOW_CALL_pp()             TICK_BUMP(SLOW_CALL_pp_ctr)
493 #define TICK_SLOW_CALL_ppp()            TICK_BUMP(SLOW_CALL_ppp_ctr)
494 #define TICK_SLOW_CALL_pppp()           TICK_BUMP(SLOW_CALL_pppp_ctr)
495 #define TICK_SLOW_CALL_ppppp()          TICK_BUMP(SLOW_CALL_ppppp_ctr)
496 #define TICK_SLOW_CALL_pppppp()         TICK_BUMP(SLOW_CALL_pppppp_ctr)
497
498 /* NOTE: TICK_HISTO_BY and TICK_HISTO 
499    currently have no effect.
500    The old code for it didn't typecheck and I 
501    just commented it out to get ticky to work.
502    - krc 1/2007 */
503
504 #define TICK_HISTO_BY(histo,n,i) /* nothing */
505
506 #define TICK_HISTO(histo,n) TICK_HISTO_BY(histo,n,1)
507
508 /* An unboxed tuple with n components. */
509 #define TICK_RET_UNBOXED_TUP(n)                 \
510   TICK_BUMP(RET_UNBOXED_TUP_ctr++);             \
511   TICK_HISTO(RET_UNBOXED_TUP,n)
512
513 /*
514  * A slow call with n arguments.  In the unevald case, this call has
515  * already been counted once, so don't count it again.
516  */
517 #define TICK_SLOW_CALL(n)                       \
518   TICK_BUMP(SLOW_CALL_ctr);                     \
519   TICK_HISTO(SLOW_CALL,n)
520
521 /*
522  * This slow call was found to be to an unevaluated function; undo the
523  * ticks we did in TICK_SLOW_CALL.
524  */
525 #define TICK_SLOW_CALL_UNEVALD(n)               \
526   TICK_BUMP(SLOW_CALL_UNEVALD_ctr);             \
527   TICK_BUMP_BY(SLOW_CALL_ctr,-1);               \
528   TICK_HISTO_BY(SLOW_CALL,n,-1);
529
530 /* Updating a closure with a new CON */
531 #define TICK_UPD_CON_IN_NEW(n)                  \
532   TICK_BUMP(UPD_CON_IN_NEW_ctr);                \
533   TICK_HISTO(UPD_CON_IN_NEW,n)
534
535 #define TICK_ALLOC_HEAP_NOCTR(n)                \
536     TICK_BUMP(ALLOC_HEAP_ctr);                  \
537     TICK_BUMP_BY(ALLOC_HEAP_tot,n)
538
539 /* -----------------------------------------------------------------------------
540    Misc junk
541    -------------------------------------------------------------------------- */
542
543 #define NO_TREC                   stg_NO_TREC_closure
544 #define END_TSO_QUEUE             stg_END_TSO_QUEUE_closure
545 #define END_INVARIANT_CHECK_QUEUE stg_END_INVARIANT_CHECK_QUEUE_closure
546
547 #define dirtyTSO(tso) \
548     StgTSO_flags(tso) = StgTSO_flags(tso) | TSO_DIRTY::I32;
549
550 #define recordMutableCap(p, gen, regs)                                  \
551   W_ __bd;                                                              \
552   W_ mut_list;                                                          \
553   mut_list = Capability_mut_lists(MyCapability()) + WDS(gen);           \
554  __bd = W_[mut_list];                                                   \
555   if (bdescr_free(__bd) >= bdescr_start(__bd) + BLOCK_SIZE) {           \
556       W_ __new_bd;                                                      \
557       ("ptr" __new_bd) = foreign "C" allocBlock_lock() [regs];          \
558       bdescr_link(__new_bd) = __bd;                                     \
559       __bd = __new_bd;                                                  \
560       W_[mut_list] = __bd;                                              \
561   }                                                                     \
562   W_ free;                                                              \
563   free = bdescr_free(__bd);                                             \
564   W_[free] = p;                                                         \
565   bdescr_free(__bd) = free + WDS(1);
566
567 #define recordMutable(p, regs)                                  \
568       W_ __p;                                                   \
569       W_ __bd;                                                  \
570       W_ __gen;                                                 \
571       __p = p;                                                  \
572       __bd = Bdescr(__p);                                       \
573       __gen = TO_W_(bdescr_gen_no(__bd));                       \
574       if (__gen > 0) { recordMutableCap(__p, __gen, regs); }
575
576 #endif /* CMM_H */