1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Out-of-line primitive operations
7 * This file contains the implementations of all the primitive
8 * operations ("primops") which are not expanded inline. See
9 * ghc/compiler/prelude/primops.txt.pp for a list of all the primops;
10 * this file contains code for most of those with the attribute
13 * Entry convention: the entry convention for a primop is that all the
14 * args are in Stg registers (R1, R2, etc.). This is to make writing
15 * the primops easier. (see compiler/codeGen/CgCallConv.hs).
17 * Return convention: results from a primop are generally returned
18 * using the ordinary unboxed tuple return convention. The C-- parser
19 * implements the RET_xxxx() macros to perform unboxed-tuple returns
20 * based on the prevailing return convention.
22 * This file is written in a subset of C--, extended with various
23 * features specific to GHC. It is compiled by GHC directly. For the
24 * syntax of .cmm files, see the parser in ghc/compiler/cmm/CmmParse.y.
26 * ---------------------------------------------------------------------------*/
31 #ifndef mingw32_HOST_OS
41 import __gmpz_tdiv_qr;
42 import __gmpz_fdiv_qr;
43 import __gmpz_divexact;
49 import pthread_mutex_lock;
50 import pthread_mutex_unlock;
52 import base_ControlziExceptionziBase_nestedAtomically_closure;
53 import EnterCriticalSection;
54 import LeaveCriticalSection;
55 import ghczmprim_GHCziBool_False_closure;
57 /*-----------------------------------------------------------------------------
60 Basically just new*Array - the others are all inline macros.
62 The size arg is always passed in R1, and the result returned in R1.
64 The slow entry point is for returning from a heap check, the saved
65 size argument must be re-loaded from the stack.
66 -------------------------------------------------------------------------- */
68 /* for objects that are *less* than the size of a word, make sure we
69 * round up to the nearest word for the size of the array.
74 W_ words, payload_words, n, p;
75 MAYBE_GC(NO_PTRS,newByteArrayzh_fast);
77 payload_words = ROUNDUP_BYTES_TO_WDS(n);
78 words = BYTES_TO_WDS(SIZEOF_StgArrWords) + payload_words;
79 ("ptr" p) = foreign "C" allocateLocal(MyCapability() "ptr",words) [];
80 TICK_ALLOC_PRIM(SIZEOF_StgArrWords,WDS(payload_words),0);
81 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
82 StgArrWords_words(p) = payload_words;
87 #define BA_MASK (BA_ALIGN-1)
89 newPinnedByteArrayzh_fast
91 W_ words, bytes, payload_words, p;
93 MAYBE_GC(NO_PTRS,newPinnedByteArrayzh_fast);
95 /* payload_words is what we will tell the profiler we had to allocate */
96 payload_words = ROUNDUP_BYTES_TO_WDS(bytes);
97 /* When we actually allocate memory, we need to allow space for the
99 bytes = bytes + SIZEOF_StgArrWords;
100 /* And we want to align to BA_ALIGN bytes, so we need to allow space
101 to shift up to BA_ALIGN - 1 bytes: */
102 bytes = bytes + BA_ALIGN - 1;
103 /* Now we convert to a number of words: */
104 words = ROUNDUP_BYTES_TO_WDS(bytes);
106 ("ptr" p) = foreign "C" allocatePinned(words) [];
107 TICK_ALLOC_PRIM(SIZEOF_StgArrWords,WDS(payload_words),0);
109 /* Now we need to move p forward so that the payload is aligned
110 to BA_ALIGN bytes: */
111 p = p + ((-p - SIZEOF_StgArrWords) & BA_MASK);
113 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
114 StgArrWords_words(p) = payload_words;
118 newAlignedPinnedByteArrayzh_fast
120 W_ words, bytes, payload_words, p, alignment;
122 MAYBE_GC(NO_PTRS,newAlignedPinnedByteArrayzh_fast);
126 /* payload_words is what we will tell the profiler we had to allocate */
127 payload_words = ROUNDUP_BYTES_TO_WDS(bytes);
129 /* When we actually allocate memory, we need to allow space for the
131 bytes = bytes + SIZEOF_StgArrWords;
132 /* And we want to align to <alignment> bytes, so we need to allow space
133 to shift up to <alignment - 1> bytes: */
134 bytes = bytes + alignment - 1;
135 /* Now we convert to a number of words: */
136 words = ROUNDUP_BYTES_TO_WDS(bytes);
138 ("ptr" p) = foreign "C" allocatePinned(words) [];
139 TICK_ALLOC_PRIM(SIZEOF_StgArrWords,WDS(payload_words),0);
141 /* Now we need to move p forward so that the payload is aligned
142 to <alignment> bytes. Note that we are assuming that
143 <alignment> is a power of 2, which is technically not guaranteed */
144 p = p + ((-p - SIZEOF_StgArrWords) & (alignment - 1));
146 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
147 StgArrWords_words(p) = payload_words;
153 W_ words, n, init, arr, p;
154 /* Args: R1 = words, R2 = initialisation value */
157 MAYBE_GC(R2_PTR,newArrayzh_fast);
159 words = BYTES_TO_WDS(SIZEOF_StgMutArrPtrs) + n;
160 ("ptr" arr) = foreign "C" allocateLocal(MyCapability() "ptr",words) [R2];
161 TICK_ALLOC_PRIM(SIZEOF_StgMutArrPtrs, WDS(n), 0);
163 SET_HDR(arr, stg_MUT_ARR_PTRS_DIRTY_info, W_[CCCS]);
164 StgMutArrPtrs_ptrs(arr) = n;
166 // Initialise all elements of the the array with the value in R2
168 p = arr + SIZEOF_StgMutArrPtrs;
170 if (p < arr + WDS(words)) {
179 unsafeThawArrayzh_fast
181 // SUBTLETY TO DO WITH THE OLD GEN MUTABLE LIST
183 // A MUT_ARR_PTRS lives on the mutable list, but a MUT_ARR_PTRS_FROZEN
184 // normally doesn't. However, when we freeze a MUT_ARR_PTRS, we leave
185 // it on the mutable list for the GC to remove (removing something from
186 // the mutable list is not easy, because the mut_list is only singly-linked).
188 // So that we can tell whether a MUT_ARR_PTRS_FROZEN is on the mutable list,
189 // when we freeze it we set the info ptr to be MUT_ARR_PTRS_FROZEN0
190 // to indicate that it is still on the mutable list.
192 // So, when we thaw a MUT_ARR_PTRS_FROZEN, we must cope with two cases:
193 // either it is on a mut_list, or it isn't. We adopt the convention that
194 // the closure type is MUT_ARR_PTRS_FROZEN0 if it is on the mutable list,
195 // and MUT_ARR_PTRS_FROZEN otherwise. In fact it wouldn't matter if
196 // we put it on the mutable list more than once, but it would get scavenged
197 // multiple times during GC, which would be unnecessarily slow.
199 if (StgHeader_info(R1) != stg_MUT_ARR_PTRS_FROZEN0_info) {
200 SET_INFO(R1,stg_MUT_ARR_PTRS_DIRTY_info);
201 recordMutable(R1, R1);
202 // must be done after SET_INFO, because it ASSERTs closure_MUTABLE()
205 SET_INFO(R1,stg_MUT_ARR_PTRS_DIRTY_info);
210 /* -----------------------------------------------------------------------------
212 -------------------------------------------------------------------------- */
217 /* Args: R1 = initialisation value */
219 ALLOC_PRIM( SIZEOF_StgMutVar, R1_PTR, newMutVarzh_fast);
221 mv = Hp - SIZEOF_StgMutVar + WDS(1);
222 SET_HDR(mv,stg_MUT_VAR_DIRTY_info,W_[CCCS]);
223 StgMutVar_var(mv) = R1;
228 atomicModifyMutVarzh_fast
230 W_ mv, f, z, x, y, r, h;
231 /* Args: R1 :: MutVar#, R2 :: a -> (a,b) */
233 /* If x is the current contents of the MutVar#, then
234 We want to make the new contents point to
238 and the return value is
242 obviously we can share (f x).
244 z = [stg_ap_2 f x] (max (HS + 2) MIN_UPD_SIZE)
245 y = [stg_sel_0 z] (max (HS + 1) MIN_UPD_SIZE)
246 r = [stg_sel_1 z] (max (HS + 1) MIN_UPD_SIZE)
250 #define THUNK_1_SIZE (SIZEOF_StgThunkHeader + WDS(MIN_UPD_SIZE))
251 #define TICK_ALLOC_THUNK_1() TICK_ALLOC_UP_THK(WDS(1),WDS(MIN_UPD_SIZE-1))
253 #define THUNK_1_SIZE (SIZEOF_StgThunkHeader + WDS(1))
254 #define TICK_ALLOC_THUNK_1() TICK_ALLOC_UP_THK(WDS(1),0)
258 #define THUNK_2_SIZE (SIZEOF_StgThunkHeader + WDS(MIN_UPD_SIZE))
259 #define TICK_ALLOC_THUNK_2() TICK_ALLOC_UP_THK(WDS(2),WDS(MIN_UPD_SIZE-2))
261 #define THUNK_2_SIZE (SIZEOF_StgThunkHeader + WDS(2))
262 #define TICK_ALLOC_THUNK_2() TICK_ALLOC_UP_THK(WDS(2),0)
265 #define SIZE (THUNK_2_SIZE + THUNK_1_SIZE + THUNK_1_SIZE)
267 HP_CHK_GEN_TICKY(SIZE, R1_PTR & R2_PTR, atomicModifyMutVarzh_fast);
272 TICK_ALLOC_THUNK_2();
273 CCCS_ALLOC(THUNK_2_SIZE);
274 z = Hp - THUNK_2_SIZE + WDS(1);
275 SET_HDR(z, stg_ap_2_upd_info, W_[CCCS]);
276 LDV_RECORD_CREATE(z);
277 StgThunk_payload(z,0) = f;
279 TICK_ALLOC_THUNK_1();
280 CCCS_ALLOC(THUNK_1_SIZE);
281 y = z - THUNK_1_SIZE;
282 SET_HDR(y, stg_sel_0_upd_info, W_[CCCS]);
283 LDV_RECORD_CREATE(y);
284 StgThunk_payload(y,0) = z;
286 TICK_ALLOC_THUNK_1();
287 CCCS_ALLOC(THUNK_1_SIZE);
288 r = y - THUNK_1_SIZE;
289 SET_HDR(r, stg_sel_1_upd_info, W_[CCCS]);
290 LDV_RECORD_CREATE(r);
291 StgThunk_payload(r,0) = z;
294 x = StgMutVar_var(mv);
295 StgThunk_payload(z,1) = x;
297 (h) = foreign "C" cas(mv + SIZEOF_StgHeader + OFFSET_StgMutVar_var, x, y) [];
298 if (h != x) { goto retry; }
300 StgMutVar_var(mv) = y;
303 if (GET_INFO(mv) == stg_MUT_VAR_CLEAN_info) {
304 foreign "C" dirty_MUT_VAR(BaseReg "ptr", mv "ptr") [];
310 /* -----------------------------------------------------------------------------
311 Weak Pointer Primitives
312 -------------------------------------------------------------------------- */
314 STRING(stg_weak_msg,"New weak pointer at %p\n")
320 R3 = finalizer (or NULL)
325 R3 = stg_NO_FINALIZER_closure;
328 ALLOC_PRIM( SIZEOF_StgWeak, R1_PTR & R2_PTR & R3_PTR, mkWeakzh_fast );
330 w = Hp - SIZEOF_StgWeak + WDS(1);
331 SET_HDR(w, stg_WEAK_info, W_[CCCS]);
333 // We don't care about cfinalizer here.
334 // Should StgWeak_cfinalizer(w) be stg_NO_FINALIZER_closure or
338 StgWeak_value(w) = R2;
339 StgWeak_finalizer(w) = R3;
340 StgWeak_cfinalizer(w) = stg_NO_FINALIZER_closure;
342 StgWeak_link(w) = W_[weak_ptr_list];
343 W_[weak_ptr_list] = w;
345 IF_DEBUG(weak, foreign "C" debugBelch(stg_weak_msg,w) []);
350 mkWeakForeignEnvzh_fast
356 R5 = has environment (0 or 1)
359 W_ w, payload_words, words, p;
361 W_ key, val, fptr, ptr, flag, eptr;
370 ALLOC_PRIM( SIZEOF_StgWeak, R1_PTR & R2_PTR & R3_PTR, mkWeakForeignEnvzh_fast );
372 w = Hp - SIZEOF_StgWeak + WDS(1);
373 SET_HDR(w, stg_WEAK_info, W_[CCCS]);
376 words = BYTES_TO_WDS(SIZEOF_StgArrWords) + payload_words;
377 ("ptr" p) = foreign "C" allocateLocal(MyCapability() "ptr", words) [];
379 TICK_ALLOC_PRIM(SIZEOF_StgArrWords,WDS(payload_words),0);
380 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
382 StgArrWords_words(p) = payload_words;
383 StgArrWords_payload(p,0) = fptr;
384 StgArrWords_payload(p,1) = ptr;
385 StgArrWords_payload(p,2) = eptr;
386 StgArrWords_payload(p,3) = flag;
388 // We don't care about the value here.
389 // Should StgWeak_value(w) be stg_NO_FINALIZER_closure or something else?
391 StgWeak_key(w) = key;
392 StgWeak_value(w) = val;
393 StgWeak_finalizer(w) = stg_NO_FINALIZER_closure;
394 StgWeak_cfinalizer(w) = p;
396 StgWeak_link(w) = W_[weak_ptr_list];
397 W_[weak_ptr_list] = w;
399 IF_DEBUG(weak, foreign "C" debugBelch(stg_weak_msg,w) []);
413 if (GET_INFO(w) == stg_DEAD_WEAK_info) {
414 RET_NP(0,stg_NO_FINALIZER_closure);
420 // A weak pointer is inherently used, so we do not need to call
421 // LDV_recordDead_FILL_SLOP_DYNAMIC():
422 // LDV_recordDead_FILL_SLOP_DYNAMIC((StgClosure *)w);
423 // or, LDV_recordDead():
424 // LDV_recordDead((StgClosure *)w, sizeofW(StgWeak) - sizeofW(StgProfHeader));
425 // Furthermore, when PROFILING is turned on, dead weak pointers are exactly as
426 // large as weak pointers, so there is no need to fill the slop, either.
427 // See stg_DEAD_WEAK_info in StgMiscClosures.hc.
431 // Todo: maybe use SET_HDR() and remove LDV_recordCreate()?
433 SET_INFO(w,stg_DEAD_WEAK_info);
434 LDV_RECORD_CREATE(w);
436 f = StgWeak_finalizer(w);
437 arr = StgWeak_cfinalizer(w);
439 StgDeadWeak_link(w) = StgWeak_link(w);
441 if (arr != stg_NO_FINALIZER_closure) {
442 foreign "C" runCFinalizer(StgArrWords_payload(arr,0),
443 StgArrWords_payload(arr,1),
444 StgArrWords_payload(arr,2),
445 StgArrWords_payload(arr,3)) [];
448 /* return the finalizer */
449 if (f == stg_NO_FINALIZER_closure) {
450 RET_NP(0,stg_NO_FINALIZER_closure);
462 if (GET_INFO(w) == stg_WEAK_info) {
464 val = StgWeak_value(w);
472 /* -----------------------------------------------------------------------------
473 Arbitrary-precision Integer operations.
475 There are some assumptions in this code that mp_limb_t == W_. This is
476 the case for all the platforms that GHC supports, currently.
477 -------------------------------------------------------------------------- */
481 /* arguments: R1 = Int# */
483 W_ val, s, p; /* to avoid aliasing */
486 ALLOC_PRIM( SIZEOF_StgArrWords + WDS(1), NO_PTRS, int2Integerzh_fast );
488 p = Hp - SIZEOF_StgArrWords;
489 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
490 StgArrWords_words(p) = 1;
492 /* mpz_set_si is inlined here, makes things simpler */
505 /* returns (# size :: Int#,
514 /* arguments: R1 = Word# */
516 W_ val, s, p; /* to avoid aliasing */
520 ALLOC_PRIM( SIZEOF_StgArrWords + WDS(1), NO_PTRS, word2Integerzh_fast);
522 p = Hp - SIZEOF_StgArrWords;
523 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
524 StgArrWords_words(p) = 1;
533 /* returns (# size :: Int#,
534 data :: ByteArray# #)
541 * 'long long' primops for converting to/from Integers.
544 #ifdef SUPPORT_LONG_LONGS
546 int64ToIntegerzh_fast
548 /* arguments: L1 = Int64# */
551 W_ hi, lo, s, neg, words_needed, p;
556 hi = TO_W_(val >> 32);
559 if ( hi == 0 || (hi == 0xFFFFFFFF && lo != 0) ) {
560 // minimum is one word
566 ALLOC_PRIM( SIZEOF_StgArrWords + WDS(words_needed),
567 NO_PTRS, int64ToIntegerzh_fast );
569 p = Hp - SIZEOF_StgArrWords - WDS(words_needed) + WDS(1);
570 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
571 StgArrWords_words(p) = words_needed;
583 if ( words_needed == 2 ) {
591 } else /* val==0 */ {
599 /* returns (# size :: Int#,
600 data :: ByteArray# #)
604 word64ToIntegerzh_fast
606 /* arguments: L1 = Word64# */
609 W_ hi, lo, s, words_needed, p;
612 hi = TO_W_(val >> 32);
621 ALLOC_PRIM( SIZEOF_StgArrWords + WDS(words_needed),
622 NO_PTRS, word64ToIntegerzh_fast );
624 p = Hp - SIZEOF_StgArrWords - WDS(words_needed) + WDS(1);
625 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
626 StgArrWords_words(p) = words_needed;
636 } else /* val==0 */ {
641 /* returns (# size :: Int#,
642 data :: ByteArray# #)
649 #endif /* SUPPORT_LONG_LONGS */
651 /* ToDo: this is shockingly inefficient */
656 bits8 [SIZEOF_MP_INT];
661 bits8 [SIZEOF_MP_INT];
666 bits8 [SIZEOF_MP_INT];
671 bits8 [SIZEOF_MP_INT];
676 #define FETCH_MP_TEMP(X) \
678 X = BaseReg + (OFFSET_StgRegTable_r ## X);
680 #define FETCH_MP_TEMP(X) /* Nothing */
683 #define GMP_TAKE2_RET1(name,mp_fun) \
688 FETCH_MP_TEMP(mp_tmp1); \
689 FETCH_MP_TEMP(mp_tmp2); \
690 FETCH_MP_TEMP(mp_result1) \
691 FETCH_MP_TEMP(mp_result2); \
693 /* call doYouWantToGC() */ \
694 MAYBE_GC(R2_PTR & R4_PTR, name); \
701 MP_INT__mp_alloc(mp_tmp1) = W_TO_INT(StgArrWords_words(d1)); \
702 MP_INT__mp_size(mp_tmp1) = (s1); \
703 MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(d1); \
704 MP_INT__mp_alloc(mp_tmp2) = W_TO_INT(StgArrWords_words(d2)); \
705 MP_INT__mp_size(mp_tmp2) = (s2); \
706 MP_INT__mp_d(mp_tmp2) = BYTE_ARR_CTS(d2); \
708 foreign "C" __gmpz_init(mp_result1 "ptr") []; \
710 /* Perform the operation */ \
711 foreign "C" mp_fun(mp_result1 "ptr",mp_tmp1 "ptr",mp_tmp2 "ptr") []; \
713 RET_NP(TO_W_(MP_INT__mp_size(mp_result1)), \
714 MP_INT__mp_d(mp_result1) - SIZEOF_StgArrWords); \
717 #define GMP_TAKE1_RET1(name,mp_fun) \
722 FETCH_MP_TEMP(mp_tmp1); \
723 FETCH_MP_TEMP(mp_result1) \
725 /* call doYouWantToGC() */ \
726 MAYBE_GC(R2_PTR, name); \
731 MP_INT__mp_alloc(mp_tmp1) = W_TO_INT(StgArrWords_words(d1)); \
732 MP_INT__mp_size(mp_tmp1) = (s1); \
733 MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(d1); \
735 foreign "C" __gmpz_init(mp_result1 "ptr") []; \
737 /* Perform the operation */ \
738 foreign "C" mp_fun(mp_result1 "ptr",mp_tmp1 "ptr") []; \
740 RET_NP(TO_W_(MP_INT__mp_size(mp_result1)), \
741 MP_INT__mp_d(mp_result1) - SIZEOF_StgArrWords); \
744 #define GMP_TAKE2_RET2(name,mp_fun) \
749 FETCH_MP_TEMP(mp_tmp1); \
750 FETCH_MP_TEMP(mp_tmp2); \
751 FETCH_MP_TEMP(mp_result1) \
752 FETCH_MP_TEMP(mp_result2) \
754 /* call doYouWantToGC() */ \
755 MAYBE_GC(R2_PTR & R4_PTR, name); \
762 MP_INT__mp_alloc(mp_tmp1) = W_TO_INT(StgArrWords_words(d1)); \
763 MP_INT__mp_size(mp_tmp1) = (s1); \
764 MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(d1); \
765 MP_INT__mp_alloc(mp_tmp2) = W_TO_INT(StgArrWords_words(d2)); \
766 MP_INT__mp_size(mp_tmp2) = (s2); \
767 MP_INT__mp_d(mp_tmp2) = BYTE_ARR_CTS(d2); \
769 foreign "C" __gmpz_init(mp_result1 "ptr") []; \
770 foreign "C" __gmpz_init(mp_result2 "ptr") []; \
772 /* Perform the operation */ \
773 foreign "C" mp_fun(mp_result1 "ptr",mp_result2 "ptr",mp_tmp1 "ptr",mp_tmp2 "ptr") []; \
775 RET_NPNP(TO_W_(MP_INT__mp_size(mp_result1)), \
776 MP_INT__mp_d(mp_result1) - SIZEOF_StgArrWords, \
777 TO_W_(MP_INT__mp_size(mp_result2)), \
778 MP_INT__mp_d(mp_result2) - SIZEOF_StgArrWords); \
781 GMP_TAKE2_RET1(plusIntegerzh_fast, __gmpz_add)
782 GMP_TAKE2_RET1(minusIntegerzh_fast, __gmpz_sub)
783 GMP_TAKE2_RET1(timesIntegerzh_fast, __gmpz_mul)
784 GMP_TAKE2_RET1(gcdIntegerzh_fast, __gmpz_gcd)
785 GMP_TAKE2_RET1(quotIntegerzh_fast, __gmpz_tdiv_q)
786 GMP_TAKE2_RET1(remIntegerzh_fast, __gmpz_tdiv_r)
787 GMP_TAKE2_RET1(divExactIntegerzh_fast, __gmpz_divexact)
788 GMP_TAKE2_RET1(andIntegerzh_fast, __gmpz_and)
789 GMP_TAKE2_RET1(orIntegerzh_fast, __gmpz_ior)
790 GMP_TAKE2_RET1(xorIntegerzh_fast, __gmpz_xor)
791 GMP_TAKE1_RET1(complementIntegerzh_fast, __gmpz_com)
793 GMP_TAKE2_RET2(quotRemIntegerzh_fast, __gmpz_tdiv_qr)
794 GMP_TAKE2_RET2(divModIntegerzh_fast, __gmpz_fdiv_qr)
798 mp_tmp_w: W_; // NB. mp_tmp_w is really an here mp_limb_t
804 /* R1 = the first Int#; R2 = the second Int# */
806 FETCH_MP_TEMP(mp_tmp_w);
809 (r) = foreign "C" __gmpn_gcd_1(mp_tmp_w "ptr", 1, R2) [];
812 /* Result parked in R1, return via info-pointer at TOS */
813 jump %ENTRY_CODE(Sp(0));
819 /* R1 = s1; R2 = d1; R3 = the int */
821 (s1) = foreign "C" __gmpn_gcd_1( BYTE_ARR_CTS(R2) "ptr", R1, R3) [];
824 /* Result parked in R1, return via info-pointer at TOS */
825 jump %ENTRY_CODE(Sp(0));
831 /* R1 = s1; R2 = d1; R3 = the int */
832 W_ usize, vsize, v_digit, u_digit;
838 // paraphrased from __gmpz_cmp_si() in the GMP sources
839 if (%gt(v_digit,0)) {
842 if (%lt(v_digit,0)) {
848 if (usize != vsize) {
850 jump %ENTRY_CODE(Sp(0));
855 jump %ENTRY_CODE(Sp(0));
858 u_digit = W_[BYTE_ARR_CTS(R2)];
860 if (u_digit == v_digit) {
862 jump %ENTRY_CODE(Sp(0));
865 if (%gtu(u_digit,v_digit)) { // NB. unsigned: these are mp_limb_t's
871 jump %ENTRY_CODE(Sp(0));
876 /* R1 = s1; R2 = d1; R3 = s2; R4 = d2 */
877 W_ usize, vsize, size, up, vp;
880 // paraphrased from __gmpz_cmp() in the GMP sources
884 if (usize != vsize) {
886 jump %ENTRY_CODE(Sp(0));
891 jump %ENTRY_CODE(Sp(0));
894 if (%lt(usize,0)) { // NB. not <, which is unsigned
900 up = BYTE_ARR_CTS(R2);
901 vp = BYTE_ARR_CTS(R4);
903 (cmp) = foreign "C" __gmpn_cmp(up "ptr", vp "ptr", size) [];
905 if (cmp == 0 :: CInt) {
907 jump %ENTRY_CODE(Sp(0));
910 if (%lt(cmp,0 :: CInt) == %lt(usize,0)) {
915 /* Result parked in R1, return via info-pointer at TOS */
916 jump %ENTRY_CODE(Sp(0));
928 r = W_[R2 + SIZEOF_StgArrWords];
933 /* Result parked in R1, return via info-pointer at TOS */
935 jump %ENTRY_CODE(Sp(0));
947 r = W_[R2 + SIZEOF_StgArrWords];
952 /* Result parked in R1, return via info-pointer at TOS */
954 jump %ENTRY_CODE(Sp(0));
961 FETCH_MP_TEMP(mp_tmp1);
962 FETCH_MP_TEMP(mp_tmp_w);
964 /* arguments: F1 = Float# */
967 ALLOC_PRIM( SIZEOF_StgArrWords + WDS(1), NO_PTRS, decodeFloatzh_fast );
969 /* Be prepared to tell Lennart-coded __decodeFloat
970 where mantissa._mp_d can be put (it does not care about the rest) */
971 p = Hp - SIZEOF_StgArrWords;
972 SET_HDR(p,stg_ARR_WORDS_info,W_[CCCS]);
973 StgArrWords_words(p) = 1;
974 MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(p);
976 /* Perform the operation */
977 foreign "C" __decodeFloat(mp_tmp1 "ptr",mp_tmp_w "ptr" ,arg) [];
979 /* returns: (Int# (expn), Int#, ByteArray#) */
980 RET_NNP(W_[mp_tmp_w], TO_W_(MP_INT__mp_size(mp_tmp1)), p);
983 decodeFloatzuIntzh_fast
987 FETCH_MP_TEMP(mp_tmp1);
988 FETCH_MP_TEMP(mp_tmp_w);
990 /* arguments: F1 = Float# */
993 /* Perform the operation */
994 foreign "C" __decodeFloat_Int(mp_tmp1 "ptr", mp_tmp_w "ptr", arg) [];
996 /* returns: (Int# (mantissa), Int# (exponent)) */
997 RET_NN(W_[mp_tmp1], W_[mp_tmp_w]);
1000 #define DOUBLE_MANTISSA_SIZE SIZEOF_DOUBLE
1001 #define ARR_SIZE (SIZEOF_StgArrWords + DOUBLE_MANTISSA_SIZE)
1007 FETCH_MP_TEMP(mp_tmp1);
1008 FETCH_MP_TEMP(mp_tmp_w);
1010 /* arguments: D1 = Double# */
1013 ALLOC_PRIM( ARR_SIZE, NO_PTRS, decodeDoublezh_fast );
1015 /* Be prepared to tell Lennart-coded __decodeDouble
1016 where mantissa.d can be put (it does not care about the rest) */
1017 p = Hp - ARR_SIZE + WDS(1);
1018 SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]);
1019 StgArrWords_words(p) = BYTES_TO_WDS(DOUBLE_MANTISSA_SIZE);
1020 MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(p);
1022 /* Perform the operation */
1023 foreign "C" __decodeDouble(mp_tmp1 "ptr", mp_tmp_w "ptr",arg) [];
1025 /* returns: (Int# (expn), Int#, ByteArray#) */
1026 RET_NNP(W_[mp_tmp_w], TO_W_(MP_INT__mp_size(mp_tmp1)), p);
1029 decodeDoublezu2Intzh_fast
1033 FETCH_MP_TEMP(mp_tmp1);
1034 FETCH_MP_TEMP(mp_tmp2);
1035 FETCH_MP_TEMP(mp_result1);
1036 FETCH_MP_TEMP(mp_result2);
1038 /* arguments: D1 = Double# */
1041 /* Perform the operation */
1042 foreign "C" __decodeDouble_2Int(mp_tmp1 "ptr", mp_tmp2 "ptr",
1043 mp_result1 "ptr", mp_result2 "ptr",
1047 (Int# (mant sign), Word# (mant high), Word# (mant low), Int# (expn)) */
1048 RET_NNNN(W_[mp_tmp1], W_[mp_tmp2], W_[mp_result1], W_[mp_result2]);
1051 /* -----------------------------------------------------------------------------
1052 * Concurrency primitives
1053 * -------------------------------------------------------------------------- */
1057 /* args: R1 = closure to spark */
1059 MAYBE_GC(R1_PTR, forkzh_fast);
1065 ("ptr" threadid) = foreign "C" createIOThread( MyCapability() "ptr",
1066 RtsFlags_GcFlags_initialStkSize(RtsFlags),
1069 /* start blocked if the current thread is blocked */
1070 StgTSO_flags(threadid) =
1071 StgTSO_flags(threadid) | (StgTSO_flags(CurrentTSO) &
1072 (TSO_BLOCKEX::I32 | TSO_INTERRUPTIBLE::I32));
1074 foreign "C" scheduleThread(MyCapability() "ptr", threadid "ptr") [];
1076 // switch at the earliest opportunity
1077 Capability_context_switch(MyCapability()) = 1 :: CInt;
1084 /* args: R1 = cpu, R2 = closure to spark */
1086 MAYBE_GC(R2_PTR, forkOnzh_fast);
1094 ("ptr" threadid) = foreign "C" createIOThread( MyCapability() "ptr",
1095 RtsFlags_GcFlags_initialStkSize(RtsFlags),
1098 /* start blocked if the current thread is blocked */
1099 StgTSO_flags(threadid) =
1100 StgTSO_flags(threadid) | (StgTSO_flags(CurrentTSO) &
1101 (TSO_BLOCKEX::I32 | TSO_INTERRUPTIBLE::I32));
1103 foreign "C" scheduleThreadOn(MyCapability() "ptr", cpu, threadid "ptr") [];
1105 // switch at the earliest opportunity
1106 Capability_context_switch(MyCapability()) = 1 :: CInt;
1113 jump stg_yield_noregs;
1128 foreign "C" labelThread(R1 "ptr", R2 "ptr") [];
1130 jump %ENTRY_CODE(Sp(0));
1133 isCurrentThreadBoundzh_fast
1137 (r) = foreign "C" isThreadBound(CurrentTSO) [];
1143 /* args: R1 :: ThreadId# */
1151 if (TO_W_(StgTSO_what_next(tso)) == ThreadRelocated) {
1152 tso = StgTSO__link(tso);
1156 what_next = TO_W_(StgTSO_what_next(tso));
1157 why_blocked = TO_W_(StgTSO_why_blocked(tso));
1158 // Note: these two reads are not atomic, so they might end up
1159 // being inconsistent. It doesn't matter, since we
1160 // only return one or the other. If we wanted to return the
1161 // contents of block_info too, then we'd have to do some synchronisation.
1163 if (what_next == ThreadComplete) {
1164 ret = 16; // NB. magic, matches up with GHC.Conc.threadStatus
1166 if (what_next == ThreadKilled) {
1175 /* -----------------------------------------------------------------------------
1177 * -------------------------------------------------------------------------- */
1181 // Catch retry frame ------------------------------------------------------------
1183 INFO_TABLE_RET(stg_catch_retry_frame, CATCH_RETRY_FRAME,
1184 #if defined(PROFILING)
1185 W_ unused1, W_ unused2,
1187 W_ unused3, P_ unused4, P_ unused5)
1189 W_ r, frame, trec, outer;
1192 trec = StgTSO_trec(CurrentTSO);
1193 ("ptr" outer) = foreign "C" stmGetEnclosingTRec(trec "ptr") [];
1194 (r) = foreign "C" stmCommitNestedTransaction(MyCapability() "ptr", trec "ptr") [];
1196 /* Succeeded (either first branch or second branch) */
1197 StgTSO_trec(CurrentTSO) = outer;
1198 Sp = Sp + SIZEOF_StgCatchRetryFrame;
1199 jump %ENTRY_CODE(Sp(SP_OFF));
1201 /* Did not commit: re-execute */
1203 ("ptr" new_trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", outer "ptr") [];
1204 StgTSO_trec(CurrentTSO) = new_trec;
1205 if (StgCatchRetryFrame_running_alt_code(frame) != 0::I32) {
1206 R1 = StgCatchRetryFrame_alt_code(frame);
1208 R1 = StgCatchRetryFrame_first_code(frame);
1215 // Atomically frame ------------------------------------------------------------
1217 INFO_TABLE_RET(stg_atomically_frame, ATOMICALLY_FRAME,
1218 #if defined(PROFILING)
1219 W_ unused1, W_ unused2,
1221 P_ unused3, P_ unused4)
1223 W_ frame, trec, valid, next_invariant, q, outer;
1226 trec = StgTSO_trec(CurrentTSO);
1227 ("ptr" outer) = foreign "C" stmGetEnclosingTRec(trec "ptr") [];
1229 if (outer == NO_TREC) {
1230 /* First time back at the atomically frame -- pick up invariants */
1231 ("ptr" q) = foreign "C" stmGetInvariantsToCheck(MyCapability() "ptr", trec "ptr") [];
1232 StgAtomicallyFrame_next_invariant_to_check(frame) = q;
1235 /* Second/subsequent time back at the atomically frame -- abort the
1236 * tx that's checking the invariant and move on to the next one */
1237 StgTSO_trec(CurrentTSO) = outer;
1238 q = StgAtomicallyFrame_next_invariant_to_check(frame);
1239 StgInvariantCheckQueue_my_execution(q) = trec;
1240 foreign "C" stmAbortTransaction(MyCapability() "ptr", trec "ptr") [];
1241 /* Don't free trec -- it's linked from q and will be stashed in the
1242 * invariant if we eventually commit. */
1243 q = StgInvariantCheckQueue_next_queue_entry(q);
1244 StgAtomicallyFrame_next_invariant_to_check(frame) = q;
1248 q = StgAtomicallyFrame_next_invariant_to_check(frame);
1250 if (q != END_INVARIANT_CHECK_QUEUE) {
1251 /* We can't commit yet: another invariant to check */
1252 ("ptr" trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", trec "ptr") [];
1253 StgTSO_trec(CurrentTSO) = trec;
1255 next_invariant = StgInvariantCheckQueue_invariant(q);
1256 R1 = StgAtomicInvariant_code(next_invariant);
1261 /* We've got no more invariants to check, try to commit */
1262 (valid) = foreign "C" stmCommitTransaction(MyCapability() "ptr", trec "ptr") [];
1264 /* Transaction was valid: commit succeeded */
1265 StgTSO_trec(CurrentTSO) = NO_TREC;
1266 Sp = Sp + SIZEOF_StgAtomicallyFrame;
1267 jump %ENTRY_CODE(Sp(SP_OFF));
1269 /* Transaction was not valid: try again */
1270 ("ptr" trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", NO_TREC "ptr") [];
1271 StgTSO_trec(CurrentTSO) = trec;
1272 StgAtomicallyFrame_next_invariant_to_check(frame) = END_INVARIANT_CHECK_QUEUE;
1273 R1 = StgAtomicallyFrame_code(frame);
1279 INFO_TABLE_RET(stg_atomically_waiting_frame, ATOMICALLY_FRAME,
1280 #if defined(PROFILING)
1281 W_ unused1, W_ unused2,
1283 P_ unused3, P_ unused4)
1285 W_ frame, trec, valid;
1289 /* The TSO is currently waiting: should we stop waiting? */
1290 (valid) = foreign "C" stmReWait(MyCapability() "ptr", CurrentTSO "ptr") [];
1292 /* Previous attempt is still valid: no point trying again yet */
1293 jump stg_block_noregs;
1295 /* Previous attempt is no longer valid: try again */
1296 ("ptr" trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", NO_TREC "ptr") [];
1297 StgTSO_trec(CurrentTSO) = trec;
1298 StgHeader_info(frame) = stg_atomically_frame_info;
1299 R1 = StgAtomicallyFrame_code(frame);
1304 // STM catch frame --------------------------------------------------------------
1308 /* Catch frames are very similar to update frames, but when entering
1309 * one we just pop the frame off the stack and perform the correct
1310 * kind of return to the activation record underneath us on the stack.
1313 INFO_TABLE_RET(stg_catch_stm_frame, CATCH_STM_FRAME,
1314 #if defined(PROFILING)
1315 W_ unused1, W_ unused2,
1317 P_ unused3, P_ unused4)
1319 W_ r, frame, trec, outer;
1321 trec = StgTSO_trec(CurrentTSO);
1322 ("ptr" outer) = foreign "C" stmGetEnclosingTRec(trec "ptr") [];
1323 (r) = foreign "C" stmCommitNestedTransaction(MyCapability() "ptr", trec "ptr") [];
1325 /* Commit succeeded */
1326 StgTSO_trec(CurrentTSO) = outer;
1327 Sp = Sp + SIZEOF_StgCatchSTMFrame;
1332 ("ptr" new_trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", outer "ptr") [];
1333 StgTSO_trec(CurrentTSO) = new_trec;
1334 R1 = StgCatchSTMFrame_code(frame);
1340 // Primop definition ------------------------------------------------------------
1348 // stmStartTransaction may allocate
1349 MAYBE_GC (R1_PTR, atomicallyzh_fast);
1351 /* Args: R1 = m :: STM a */
1352 STK_CHK_GEN(SIZEOF_StgAtomicallyFrame + WDS(1), R1_PTR, atomicallyzh_fast);
1354 old_trec = StgTSO_trec(CurrentTSO);
1356 /* Nested transactions are not allowed; raise an exception */
1357 if (old_trec != NO_TREC) {
1358 R1 = base_ControlziExceptionziBase_nestedAtomically_closure;
1362 /* Set up the atomically frame */
1363 Sp = Sp - SIZEOF_StgAtomicallyFrame;
1366 SET_HDR(frame,stg_atomically_frame_info, W_[CCCS]);
1367 StgAtomicallyFrame_code(frame) = R1;
1368 StgAtomicallyFrame_next_invariant_to_check(frame) = END_INVARIANT_CHECK_QUEUE;
1370 /* Start the memory transcation */
1371 ("ptr" new_trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", old_trec "ptr") [R1];
1372 StgTSO_trec(CurrentTSO) = new_trec;
1374 /* Apply R1 to the realworld token */
1383 /* Args: R1 :: STM a */
1384 /* Args: R2 :: Exception -> STM a */
1385 STK_CHK_GEN(SIZEOF_StgCatchSTMFrame + WDS(1), R1_PTR & R2_PTR, catchSTMzh_fast);
1387 /* Set up the catch frame */
1388 Sp = Sp - SIZEOF_StgCatchSTMFrame;
1391 SET_HDR(frame, stg_catch_stm_frame_info, W_[CCCS]);
1392 StgCatchSTMFrame_handler(frame) = R2;
1393 StgCatchSTMFrame_code(frame) = R1;
1395 /* Start a nested transaction to run the body of the try block in */
1398 cur_trec = StgTSO_trec(CurrentTSO);
1399 ("ptr" new_trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", cur_trec "ptr");
1400 StgTSO_trec(CurrentTSO) = new_trec;
1402 /* Apply R1 to the realworld token */
1413 // stmStartTransaction may allocate
1414 MAYBE_GC (R1_PTR & R2_PTR, catchRetryzh_fast);
1416 /* Args: R1 :: STM a */
1417 /* Args: R2 :: STM a */
1418 STK_CHK_GEN(SIZEOF_StgCatchRetryFrame + WDS(1), R1_PTR & R2_PTR, catchRetryzh_fast);
1420 /* Start a nested transaction within which to run the first code */
1421 trec = StgTSO_trec(CurrentTSO);
1422 ("ptr" new_trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", trec "ptr") [R1,R2];
1423 StgTSO_trec(CurrentTSO) = new_trec;
1425 /* Set up the catch-retry frame */
1426 Sp = Sp - SIZEOF_StgCatchRetryFrame;
1429 SET_HDR(frame, stg_catch_retry_frame_info, W_[CCCS]);
1430 StgCatchRetryFrame_running_alt_code(frame) = 0 :: CInt; // false;
1431 StgCatchRetryFrame_first_code(frame) = R1;
1432 StgCatchRetryFrame_alt_code(frame) = R2;
1434 /* Apply R1 to the realworld token */
1447 MAYBE_GC (NO_PTRS, retryzh_fast); // STM operations may allocate
1449 // Find the enclosing ATOMICALLY_FRAME or CATCH_RETRY_FRAME
1451 StgTSO_sp(CurrentTSO) = Sp;
1452 (frame_type) = foreign "C" findRetryFrameHelper(CurrentTSO "ptr") [];
1453 Sp = StgTSO_sp(CurrentTSO);
1455 trec = StgTSO_trec(CurrentTSO);
1456 ("ptr" outer) = foreign "C" stmGetEnclosingTRec(trec "ptr") [];
1458 if (frame_type == CATCH_RETRY_FRAME) {
1459 // The retry reaches a CATCH_RETRY_FRAME before the atomic frame
1460 ASSERT(outer != NO_TREC);
1461 // Abort the transaction attempting the current branch
1462 foreign "C" stmAbortTransaction(MyCapability() "ptr", trec "ptr") [];
1463 foreign "C" stmFreeAbortedTRec(MyCapability() "ptr", trec "ptr") [];
1464 if (!StgCatchRetryFrame_running_alt_code(frame) != 0::I32) {
1465 // Retry in the first branch: try the alternative
1466 ("ptr" trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", outer "ptr") [];
1467 StgTSO_trec(CurrentTSO) = trec;
1468 StgCatchRetryFrame_running_alt_code(frame) = 1 :: CInt; // true;
1469 R1 = StgCatchRetryFrame_alt_code(frame);
1472 // Retry in the alternative code: propagate the retry
1473 StgTSO_trec(CurrentTSO) = outer;
1474 Sp = Sp + SIZEOF_StgCatchRetryFrame;
1475 goto retry_pop_stack;
1479 // We've reached the ATOMICALLY_FRAME: attempt to wait
1480 ASSERT(frame_type == ATOMICALLY_FRAME);
1481 if (outer != NO_TREC) {
1482 // We called retry while checking invariants, so abort the current
1483 // invariant check (merging its TVar accesses into the parents read
1484 // set so we'll wait on them)
1485 foreign "C" stmAbortTransaction(MyCapability() "ptr", trec "ptr") [];
1486 foreign "C" stmFreeAbortedTRec(MyCapability() "ptr", trec "ptr") [];
1488 StgTSO_trec(CurrentTSO) = trec;
1489 ("ptr" outer) = foreign "C" stmGetEnclosingTRec(trec "ptr") [];
1491 ASSERT(outer == NO_TREC);
1493 (r) = foreign "C" stmWait(MyCapability() "ptr", CurrentTSO "ptr", trec "ptr") [];
1495 // Transaction was valid: stmWait put us on the TVars' queues, we now block
1496 StgHeader_info(frame) = stg_atomically_waiting_frame_info;
1498 // Fix up the stack in the unregisterised case: the return convention is different.
1499 R3 = trec; // passing to stmWaitUnblock()
1500 jump stg_block_stmwait;
1502 // Transaction was not valid: retry immediately
1503 ("ptr" trec) = foreign "C" stmStartTransaction(MyCapability() "ptr", outer "ptr") [];
1504 StgTSO_trec(CurrentTSO) = trec;
1505 R1 = StgAtomicallyFrame_code(frame);
1516 /* Args: R1 = invariant closure */
1517 MAYBE_GC (R1_PTR, checkzh_fast);
1519 trec = StgTSO_trec(CurrentTSO);
1521 foreign "C" stmAddInvariantToCheck(MyCapability() "ptr",
1525 jump %ENTRY_CODE(Sp(0));
1534 /* Args: R1 = initialisation value */
1536 MAYBE_GC (R1_PTR, newTVarzh_fast);
1538 ("ptr" tv) = foreign "C" stmNewTVar(MyCapability() "ptr", new_value "ptr") [];
1549 /* Args: R1 = TVar closure */
1551 MAYBE_GC (R1_PTR, readTVarzh_fast); // Call to stmReadTVar may allocate
1552 trec = StgTSO_trec(CurrentTSO);
1554 ("ptr" result) = foreign "C" stmReadTVar(MyCapability() "ptr", trec "ptr", tvar "ptr") [];
1564 result = StgTVar_current_value(R1);
1565 if (%INFO_PTR(result) == stg_TREC_HEADER_info) {
1577 /* Args: R1 = TVar closure */
1578 /* R2 = New value */
1580 MAYBE_GC (R1_PTR & R2_PTR, writeTVarzh_fast); // Call to stmWriteTVar may allocate
1581 trec = StgTSO_trec(CurrentTSO);
1584 foreign "C" stmWriteTVar(MyCapability() "ptr", trec "ptr", tvar "ptr", new_value "ptr") [];
1586 jump %ENTRY_CODE(Sp(0));
1590 /* -----------------------------------------------------------------------------
1593 * take & putMVar work as follows. Firstly, an important invariant:
1595 * If the MVar is full, then the blocking queue contains only
1596 * threads blocked on putMVar, and if the MVar is empty then the
1597 * blocking queue contains only threads blocked on takeMVar.
1600 * MVar empty : then add ourselves to the blocking queue
1601 * MVar full : remove the value from the MVar, and
1602 * blocking queue empty : return
1603 * blocking queue non-empty : perform the first blocked putMVar
1604 * from the queue, and wake up the
1605 * thread (MVar is now full again)
1607 * putMVar is just the dual of the above algorithm.
1609 * How do we "perform a putMVar"? Well, we have to fiddle around with
1610 * the stack of the thread waiting to do the putMVar. See
1611 * stg_block_putmvar and stg_block_takemvar in HeapStackCheck.c for
1612 * the stack layout, and the PerformPut and PerformTake macros below.
1614 * It is important that a blocked take or put is woken up with the
1615 * take/put already performed, because otherwise there would be a
1616 * small window of vulnerability where the thread could receive an
1617 * exception and never perform its take or put, and we'd end up with a
1620 * -------------------------------------------------------------------------- */
1624 /* args: R1 = MVar closure */
1626 if (StgMVar_value(R1) == stg_END_TSO_QUEUE_closure) {
1638 ALLOC_PRIM ( SIZEOF_StgMVar, NO_PTRS, newMVarzh_fast );
1640 mvar = Hp - SIZEOF_StgMVar + WDS(1);
1641 SET_HDR(mvar,stg_MVAR_DIRTY_info,W_[CCCS]);
1642 // MVARs start dirty: generation 0 has no mutable list
1643 StgMVar_head(mvar) = stg_END_TSO_QUEUE_closure;
1644 StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
1645 StgMVar_value(mvar) = stg_END_TSO_QUEUE_closure;
1650 #define PerformTake(tso, value) \
1651 W_[StgTSO_sp(tso) + WDS(1)] = value; \
1652 W_[StgTSO_sp(tso) + WDS(0)] = stg_gc_unpt_r1_info;
1654 #define PerformPut(tso,lval) \
1655 StgTSO_sp(tso) = StgTSO_sp(tso) + WDS(3); \
1656 lval = W_[StgTSO_sp(tso) - WDS(1)];
1660 W_ mvar, val, info, tso;
1662 /* args: R1 = MVar closure */
1665 #if defined(THREADED_RTS)
1666 ("ptr" info) = foreign "C" lockClosure(mvar "ptr") [];
1668 info = GET_INFO(mvar);
1671 if (info == stg_MVAR_CLEAN_info) {
1672 foreign "C" dirty_MVAR(BaseReg "ptr", mvar "ptr") [];
1675 /* If the MVar is empty, put ourselves on its blocking queue,
1676 * and wait until we're woken up.
1678 if (StgMVar_value(mvar) == stg_END_TSO_QUEUE_closure) {
1679 if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
1680 StgMVar_head(mvar) = CurrentTSO;
1682 foreign "C" setTSOLink(MyCapability() "ptr",
1683 StgMVar_tail(mvar) "ptr",
1686 StgTSO__link(CurrentTSO) = stg_END_TSO_QUEUE_closure;
1687 StgTSO_block_info(CurrentTSO) = mvar;
1688 // write barrier for throwTo(), which looks at block_info
1689 // if why_blocked==BlockedOnMVar.
1690 prim %write_barrier() [];
1691 StgTSO_why_blocked(CurrentTSO) = BlockedOnMVar::I16;
1692 StgMVar_tail(mvar) = CurrentTSO;
1695 jump stg_block_takemvar;
1698 /* we got the value... */
1699 val = StgMVar_value(mvar);
1701 if (StgMVar_head(mvar) != stg_END_TSO_QUEUE_closure)
1703 /* There are putMVar(s) waiting...
1704 * wake up the first thread on the queue
1706 ASSERT(StgTSO_why_blocked(StgMVar_head(mvar)) == BlockedOnMVar::I16);
1708 /* actually perform the putMVar for the thread that we just woke up */
1709 tso = StgMVar_head(mvar);
1710 PerformPut(tso,StgMVar_value(mvar));
1712 if (TO_W_(StgTSO_flags(tso)) & TSO_DIRTY == 0) {
1713 foreign "C" dirty_TSO(MyCapability() "ptr", tso "ptr") [];
1716 ("ptr" tso) = foreign "C" unblockOne_(MyCapability() "ptr",
1717 StgMVar_head(mvar) "ptr", 1) [];
1718 StgMVar_head(mvar) = tso;
1720 if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
1721 StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
1724 #if defined(THREADED_RTS)
1725 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1727 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1733 /* No further putMVars, MVar is now empty */
1734 StgMVar_value(mvar) = stg_END_TSO_QUEUE_closure;
1736 #if defined(THREADED_RTS)
1737 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1739 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1749 W_ mvar, val, info, tso;
1751 /* args: R1 = MVar closure */
1755 #if defined(THREADED_RTS)
1756 ("ptr" info) = foreign "C" lockClosure(mvar "ptr") [];
1758 info = GET_INFO(mvar);
1761 if (StgMVar_value(mvar) == stg_END_TSO_QUEUE_closure) {
1762 #if defined(THREADED_RTS)
1763 unlockClosure(mvar, info);
1765 /* HACK: we need a pointer to pass back,
1766 * so we abuse NO_FINALIZER_closure
1768 RET_NP(0, stg_NO_FINALIZER_closure);
1771 if (info == stg_MVAR_CLEAN_info) {
1772 foreign "C" dirty_MVAR(BaseReg "ptr", mvar "ptr");
1775 /* we got the value... */
1776 val = StgMVar_value(mvar);
1778 if (StgMVar_head(mvar) != stg_END_TSO_QUEUE_closure) {
1780 /* There are putMVar(s) waiting...
1781 * wake up the first thread on the queue
1783 ASSERT(StgTSO_why_blocked(StgMVar_head(mvar)) == BlockedOnMVar::I16);
1785 /* actually perform the putMVar for the thread that we just woke up */
1786 tso = StgMVar_head(mvar);
1787 PerformPut(tso,StgMVar_value(mvar));
1788 if (TO_W_(StgTSO_flags(tso)) & TSO_DIRTY == 0) {
1789 foreign "C" dirty_TSO(MyCapability() "ptr", tso "ptr") [];
1792 ("ptr" tso) = foreign "C" unblockOne_(MyCapability() "ptr",
1793 StgMVar_head(mvar) "ptr", 1) [];
1794 StgMVar_head(mvar) = tso;
1796 if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
1797 StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
1799 #if defined(THREADED_RTS)
1800 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1802 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1807 /* No further putMVars, MVar is now empty */
1808 StgMVar_value(mvar) = stg_END_TSO_QUEUE_closure;
1809 #if defined(THREADED_RTS)
1810 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1812 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1822 W_ mvar, val, info, tso;
1824 /* args: R1 = MVar, R2 = value */
1828 #if defined(THREADED_RTS)
1829 ("ptr" info) = foreign "C" lockClosure(mvar "ptr") [];
1831 info = GET_INFO(mvar);
1834 if (info == stg_MVAR_CLEAN_info) {
1835 foreign "C" dirty_MVAR(BaseReg "ptr", mvar "ptr");
1838 if (StgMVar_value(mvar) != stg_END_TSO_QUEUE_closure) {
1839 if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
1840 StgMVar_head(mvar) = CurrentTSO;
1842 foreign "C" setTSOLink(MyCapability() "ptr",
1843 StgMVar_tail(mvar) "ptr",
1846 StgTSO__link(CurrentTSO) = stg_END_TSO_QUEUE_closure;
1847 StgTSO_block_info(CurrentTSO) = mvar;
1848 // write barrier for throwTo(), which looks at block_info
1849 // if why_blocked==BlockedOnMVar.
1850 prim %write_barrier() [];
1851 StgTSO_why_blocked(CurrentTSO) = BlockedOnMVar::I16;
1852 StgMVar_tail(mvar) = CurrentTSO;
1856 jump stg_block_putmvar;
1859 if (StgMVar_head(mvar) != stg_END_TSO_QUEUE_closure) {
1861 /* There are takeMVar(s) waiting: wake up the first one
1863 ASSERT(StgTSO_why_blocked(StgMVar_head(mvar)) == BlockedOnMVar::I16);
1865 /* actually perform the takeMVar */
1866 tso = StgMVar_head(mvar);
1867 PerformTake(tso, val);
1868 if (TO_W_(StgTSO_flags(tso)) & TSO_DIRTY == 0) {
1869 foreign "C" dirty_TSO(MyCapability() "ptr", tso "ptr") [];
1872 ("ptr" tso) = foreign "C" unblockOne_(MyCapability() "ptr",
1873 StgMVar_head(mvar) "ptr", 1) [];
1874 StgMVar_head(mvar) = tso;
1876 if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
1877 StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
1880 #if defined(THREADED_RTS)
1881 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1883 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1885 jump %ENTRY_CODE(Sp(0));
1889 /* No further takes, the MVar is now full. */
1890 StgMVar_value(mvar) = val;
1892 #if defined(THREADED_RTS)
1893 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1895 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1897 jump %ENTRY_CODE(Sp(0));
1900 /* ToDo: yield afterward for better communication performance? */
1908 /* args: R1 = MVar, R2 = value */
1911 #if defined(THREADED_RTS)
1912 ("ptr" info) = foreign "C" lockClosure(mvar "ptr") [R2];
1914 info = GET_INFO(mvar);
1917 if (StgMVar_value(mvar) != stg_END_TSO_QUEUE_closure) {
1918 #if defined(THREADED_RTS)
1919 unlockClosure(mvar, info);
1924 if (info == stg_MVAR_CLEAN_info) {
1925 foreign "C" dirty_MVAR(BaseReg "ptr", mvar "ptr");
1928 if (StgMVar_head(mvar) != stg_END_TSO_QUEUE_closure) {
1930 /* There are takeMVar(s) waiting: wake up the first one
1932 ASSERT(StgTSO_why_blocked(StgMVar_head(mvar)) == BlockedOnMVar::I16);
1934 /* actually perform the takeMVar */
1935 tso = StgMVar_head(mvar);
1936 PerformTake(tso, R2);
1937 if (TO_W_(StgTSO_flags(tso)) & TSO_DIRTY == 0) {
1938 foreign "C" dirty_TSO(MyCapability() "ptr", tso "ptr") [];
1941 ("ptr" tso) = foreign "C" unblockOne_(MyCapability() "ptr",
1942 StgMVar_head(mvar) "ptr", 1) [];
1943 StgMVar_head(mvar) = tso;
1945 if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
1946 StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
1949 #if defined(THREADED_RTS)
1950 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1952 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1957 /* No further takes, the MVar is now full. */
1958 StgMVar_value(mvar) = R2;
1960 #if defined(THREADED_RTS)
1961 unlockClosure(mvar, stg_MVAR_DIRTY_info);
1963 SET_INFO(mvar,stg_MVAR_DIRTY_info);
1968 /* ToDo: yield afterward for better communication performance? */
1972 /* -----------------------------------------------------------------------------
1973 Stable pointer primitives
1974 ------------------------------------------------------------------------- */
1976 makeStableNamezh_fast
1980 ALLOC_PRIM( SIZEOF_StgStableName, R1_PTR, makeStableNamezh_fast );
1982 (index) = foreign "C" lookupStableName(R1 "ptr") [];
1984 /* Is there already a StableName for this heap object?
1985 * stable_ptr_table is a pointer to an array of snEntry structs.
1987 if ( snEntry_sn_obj(W_[stable_ptr_table] + index*SIZEOF_snEntry) == NULL ) {
1988 sn_obj = Hp - SIZEOF_StgStableName + WDS(1);
1989 SET_HDR(sn_obj, stg_STABLE_NAME_info, W_[CCCS]);
1990 StgStableName_sn(sn_obj) = index;
1991 snEntry_sn_obj(W_[stable_ptr_table] + index*SIZEOF_snEntry) = sn_obj;
1993 sn_obj = snEntry_sn_obj(W_[stable_ptr_table] + index*SIZEOF_snEntry);
2000 makeStablePtrzh_fast
2004 MAYBE_GC(R1_PTR, makeStablePtrzh_fast);
2005 ("ptr" sp) = foreign "C" getStablePtr(R1 "ptr") [];
2009 deRefStablePtrzh_fast
2011 /* Args: R1 = the stable ptr */
2014 r = snEntry_addr(W_[stable_ptr_table] + sp*SIZEOF_snEntry);
2018 /* -----------------------------------------------------------------------------
2019 Bytecode object primitives
2020 ------------------------------------------------------------------------- */
2030 W_ bco, bitmap_arr, bytes, words;
2034 words = BYTES_TO_WDS(SIZEOF_StgBCO) + StgArrWords_words(bitmap_arr);
2037 ALLOC_PRIM( bytes, R1_PTR&R2_PTR&R3_PTR&R5_PTR, newBCOzh_fast );
2039 bco = Hp - bytes + WDS(1);
2040 SET_HDR(bco, stg_BCO_info, W_[CCCS]);
2042 StgBCO_instrs(bco) = R1;
2043 StgBCO_literals(bco) = R2;
2044 StgBCO_ptrs(bco) = R3;
2045 StgBCO_arity(bco) = HALF_W_(R4);
2046 StgBCO_size(bco) = HALF_W_(words);
2048 // Copy the arity/bitmap info into the BCO
2052 if (i < StgArrWords_words(bitmap_arr)) {
2053 StgBCO_bitmap(bco,i) = StgArrWords_payload(bitmap_arr,i);
2064 // R1 = the BCO# for the AP
2068 // This function is *only* used to wrap zero-arity BCOs in an
2069 // updatable wrapper (see ByteCodeLink.lhs). An AP thunk is always
2070 // saturated and always points directly to a FUN or BCO.
2071 ASSERT(%INFO_TYPE(%GET_STD_INFO(R1)) == HALF_W_(BCO) &&
2072 StgBCO_arity(R1) == HALF_W_(0));
2074 HP_CHK_GEN_TICKY(SIZEOF_StgAP, R1_PTR, mkApUpd0zh_fast);
2075 TICK_ALLOC_UP_THK(0, 0);
2076 CCCS_ALLOC(SIZEOF_StgAP);
2078 ap = Hp - SIZEOF_StgAP + WDS(1);
2079 SET_HDR(ap, stg_AP_info, W_[CCCS]);
2081 StgAP_n_args(ap) = HALF_W_(0);
2087 unpackClosurezh_fast
2089 /* args: R1 = closure to analyze */
2090 // TODO: Consider the absence of ptrs or nonptrs as a special case ?
2092 W_ info, ptrs, nptrs, p, ptrs_arr, nptrs_arr;
2093 info = %GET_STD_INFO(UNTAG(R1));
2095 // Some closures have non-standard layout, so we omit those here.
2097 type = TO_W_(%INFO_TYPE(info));
2098 switch [0 .. N_CLOSURE_TYPES] type {
2099 case THUNK_SELECTOR : {
2104 case THUNK, THUNK_1_0, THUNK_0_1, THUNK_2_0, THUNK_1_1,
2105 THUNK_0_2, THUNK_STATIC, AP, PAP, AP_STACK, BCO : {
2111 ptrs = TO_W_(%INFO_PTRS(info));
2112 nptrs = TO_W_(%INFO_NPTRS(info));
2117 W_ ptrs_arr_sz, nptrs_arr_sz;
2118 nptrs_arr_sz = SIZEOF_StgArrWords + WDS(nptrs);
2119 ptrs_arr_sz = SIZEOF_StgMutArrPtrs + WDS(ptrs);
2121 ALLOC_PRIM (ptrs_arr_sz + nptrs_arr_sz, R1_PTR, unpackClosurezh_fast);
2126 ptrs_arr = Hp - nptrs_arr_sz - ptrs_arr_sz + WDS(1);
2127 nptrs_arr = Hp - nptrs_arr_sz + WDS(1);
2129 SET_HDR(ptrs_arr, stg_MUT_ARR_PTRS_FROZEN_info, W_[CCCS]);
2130 StgMutArrPtrs_ptrs(ptrs_arr) = ptrs;
2134 W_[ptrs_arr + SIZEOF_StgMutArrPtrs + WDS(p)] = StgClosure_payload(clos,p);
2139 SET_HDR(nptrs_arr, stg_ARR_WORDS_info, W_[CCCS]);
2140 StgArrWords_words(nptrs_arr) = nptrs;
2144 W_[BYTE_ARR_CTS(nptrs_arr) + WDS(p)] = StgClosure_payload(clos, p+ptrs);
2148 RET_NPP(info, ptrs_arr, nptrs_arr);
2151 /* -----------------------------------------------------------------------------
2152 Thread I/O blocking primitives
2153 -------------------------------------------------------------------------- */
2155 /* Add a thread to the end of the blocked queue. (C-- version of the C
2156 * macro in Schedule.h).
2158 #define APPEND_TO_BLOCKED_QUEUE(tso) \
2159 ASSERT(StgTSO__link(tso) == END_TSO_QUEUE); \
2160 if (W_[blocked_queue_hd] == END_TSO_QUEUE) { \
2161 W_[blocked_queue_hd] = tso; \
2163 foreign "C" setTSOLink(MyCapability() "ptr", W_[blocked_queue_tl] "ptr", tso) []; \
2165 W_[blocked_queue_tl] = tso;
2171 foreign "C" barf("waitRead# on threaded RTS") never returns;
2174 ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
2175 StgTSO_why_blocked(CurrentTSO) = BlockedOnRead::I16;
2176 StgTSO_block_info(CurrentTSO) = R1;
2177 // No locking - we're not going to use this interface in the
2178 // threaded RTS anyway.
2179 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
2180 jump stg_block_noregs;
2188 foreign "C" barf("waitWrite# on threaded RTS") never returns;
2191 ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
2192 StgTSO_why_blocked(CurrentTSO) = BlockedOnWrite::I16;
2193 StgTSO_block_info(CurrentTSO) = R1;
2194 // No locking - we're not going to use this interface in the
2195 // threaded RTS anyway.
2196 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
2197 jump stg_block_noregs;
2202 STRING(stg_delayzh_malloc_str, "delayzh_fast")
2205 #ifdef mingw32_HOST_OS
2213 foreign "C" barf("delay# on threaded RTS") never returns;
2216 /* args: R1 (microsecond delay amount) */
2217 ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
2218 StgTSO_why_blocked(CurrentTSO) = BlockedOnDelay::I16;
2220 #ifdef mingw32_HOST_OS
2222 /* could probably allocate this on the heap instead */
2223 ("ptr" ares) = foreign "C" stgMallocBytes(SIZEOF_StgAsyncIOResult,
2224 stg_delayzh_malloc_str);
2225 (reqID) = foreign "C" addDelayRequest(R1);
2226 StgAsyncIOResult_reqID(ares) = reqID;
2227 StgAsyncIOResult_len(ares) = 0;
2228 StgAsyncIOResult_errCode(ares) = 0;
2229 StgTSO_block_info(CurrentTSO) = ares;
2231 /* Having all async-blocked threads reside on the blocked_queue
2232 * simplifies matters, so change the status to OnDoProc put the
2233 * delayed thread on the blocked_queue.
2235 StgTSO_why_blocked(CurrentTSO) = BlockedOnDoProc::I16;
2236 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
2237 jump stg_block_async_void;
2243 (time) = foreign "C" getourtimeofday() [R1];
2244 divisor = TO_W_(RtsFlags_MiscFlags_tickInterval(RtsFlags));
2248 divisor = divisor * 1000;
2249 target = ((R1 + divisor - 1) / divisor) /* divide rounding up */
2250 + time + 1; /* Add 1 as getourtimeofday rounds down */
2251 StgTSO_block_info(CurrentTSO) = target;
2253 /* Insert the new thread in the sleeping queue. */
2255 t = W_[sleeping_queue];
2257 if (t != END_TSO_QUEUE && StgTSO_block_info(t) < target) {
2259 t = StgTSO__link(t);
2263 StgTSO__link(CurrentTSO) = t;
2265 W_[sleeping_queue] = CurrentTSO;
2267 foreign "C" setTSOLink(MyCapability() "ptr", prev "ptr", CurrentTSO) [];
2269 jump stg_block_noregs;
2271 #endif /* !THREADED_RTS */
2275 #ifdef mingw32_HOST_OS
2276 STRING(stg_asyncReadzh_malloc_str, "asyncReadzh_fast")
2283 foreign "C" barf("asyncRead# on threaded RTS") never returns;
2286 /* args: R1 = fd, R2 = isSock, R3 = len, R4 = buf */
2287 ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
2288 StgTSO_why_blocked(CurrentTSO) = BlockedOnRead::I16;
2290 /* could probably allocate this on the heap instead */
2291 ("ptr" ares) = foreign "C" stgMallocBytes(SIZEOF_StgAsyncIOResult,
2292 stg_asyncReadzh_malloc_str)
2294 (reqID) = foreign "C" addIORequest(R1, 0/*FALSE*/,R2,R3,R4 "ptr") [];
2295 StgAsyncIOResult_reqID(ares) = reqID;
2296 StgAsyncIOResult_len(ares) = 0;
2297 StgAsyncIOResult_errCode(ares) = 0;
2298 StgTSO_block_info(CurrentTSO) = ares;
2299 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
2300 jump stg_block_async;
2304 STRING(stg_asyncWritezh_malloc_str, "asyncWritezh_fast")
2311 foreign "C" barf("asyncWrite# on threaded RTS") never returns;
2314 /* args: R1 = fd, R2 = isSock, R3 = len, R4 = buf */
2315 ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
2316 StgTSO_why_blocked(CurrentTSO) = BlockedOnWrite::I16;
2318 ("ptr" ares) = foreign "C" stgMallocBytes(SIZEOF_StgAsyncIOResult,
2319 stg_asyncWritezh_malloc_str)
2321 (reqID) = foreign "C" addIORequest(R1, 1/*TRUE*/,R2,R3,R4 "ptr") [];
2323 StgAsyncIOResult_reqID(ares) = reqID;
2324 StgAsyncIOResult_len(ares) = 0;
2325 StgAsyncIOResult_errCode(ares) = 0;
2326 StgTSO_block_info(CurrentTSO) = ares;
2327 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
2328 jump stg_block_async;
2332 STRING(stg_asyncDoProczh_malloc_str, "asyncDoProczh_fast")
2339 foreign "C" barf("asyncDoProc# on threaded RTS") never returns;
2342 /* args: R1 = proc, R2 = param */
2343 ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
2344 StgTSO_why_blocked(CurrentTSO) = BlockedOnDoProc::I16;
2346 /* could probably allocate this on the heap instead */
2347 ("ptr" ares) = foreign "C" stgMallocBytes(SIZEOF_StgAsyncIOResult,
2348 stg_asyncDoProczh_malloc_str)
2350 (reqID) = foreign "C" addDoProcRequest(R1 "ptr",R2 "ptr") [];
2351 StgAsyncIOResult_reqID(ares) = reqID;
2352 StgAsyncIOResult_len(ares) = 0;
2353 StgAsyncIOResult_errCode(ares) = 0;
2354 StgTSO_block_info(CurrentTSO) = ares;
2355 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
2356 jump stg_block_async;
2361 // noDuplicate# tries to ensure that none of the thunks under
2362 // evaluation by the current thread are also under evaluation by
2363 // another thread. It relies on *both* threads doing noDuplicate#;
2364 // the second one will get blocked if they are duplicating some work.
2367 SAVE_THREAD_STATE();
2368 ASSERT(StgTSO_what_next(CurrentTSO) == ThreadRunGHC::I16);
2369 foreign "C" threadPaused (MyCapability() "ptr", CurrentTSO "ptr") [];
2371 if (StgTSO_what_next(CurrentTSO) == ThreadKilled::I16) {
2372 jump stg_threadFinished;
2374 LOAD_THREAD_STATE();
2375 ASSERT(StgTSO_what_next(CurrentTSO) == ThreadRunGHC::I16);
2376 jump %ENTRY_CODE(Sp(0));
2380 getApStackValzh_fast
2382 W_ ap_stack, offset, val, ok;
2384 /* args: R1 = AP_STACK, R2 = offset */
2388 if (%INFO_PTR(ap_stack) == stg_AP_STACK_info) {
2390 val = StgAP_STACK_payload(ap_stack,offset);
2398 /* -----------------------------------------------------------------------------
2400 -------------------------------------------------------------------------- */
2402 // Write the cost center stack of the first argument on stderr; return
2403 // the second. Possibly only makes sense for already evaluated
2410 ccs = StgHeader_ccs(UNTAG(R1));
2411 foreign "C" fprintCCS_stderr(ccs "ptr") [R2];
2422 #ifndef THREADED_RTS
2423 RET_NP(0,ghczmprim_GHCziBool_False_closure);
2425 (spark) = foreign "C" findSpark(MyCapability());
2429 RET_NP(0,ghczmprim_GHCziBool_False_closure);