Don't define STOLEN_X86_REGS in Cmm.h
[ghc.git] / includes / Cmm.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The University of Glasgow 2004-2012
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 * alloc_blocks ==> CInt[alloc_blocks]
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 * mkDerivedConstants.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
70 /* -----------------------------------------------------------------------------
71 Types
72
73 The following synonyms for C-- types are declared here:
74
75 I8, I16, I32, I64 MachRep-style names for convenience
76
77 W_ is shorthand for the word type (== StgWord)
78 F_ shorthand for float (F_ == StgFloat == C's float)
79 D_ shorthand for double (D_ == StgDouble == C's double)
80
81 CInt has the same size as an int in C on this platform
82 CLong has the same size as a long in C on this platform
83
84 --------------------------------------------------------------------------- */
85
86 #define I8 bits8
87 #define I16 bits16
88 #define I32 bits32
89 #define I64 bits64
90 #define P_ gcptr
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 #ifdef TABLES_NEXT_TO_CODE
147 #define RET_LBL(f) f##_info
148 #else
149 #define RET_LBL(f) f##_ret
150 #endif
151
152 #ifdef TABLES_NEXT_TO_CODE
153 #define ENTRY_LBL(f) f##_info
154 #else
155 #define ENTRY_LBL(f) f##_entry
156 #endif
157
158 /* -----------------------------------------------------------------------------
159 Byte/word macros
160
161 Everything in C-- is in byte offsets (well, most things). We use
162 some macros to allow us to express offsets in words and to try to
163 avoid byte/word confusion.
164 -------------------------------------------------------------------------- */
165
166 #define SIZEOF_W SIZEOF_VOID_P
167 #define W_MASK (SIZEOF_W-1)
168
169 #if SIZEOF_W == 4
170 #define W_SHIFT 2
171 #elif SIZEOF_W == 8
172 #define W_SHIFT 3
173 #endif
174
175 /* Converting quantities of words to bytes */
176 #define WDS(n) ((n)*SIZEOF_W)
177
178 /*
179 * Converting quantities of bytes to words
180 * NB. these work on *unsigned* values only
181 */
182 #define BYTES_TO_WDS(n) ((n) / SIZEOF_W)
183 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + SIZEOF_W - 1) / SIZEOF_W)
184
185 /* TO_W_(n) converts n to W_ type from a smaller type */
186 #if SIZEOF_W == 4
187 #define TO_W_(x) %sx32(x)
188 #define HALF_W_(x) %lobits16(x)
189 #elif SIZEOF_W == 8
190 #define TO_W_(x) %sx64(x)
191 #define HALF_W_(x) %lobits32(x)
192 #endif
193
194 #if SIZEOF_INT == 4 && SIZEOF_W == 8
195 #define W_TO_INT(x) %lobits32(x)
196 #elif SIZEOF_INT == SIZEOF_W
197 #define W_TO_INT(x) (x)
198 #endif
199
200 #if SIZEOF_LONG == 4 && SIZEOF_W == 8
201 #define W_TO_LONG(x) %lobits32(x)
202 #elif SIZEOF_LONG == SIZEOF_W
203 #define W_TO_LONG(x) (x)
204 #endif
205
206 /* -----------------------------------------------------------------------------
207 Heap/stack access, and adjusting the heap/stack pointers.
208 -------------------------------------------------------------------------- */
209
210 #define Sp(n) W_[Sp + WDS(n)]
211 #define Hp(n) W_[Hp + WDS(n)]
212
213 #define Sp_adj(n) Sp = Sp + WDS(n)
214 #define Hp_adj(n) Hp = Hp + WDS(n)
215
216 /* -----------------------------------------------------------------------------
217 Assertions and Debuggery
218 -------------------------------------------------------------------------- */
219
220 #ifdef DEBUG
221 #define ASSERT(predicate) \
222 if (predicate) { \
223 /*null*/; \
224 } else { \
225 foreign "C" _assertFail(NULL, __LINE__); \
226 }
227 #else
228 #define ASSERT(p) /* nothing */
229 #endif
230
231 #ifdef DEBUG
232 #define DEBUG_ONLY(s) s
233 #else
234 #define DEBUG_ONLY(s) /* nothing */
235 #endif
236
237 /*
238 * The IF_DEBUG macro is useful for debug messages that depend on one
239 * of the RTS debug options. For example:
240 *
241 * IF_DEBUG(RtsFlags_DebugFlags_apply,
242 * foreign "C" fprintf(stderr, stg_ap_0_ret_str));
243 *
244 * Note the syntax is slightly different to the C version of this macro.
245 */
246 #ifdef DEBUG
247 #define IF_DEBUG(c,s) if (RtsFlags_DebugFlags_##c(RtsFlags) != 0::I32) { s; }
248 #else
249 #define IF_DEBUG(c,s) /* nothing */
250 #endif
251
252 /* -----------------------------------------------------------------------------
253 Entering
254
255 It isn't safe to "enter" every closure. Functions in particular
256 have no entry code as such; their entry point contains the code to
257 apply the function.
258
259 ToDo: range should end in N_CLOSURE_TYPES-1, not N_CLOSURE_TYPES,
260 but switch doesn't allow us to use exprs there yet.
261
262 If R1 points to a tagged object it points either to
263 * A constructor.
264 * A function with arity <= TAG_MASK.
265 In both cases the right thing to do is to return.
266 Note: it is rather lucky that we can use the tag bits to do this
267 for both objects. Maybe it points to a brittle design?
268
269 Indirections can contain tagged pointers, so their tag is checked.
270 -------------------------------------------------------------------------- */
271
272 #ifdef PROFILING
273
274 // When profiling, we cannot shortcut ENTER() by checking the tag,
275 // because LDV profiling relies on entering closures to mark them as
276 // "used".
277
278 #define LOAD_INFO \
279 info = %INFO_PTR(UNTAG(P1));
280
281 #define UNTAG_R1 \
282 P1 = UNTAG(P1);
283
284 #else
285
286 #define LOAD_INFO \
287 if (GETTAG(P1) != 0) { \
288 jump %ENTRY_CODE(Sp(0)); \
289 } \
290 info = %INFO_PTR(P1);
291
292 #define UNTAG_R1 /* nothing */
293
294 #endif
295
296 #define ENTER() \
297 again: \
298 W_ info; \
299 LOAD_INFO \
300 switch [INVALID_OBJECT .. N_CLOSURE_TYPES] \
301 (TO_W_( %INFO_TYPE(%STD_INFO(info)) )) { \
302 case \
303 IND, \
304 IND_PERM, \
305 IND_STATIC: \
306 { \
307 P1 = StgInd_indirectee(P1); \
308 goto again; \
309 } \
310 case \
311 FUN, \
312 FUN_1_0, \
313 FUN_0_1, \
314 FUN_2_0, \
315 FUN_1_1, \
316 FUN_0_2, \
317 FUN_STATIC, \
318 BCO, \
319 PAP: \
320 { \
321 jump %ENTRY_CODE(Sp(0)); \
322 } \
323 default: \
324 { \
325 UNTAG_R1 \
326 jump %ENTRY_CODE(info); \
327 } \
328 }
329
330 // The FUN cases almost never happen: a pointer to a non-static FUN
331 // should always be tagged. This unfortunately isn't true for the
332 // interpreter right now, which leaves untagged FUNs on the stack.
333
334 /* -----------------------------------------------------------------------------
335 Constants.
336 -------------------------------------------------------------------------- */
337
338 #include "rts/Constants.h"
339 #include "DerivedConstants.h"
340 #include "rts/storage/ClosureTypes.h"
341 #include "rts/storage/FunTypes.h"
342 #include "rts/storage/SMPClosureOps.h"
343 #include "rts/OSThreads.h"
344
345 /*
346 * Need MachRegs, because some of the RTS code is conditionally
347 * compiled based on REG_R1, REG_R2, etc.
348 */
349 #include "stg/MachRegs.h"
350
351 #include "rts/storage/Liveness.h"
352 #include "rts/prof/LDV.h"
353
354 #undef BLOCK_SIZE
355 #undef MBLOCK_SIZE
356 #include "rts/storage/Block.h" /* For Bdescr() */
357
358
359 #define MyCapability() (BaseReg - OFFSET_Capability_r)
360
361 /* -------------------------------------------------------------------------
362 Allocation and garbage collection
363 ------------------------------------------------------------------------- */
364
365 /*
366 * ALLOC_PRIM is for allocating memory on the heap for a primitive
367 * object. It is used all over PrimOps.cmm.
368 *
369 * We make the simplifying assumption that the "admin" part of a
370 * primitive closure is just the header when calculating sizes for
371 * ticky-ticky. It's not clear whether eg. the size field of an array
372 * should be counted as "admin", or the various fields of a BCO.
373 */
374 #define ALLOC_PRIM(bytes,liveness,reentry) \
375 HP_CHK_GEN_TICKY(bytes,liveness,reentry); \
376 TICK_ALLOC_PRIM(SIZEOF_StgHeader,bytes-SIZEOF_StgHeader,0); \
377 CCCS_ALLOC(bytes);
378
379 /* CCS_ALLOC wants the size in words, because ccs->mem_alloc is in words */
380 #define CCCS_ALLOC(__alloc) CCS_ALLOC(BYTES_TO_WDS(__alloc), CCCS)
381
382 #define HP_CHK_GEN_TICKY(alloc,liveness,reentry) \
383 HP_CHK_GEN(alloc,liveness,reentry); \
384 TICK_ALLOC_HEAP_NOCTR(alloc);
385
386 // allocate() allocates from the nursery, so we check to see
387 // whether the nursery is nearly empty in any function that uses
388 // allocate() - this includes many of the primops.
389 #define MAYBE_GC(liveness,reentry) \
390 if (bdescr_link(CurrentNursery) == NULL || \
391 generation_n_new_large_words(W_[g0]) >= TO_W_(CLong[large_alloc_lim])) { \
392 R9 = liveness; \
393 R10 = reentry; \
394 HpAlloc = 0; \
395 jump stg_gc_gen_hp; \
396 }
397
398 /* -----------------------------------------------------------------------------
399 Closure headers
400 -------------------------------------------------------------------------- */
401
402 /*
403 * This is really ugly, since we don't do the rest of StgHeader this
404 * way. The problem is that values from DerivedConstants.h cannot be
405 * dependent on the way (SMP, PROF etc.). For SIZEOF_StgHeader we get
406 * the value from GHC, but it seems like too much trouble to do that
407 * for StgThunkHeader.
408 */
409 #define SIZEOF_StgThunkHeader SIZEOF_StgHeader+SIZEOF_StgSMPThunkHeader
410
411 #define StgThunk_payload(__ptr__,__ix__) \
412 W_[__ptr__+SIZEOF_StgThunkHeader+ WDS(__ix__)]
413
414 /* -----------------------------------------------------------------------------
415 Closures
416 -------------------------------------------------------------------------- */
417
418 /* The offset of the payload of an array */
419 #define BYTE_ARR_CTS(arr) ((arr) + SIZEOF_StgArrWords)
420
421 /* The number of words allocated in an array payload */
422 #define BYTE_ARR_WDS(arr) ROUNDUP_BYTES_TO_WDS(StgArrWords_bytes(arr))
423
424 /* Getting/setting the info pointer of a closure */
425 #define SET_INFO(p,info) StgHeader_info(p) = info
426 #define GET_INFO(p) StgHeader_info(p)
427
428 /* Determine the size of an ordinary closure from its info table */
429 #define sizeW_fromITBL(itbl) \
430 SIZEOF_StgHeader + WDS(%INFO_PTRS(itbl)) + WDS(%INFO_NPTRS(itbl))
431
432 /* NB. duplicated from InfoTables.h! */
433 #define BITMAP_SIZE(bitmap) ((bitmap) & BITMAP_SIZE_MASK)
434 #define BITMAP_BITS(bitmap) ((bitmap) >> BITMAP_BITS_SHIFT)
435
436 /* Debugging macros */
437 #define LOOKS_LIKE_INFO_PTR(p) \
438 ((p) != NULL && \
439 LOOKS_LIKE_INFO_PTR_NOT_NULL(p))
440
441 #define LOOKS_LIKE_INFO_PTR_NOT_NULL(p) \
442 ( (TO_W_(%INFO_TYPE(%STD_INFO(p))) != INVALID_OBJECT) && \
443 (TO_W_(%INFO_TYPE(%STD_INFO(p))) < N_CLOSURE_TYPES))
444
445 #define LOOKS_LIKE_CLOSURE_PTR(p) (LOOKS_LIKE_INFO_PTR(GET_INFO(UNTAG(p))))
446
447 /*
448 * The layout of the StgFunInfoExtra part of an info table changes
449 * depending on TABLES_NEXT_TO_CODE. So we define field access
450 * macros which use the appropriate version here:
451 */
452 #ifdef TABLES_NEXT_TO_CODE
453 /*
454 * when TABLES_NEXT_TO_CODE, slow_apply is stored as an offset
455 * instead of the normal pointer.
456 */
457
458 #define StgFunInfoExtra_slow_apply(fun_info) \
459 (TO_W_(StgFunInfoExtraRev_slow_apply_offset(fun_info)) \
460 + (fun_info) + SIZEOF_StgFunInfoExtraRev + SIZEOF_StgInfoTable)
461
462 #define StgFunInfoExtra_fun_type(i) StgFunInfoExtraRev_fun_type(i)
463 #define StgFunInfoExtra_arity(i) StgFunInfoExtraRev_arity(i)
464 #define StgFunInfoExtra_bitmap(i) StgFunInfoExtraRev_bitmap(i)
465 #else
466 #define StgFunInfoExtra_slow_apply(i) StgFunInfoExtraFwd_slow_apply(i)
467 #define StgFunInfoExtra_fun_type(i) StgFunInfoExtraFwd_fun_type(i)
468 #define StgFunInfoExtra_arity(i) StgFunInfoExtraFwd_arity(i)
469 #define StgFunInfoExtra_bitmap(i) StgFunInfoExtraFwd_bitmap(i)
470 #endif
471
472 #define mutArrCardMask ((1 << MUT_ARR_PTRS_CARD_BITS) - 1)
473 #define mutArrPtrCardDown(i) ((i) >> MUT_ARR_PTRS_CARD_BITS)
474 #define mutArrPtrCardUp(i) (((i) + mutArrCardMask) >> MUT_ARR_PTRS_CARD_BITS)
475 #define mutArrPtrsCardWords(n) ROUNDUP_BYTES_TO_WDS(mutArrPtrCardUp(n))
476
477 #if defined(PROFILING) || (!defined(THREADED_RTS) && defined(DEBUG))
478 #define OVERWRITING_CLOSURE(c) foreign "C" overwritingClosure(c "ptr")
479 #else
480 #define OVERWRITING_CLOSURE(c) /* nothing */
481 #endif
482
483 /* -----------------------------------------------------------------------------
484 Voluntary Yields/Blocks
485
486 We only have a generic version of this at the moment - if it turns
487 out to be slowing us down we can make specialised ones.
488 -------------------------------------------------------------------------- */
489
490 #define YIELD(liveness,reentry) \
491 R9 = liveness; \
492 R10 = reentry; \
493 jump stg_gen_yield;
494
495 #define BLOCK(liveness,reentry) \
496 R9 = liveness; \
497 R10 = reentry; \
498 jump stg_gen_block;
499
500 /* -----------------------------------------------------------------------------
501 Ticky macros
502 -------------------------------------------------------------------------- */
503
504 #ifdef TICKY_TICKY
505 #define TICK_BUMP_BY(ctr,n) CLong[ctr] = CLong[ctr] + n
506 #else
507 #define TICK_BUMP_BY(ctr,n) /* nothing */
508 #endif
509
510 #define TICK_BUMP(ctr) TICK_BUMP_BY(ctr,1)
511
512 #define TICK_ENT_DYN_IND() TICK_BUMP(ENT_DYN_IND_ctr)
513 #define TICK_ENT_DYN_THK() TICK_BUMP(ENT_DYN_THK_ctr)
514 #define TICK_ENT_VIA_NODE() TICK_BUMP(ENT_VIA_NODE_ctr)
515 #define TICK_ENT_STATIC_IND() TICK_BUMP(ENT_STATIC_IND_ctr)
516 #define TICK_ENT_PERM_IND() TICK_BUMP(ENT_PERM_IND_ctr)
517 #define TICK_ENT_PAP() TICK_BUMP(ENT_PAP_ctr)
518 #define TICK_ENT_AP() TICK_BUMP(ENT_AP_ctr)
519 #define TICK_ENT_AP_STACK() TICK_BUMP(ENT_AP_STACK_ctr)
520 #define TICK_ENT_BH() TICK_BUMP(ENT_BH_ctr)
521 #define TICK_UNKNOWN_CALL() TICK_BUMP(UNKNOWN_CALL_ctr)
522 #define TICK_UPDF_PUSHED() TICK_BUMP(UPDF_PUSHED_ctr)
523 #define TICK_CATCHF_PUSHED() TICK_BUMP(CATCHF_PUSHED_ctr)
524 #define TICK_UPDF_OMITTED() TICK_BUMP(UPDF_OMITTED_ctr)
525 #define TICK_UPD_NEW_IND() TICK_BUMP(UPD_NEW_IND_ctr)
526 #define TICK_UPD_NEW_PERM_IND() TICK_BUMP(UPD_NEW_PERM_IND_ctr)
527 #define TICK_UPD_OLD_IND() TICK_BUMP(UPD_OLD_IND_ctr)
528 #define TICK_UPD_OLD_PERM_IND() TICK_BUMP(UPD_OLD_PERM_IND_ctr)
529
530 #define TICK_SLOW_CALL_FUN_TOO_FEW() TICK_BUMP(SLOW_CALL_FUN_TOO_FEW_ctr)
531 #define TICK_SLOW_CALL_FUN_CORRECT() TICK_BUMP(SLOW_CALL_FUN_CORRECT_ctr)
532 #define TICK_SLOW_CALL_FUN_TOO_MANY() TICK_BUMP(SLOW_CALL_FUN_TOO_MANY_ctr)
533 #define TICK_SLOW_CALL_PAP_TOO_FEW() TICK_BUMP(SLOW_CALL_PAP_TOO_FEW_ctr)
534 #define TICK_SLOW_CALL_PAP_CORRECT() TICK_BUMP(SLOW_CALL_PAP_CORRECT_ctr)
535 #define TICK_SLOW_CALL_PAP_TOO_MANY() TICK_BUMP(SLOW_CALL_PAP_TOO_MANY_ctr)
536
537 #define TICK_SLOW_CALL_v() TICK_BUMP(SLOW_CALL_v_ctr)
538 #define TICK_SLOW_CALL_p() TICK_BUMP(SLOW_CALL_p_ctr)
539 #define TICK_SLOW_CALL_pv() TICK_BUMP(SLOW_CALL_pv_ctr)
540 #define TICK_SLOW_CALL_pp() TICK_BUMP(SLOW_CALL_pp_ctr)
541 #define TICK_SLOW_CALL_ppp() TICK_BUMP(SLOW_CALL_ppp_ctr)
542 #define TICK_SLOW_CALL_pppp() TICK_BUMP(SLOW_CALL_pppp_ctr)
543 #define TICK_SLOW_CALL_ppppp() TICK_BUMP(SLOW_CALL_ppppp_ctr)
544 #define TICK_SLOW_CALL_pppppp() TICK_BUMP(SLOW_CALL_pppppp_ctr)
545
546 /* NOTE: TICK_HISTO_BY and TICK_HISTO
547 currently have no effect.
548 The old code for it didn't typecheck and I
549 just commented it out to get ticky to work.
550 - krc 1/2007 */
551
552 #define TICK_HISTO_BY(histo,n,i) /* nothing */
553
554 #define TICK_HISTO(histo,n) TICK_HISTO_BY(histo,n,1)
555
556 /* An unboxed tuple with n components. */
557 #define TICK_RET_UNBOXED_TUP(n) \
558 TICK_BUMP(RET_UNBOXED_TUP_ctr++); \
559 TICK_HISTO(RET_UNBOXED_TUP,n)
560
561 /*
562 * A slow call with n arguments. In the unevald case, this call has
563 * already been counted once, so don't count it again.
564 */
565 #define TICK_SLOW_CALL(n) \
566 TICK_BUMP(SLOW_CALL_ctr); \
567 TICK_HISTO(SLOW_CALL,n)
568
569 /*
570 * This slow call was found to be to an unevaluated function; undo the
571 * ticks we did in TICK_SLOW_CALL.
572 */
573 #define TICK_SLOW_CALL_UNEVALD(n) \
574 TICK_BUMP(SLOW_CALL_UNEVALD_ctr); \
575 TICK_BUMP_BY(SLOW_CALL_ctr,-1); \
576 TICK_HISTO_BY(SLOW_CALL,n,-1);
577
578 /* Updating a closure with a new CON */
579 #define TICK_UPD_CON_IN_NEW(n) \
580 TICK_BUMP(UPD_CON_IN_NEW_ctr); \
581 TICK_HISTO(UPD_CON_IN_NEW,n)
582
583 #define TICK_ALLOC_HEAP_NOCTR(n) \
584 TICK_BUMP(ALLOC_HEAP_ctr); \
585 TICK_BUMP_BY(ALLOC_HEAP_tot,n)
586
587 /* -----------------------------------------------------------------------------
588 Misc junk
589 -------------------------------------------------------------------------- */
590
591 #define NO_TREC stg_NO_TREC_closure
592 #define END_TSO_QUEUE stg_END_TSO_QUEUE_closure
593 #define END_INVARIANT_CHECK_QUEUE stg_END_INVARIANT_CHECK_QUEUE_closure
594
595 #define recordMutableCap(p, gen, regs) \
596 W_ __bd; \
597 W_ mut_list; \
598 mut_list = Capability_mut_lists(MyCapability()) + WDS(gen); \
599 __bd = W_[mut_list]; \
600 if (bdescr_free(__bd) >= bdescr_start(__bd) + BLOCK_SIZE) { \
601 W_ __new_bd; \
602 ("ptr" __new_bd) = foreign "C" allocBlock_lock() [regs]; \
603 bdescr_link(__new_bd) = __bd; \
604 __bd = __new_bd; \
605 W_[mut_list] = __bd; \
606 } \
607 W_ free; \
608 free = bdescr_free(__bd); \
609 W_[free] = p; \
610 bdescr_free(__bd) = free + WDS(1);
611
612 #define recordMutable(p, regs) \
613 P_ __p; \
614 W_ __bd; \
615 W_ __gen; \
616 __p = p; \
617 __bd = Bdescr(__p); \
618 __gen = TO_W_(bdescr_gen_no(__bd)); \
619 if (__gen > 0) { recordMutableCap(__p, __gen, regs); }
620
621 #endif /* CMM_H */