1 /* -----------------------------------------------------------------------------
2 * $Id: PrimOps.hc,v 1.19 1999/03/01 10:17:15 simonm Exp $
4 * (c) The GHC Team, 1998-1999
6 * Primitive functions / data
8 * ---------------------------------------------------------------------------*/
15 #include "StgStartup.h"
20 #include "BlockAlloc.h" /* tmp */
21 #include "StablePriv.h"
25 classes CCallable and CReturnable don't really exist, but the
26 compiler insists on generating dictionaries containing references
27 to GHC_ZcCCallable_static_info etc., so we provide dummy symbols
31 W_ GHC_ZCCCallable_static_info[0];
32 W_ GHC_ZCCReturnable_static_info[0];
34 #ifndef aix_TARGET_OS /* AIX gives link errors with this as a const (RO assembler section) */
37 StgClosure *PrelBase_Bool_closure_tbl[] = {
42 /* -----------------------------------------------------------------------------
43 Macros for Hand-written primitives.
44 -------------------------------------------------------------------------- */
47 * Horrible macros for returning unboxed tuples.
49 * How an unboxed tuple is returned depends on two factors:
50 * - the number of real registers we have available
51 * - the boxedness of the returned fields.
53 * To return an unboxed tuple from a primitive operation, we have macros
54 * RET_<layout> where <layout> describes the boxedness of each field of the
55 * unboxed tuple: N indicates a non-pointer field, and P indicates a pointer.
57 * We only define the cases actually used, to avoid having too much
58 * garbage in this section. Warning: any bugs in here will be hard to
62 /*------ All Regs available */
64 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
65 # define RET_N(a) RET_P(a)
67 # define RET_PP(a,b) R1.w = (W_)(a); R2.w = (W_)(b); JMP_(ENTRY_CODE(Sp[0]));
68 # define RET_NN(a,b) RET_PP(a,b)
69 # define RET_NP(a,b) RET_PP(a,b)
71 # define RET_PPP(a,b,c) \
72 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); JMP_(ENTRY_CODE(Sp[0]));
73 # define RET_NNP(a,b,c) RET_PPP(a,b,c)
75 # define RET_NNNP(a,b,c,d) \
76 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); R4.w = (W_)d; \
77 JMP_(ENTRY_CODE(Sp[0]));
79 # define RET_NPNP(a,b,c,d) \
80 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); R4.w = (W_)(d); \
81 JMP_(ENTRY_CODE(Sp[0]));
83 # define RET_NNPNNP(a,b,c,d,e,f) \
84 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); \
85 R4.w = (W_)(d); R5.w = (W_)(e); R6.w = (W_)(f); \
86 JMP_(ENTRY_CODE(Sp[0]));
90 #if defined(REG_R7) || defined(REG_R6) || defined(REG_R5) || \
91 defined(REG_R4) || defined(REG_R3) || defined(REG_R2)
92 # error RET_n macros not defined for this setup.
95 /*------ 1 Register available */
97 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
98 # define RET_N(a) RET_P(a)
100 # define RET_PP(a,b) R1.w = (W_)(a); Sp[-1] = (W_)(b); Sp -= 1; \
101 JMP_(ENTRY_CODE(Sp[1]));
102 # define RET_NN(a,b) R1.w = (W_)(a); Sp[-1] = (W_)(b); Sp -= 2; \
103 JMP_(ENTRY_CODE(Sp[2]));
104 # define RET_NP(a,b) RET_PP(a,b)
106 # define RET_PPP(a,b,c) \
107 R1.w = (W_)(a); Sp[-2] = (W_)(b); Sp[-1] = (W_)(c); Sp -= 2; \
108 JMP_(ENTRY_CODE(Sp[2]));
109 # define RET_NNP(a,b,c) \
110 R1.w = (W_)(a); Sp[-2] = (W_)(b); Sp[-1] = (W_)(c); Sp -= 3; \
111 JMP_(ENTRY_CODE(Sp[3]));
113 # define RET_NNNP(a,b,c,d) \
115 /* Sp[-5] = ARGTAG(1); */ \
117 /* Sp[-3] = ARGTAG(1); */ \
121 JMP_(ENTRY_CODE(Sp[5]));
123 # define RET_NPNP(a,b,c,d) \
126 /* Sp[-3] = ARGTAG(1); */ \
130 JMP_(ENTRY_CODE(Sp[4]));
132 # define RET_NNPNNP(a,b,c,d,e,f) \
136 /* Sp[-3] = ARGTAG(1); */ \
138 /* Sp[-5] = ARGTAG(1); */ \
141 /* Sp[-8] = ARGTAG(1); */ \
143 JMP_(ENTRY_CODE(Sp[8]));
145 #else /* 0 Regs available */
147 #define PUSH_P(o,x) Sp[-o] = (W_)(x)
148 #define PUSH_N(o,x) Sp[1-o] = (W_)(x); /* Sp[-o] = ARGTAG(1) */
149 #define PUSHED(m) Sp -= (m); JMP_(ENTRY_CODE(Sp[m]));
151 /* Here's how to construct these macros:
153 * N = number of N's in the name;
154 * P = number of P's in the name;
156 * while (nonNull(name)) {
157 * if (nextChar == 'P') {
168 # define RET_P(a) PUSH_P(1,a); PUSHED(1)
169 # define RET_N(a) PUSH_N(2,a); PUSHED(2)
171 # define RET_PP(a,b) PUSH_P(2,a); PUSH_P(1,b); PUSHED(2)
172 # define RET_NN(a,b) PUSH_N(4,a); PUSH_N(2,b); PUSHED(4)
173 # define RET_NP(a,b) PUSH_N(3,a); PUSH_P(1,b); PUSHED(3)
175 # define RET_PPP(a,b,c) PUSH_P(3,a); PUSH_P(2,b); PUSH_P(1,c); PUSHED(3)
176 # define RET_NNP(a,b,c) PUSH_N(6,a); PUSH_N(4,b); PUSH_N(2,c); PUSHED(6)
178 # define RET_NNNP(a,b,c,d) PUSH_N(7,a); PUSH_N(5,b); PUSH_N(3,c); PUSH_P(1,d); PUSHED(7)
179 # define RET_NPNP(a,b,c,d) PUSH_N(6,a); PUSH_P(4,b); PUSH_N(3,c); PUSH_P(1,d); PUSHED(6)
180 # define RET_NNPNNP(a,b,c,d,e,f) PUSH_N(10,a); PUSH_N(8,b); PUSH_P(6,c); PUSH_N(5,d); PUSH_N(3,e); PUSH_P(1,f); PUSHED(10)
187 /*-----------------------------------------------------------------------------
190 Basically just new*Array - the others are all inline macros.
192 The size arg is always passed in R1, and the result returned in R1.
194 The slow entry point is for returning from a heap check, the saved
195 size argument must be re-loaded from the stack.
196 -------------------------------------------------------------------------- */
198 /* for objects that are *less* than the size of a word, make sure we
199 * round up to the nearest word for the size of the array.
202 #define BYTES_TO_STGWORDS(n) ((n) + sizeof(W_) - 1)/sizeof(W_)
204 #define newByteArray(ty,scale) \
205 FN_(new##ty##Arrayzh_fast) \
207 W_ stuff_size, size, n; \
210 MAYBE_GC(NO_PTRS,new##ty##Arrayzh_fast); \
212 stuff_size = BYTES_TO_STGWORDS(n*scale); \
213 size = sizeofW(StgArrWords)+ stuff_size; \
214 p = (StgArrWords *)RET_STGCALL1(P_,allocate,size); \
215 TICK_ALLOC_PRIM(sizeofW(StgArrWords),stuff_size,0); \
216 SET_HDR(p, &ARR_WORDS_info, CCCS); \
217 p->words = stuff_size; \
218 TICK_RET_UNBOXED_TUP(1) \
223 newByteArray(Char, sizeof(C_))
224 newByteArray(Int, sizeof(I_));
225 newByteArray(Word, sizeof(W_));
226 newByteArray(Addr, sizeof(P_));
227 newByteArray(Float, sizeof(StgFloat));
228 newByteArray(Double, sizeof(StgDouble));
229 newByteArray(StablePtr, sizeof(StgStablePtr));
239 MAYBE_GC(R2_PTR,newArrayzh_fast);
241 size = sizeofW(StgMutArrPtrs) + n;
242 arr = (StgMutArrPtrs *)RET_STGCALL1(P_, allocate, size);
243 TICK_ALLOC_PRIM(sizeofW(StgMutArrPtrs), n, 0);
245 SET_HDR(arr,&MUT_ARR_PTRS_info,CCCS);
249 for (p = (P_)arr + sizeofW(StgMutArrPtrs);
250 p < (P_)arr + size; p++) {
254 TICK_RET_UNBOXED_TUP(1);
259 FN_(newMutVarzh_fast)
262 /* Args: R1.p = initialisation value */
265 HP_CHK_GEN(sizeofW(StgMutVar), R1_PTR, newMutVarzh_fast,);
266 TICK_ALLOC_PRIM(sizeofW(StgHeader)+1,1, 0); /* hack, dependent on rep. */
267 CCS_ALLOC(CCCS,sizeofW(StgMutVar));
269 mv = (StgMutVar *)(Hp-sizeofW(StgMutVar)+1);
270 SET_HDR(mv,&MUT_VAR_info,CCCS);
273 TICK_RET_UNBOXED_TUP(1);
278 /* -----------------------------------------------------------------------------
279 Foreign Object Primitives
281 -------------------------------------------------------------------------- */
284 FN_(makeForeignObjzh_fast)
286 /* R1.p = ptr to foreign object,
288 StgForeignObj *result;
291 HP_CHK_GEN(sizeofW(StgForeignObj), NO_PTRS, makeForeignObjzh_fast,);
292 TICK_ALLOC_PRIM(sizeofW(StgHeader),
293 sizeofW(StgForeignObj)-sizeofW(StgHeader), 0);
294 CCS_ALLOC(CCCS,sizeofW(StgForeignObj)); /* ccs prof */
296 result = (StgForeignObj *) (Hp + 1 - sizeofW(StgForeignObj));
297 SET_HDR(result,&FOREIGN_info,CCCS);
300 /* returns (# s#, ForeignObj# #) */
301 TICK_RET_UNBOXED_TUP(1);
307 /* -----------------------------------------------------------------------------
308 Weak Pointer Primitives
309 -------------------------------------------------------------------------- */
322 HP_CHK_GEN(sizeofW(StgWeak), R1_PTR|R2_PTR|R3_PTR, mkWeakzh_fast,);
323 TICK_ALLOC_PRIM(sizeofW(StgHeader)+1, // +1 is for the link field
324 sizeofW(StgWeak)-sizeofW(StgHeader)-1, 0);
325 CCS_ALLOC(CCCS,sizeofW(StgWeak)); /* ccs prof */
327 w = (StgWeak *) (Hp + 1 - sizeofW(StgWeak));
328 SET_HDR(w, &WEAK_info, CCCS);
333 w->finalizer = R3.cl;
335 w->finalizer = &NO_FINALIZER_closure;
338 w->link = weak_ptr_list;
340 IF_DEBUG(weak, fprintf(stderr,"New weak pointer at %p\n",w));
342 TICK_RET_UNBOXED_TUP(1);
347 FN_(finalizzeWeakzh_fast)
354 TICK_RET_UNBOXED_TUP(0);
355 w = (StgDeadWeak *)R1.p;
358 if (w->header.info == &DEAD_WEAK_info) {
359 RET_NP(0,&NO_FINALIZER_closure);
363 w->header.info = &DEAD_WEAK_info;
364 f = ((StgWeak *)w)->finalizer;
365 w->link = ((StgWeak *)w)->link;
367 /* return the finalizer */
368 if (f == &NO_FINALIZER_closure) {
369 RET_NP(0,&NO_FINALIZER_closure);
378 /* -----------------------------------------------------------------------------
379 Arbitrary-precision Integer operations.
380 -------------------------------------------------------------------------- */
382 FN_(int2Integerzh_fast)
384 /* arguments: R1 = Int# */
386 I_ val, s; /* to avoid aliasing */
387 StgArrWords* p; /* address of array result */
391 HP_CHK_GEN(sizeofW(StgArrWords)+1, NO_PTRS, int2Integerzh_fast,);
392 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
393 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
395 p = stgCast(StgArrWords*,Hp)-1;
396 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, 1);
398 /* mpz_set_si is inlined here, makes things simpler */
402 } else if (val > 0) {
409 /* returns (# size :: Int#,
413 TICK_RET_UNBOXED_TUP(2);
418 FN_(word2Integerzh_fast)
420 /* arguments: R1 = Word# */
422 W_ val; /* to avoid aliasing */
424 StgArrWords* p; /* address of array result */
428 HP_CHK_GEN(sizeofW(StgArrWords)+1, NO_PTRS, word2Integerzh_fast,)
429 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
430 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
432 p = stgCast(StgArrWords*,Hp)-1;
433 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, 1);
442 /* returns (# size :: Int#,
446 TICK_RET_UNBOXED_TUP(2);
451 FN_(addr2Integerzh_fast)
457 MAYBE_GC(NO_PTRS,addr2Integerzh_fast);
459 /* args: R1 :: Addr# */
462 /* Perform the operation */
463 if (RET_STGCALL3(int, mpz_init_set_str,&result,(str),/*base*/10))
466 /* returns (# size :: Int#,
470 TICK_RET_UNBOXED_TUP(2);
471 RET_NP(result._mp_size,
472 result._mp_d - sizeofW(StgArrWords));
477 * 'long long' primops for converting to/from Integers.
480 #ifdef SUPPORT_LONG_LONGS
482 FN_(int64ToIntegerzh_fast)
484 /* arguments: L1 = Int64# */
486 StgInt64 val; /* to avoid aliasing */
488 I_ s, neg, words_needed;
489 StgArrWords* p; /* address of array result */
495 if ( val >= 0x100000000LL || val <= -0x100000000LL ) {
498 /* minimum is one word */
501 HP_CHK_GEN(sizeofW(StgArrWords)+words_needed, NO_PTRS, int64ToIntegerzh_fast,)
502 TICK_ALLOC_PRIM(sizeofW(StgArrWords),words_needed,0);
503 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+words_needed); /* ccs prof */
505 p = stgCast(StgArrWords*,(Hp-words_needed+1))-1;
506 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, words_needed);
513 hi = (W_)((LW_)val / 0x100000000ULL);
515 if ( words_needed == 2 ) {
519 } else if ( val != 0 ) {
522 } else /* val==0 */ {
525 s = ( neg ? -s : s );
527 /* returns (# size :: Int#,
531 TICK_RET_UNBOXED_TUP(2);
536 FN_(word64ToIntegerzh_fast)
538 /* arguments: L1 = Word64# */
540 StgNat64 val; /* to avoid aliasing */
543 StgArrWords* p; /* address of array result */
547 if ( val >= 0x100000000ULL ) {
552 HP_CHK_GEN(sizeofW(StgArrWords)+words_needed, NO_PTRS, word64ToIntegerzh_fast,)
553 TICK_ALLOC_PRIM(sizeofW(StgArrWords),words_needed,0);
554 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+words_needed); /* ccs prof */
556 p = stgCast(StgArrWords*,(Hp-words_needed+1))-1;
557 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, words_needed);
559 hi = (W_)((LW_)val / 0x100000000ULL);
560 if ( val >= 0x100000000ULL ) {
564 } else if ( val != 0 ) {
567 } else /* val==0 */ {
571 /* returns (# size :: Int#,
575 TICK_RET_UNBOXED_TUP(2);
581 #endif /* HAVE_LONG_LONG */
583 /* ToDo: this is shockingly inefficient */
585 #define GMP_TAKE2_RET1(name,mp_fun) \
588 MP_INT arg1, arg2, result; \
594 /* call doYouWantToGC() */ \
595 MAYBE_GC(R2_PTR | R4_PTR, name); \
597 d1 = (StgArrWords *)R2.p; \
599 d2 = (StgArrWords *)R4.p; \
602 arg1._mp_alloc = d1->words; \
603 arg1._mp_size = (s1); \
604 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
605 arg2._mp_alloc = d2->words; \
606 arg2._mp_size = (s2); \
607 arg2._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d2)); \
609 STGCALL1(mpz_init,&result); \
611 /* Perform the operation */ \
612 STGCALL3(mp_fun,&result,&arg1,&arg2); \
614 TICK_RET_UNBOXED_TUP(2); \
615 RET_NP(result._mp_size, \
616 result._mp_d-sizeofW(StgArrWords)); \
620 #define GMP_TAKE2_RET2(name,mp_fun) \
623 MP_INT arg1, arg2, result1, result2; \
629 /* call doYouWantToGC() */ \
630 MAYBE_GC(R2_PTR | R4_PTR, name); \
632 d1 = (StgArrWords *)R2.p; \
634 d2 = (StgArrWords *)R4.p; \
637 arg1._mp_alloc = d1->words; \
638 arg1._mp_size = (s1); \
639 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
640 arg2._mp_alloc = d2->words; \
641 arg2._mp_size = (s2); \
642 arg2._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d2)); \
644 STGCALL1(mpz_init,&result1); \
645 STGCALL1(mpz_init,&result2); \
647 /* Perform the operation */ \
648 STGCALL4(mp_fun,&result1,&result2,&arg1,&arg2); \
650 TICK_RET_UNBOXED_TUP(4); \
651 RET_NPNP(result1._mp_size, \
652 result1._mp_d-sizeofW(StgArrWords), \
654 result2._mp_d-sizeofW(StgArrWords)); \
658 GMP_TAKE2_RET1(plusIntegerzh_fast, mpz_add);
659 GMP_TAKE2_RET1(minusIntegerzh_fast, mpz_sub);
660 GMP_TAKE2_RET1(timesIntegerzh_fast, mpz_mul);
661 GMP_TAKE2_RET1(gcdIntegerzh_fast, mpz_gcd);
663 GMP_TAKE2_RET2(quotRemIntegerzh_fast, mpz_tdiv_qr);
664 GMP_TAKE2_RET2(divModIntegerzh_fast, mpz_fdiv_qr);
666 #ifndef FLOATS_AS_DOUBLES
667 FN_(decodeFloatzh_fast)
675 /* arguments: F1 = Float# */
678 HP_CHK_GEN(sizeof(StgArrWords)+1, NO_PTRS, decodeFloatzh_fast,);
679 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
680 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
682 /* Be prepared to tell Lennart-coded __decodeFloat */
683 /* where mantissa._mp_d can be put (it does not care about the rest) */
684 p = stgCast(StgArrWords*,Hp)-1;
685 SET_ARR_HDR(p,&ARR_WORDS_info,CCCS,1)
686 mantissa._mp_d = (void *)BYTE_ARR_CTS(p);
688 /* Perform the operation */
689 STGCALL3(__decodeFloat,&mantissa,&exponent,arg);
691 /* returns: (Int# (expn), Int#, ByteArray#) */
692 TICK_RET_UNBOXED_TUP(3);
693 RET_NNP(exponent,mantissa._mp_size,p);
696 #endif /* !FLOATS_AS_DOUBLES */
698 #define DOUBLE_MANTISSA_SIZE (sizeof(StgDouble)/sizeof(W_))
699 #define ARR_SIZE (sizeof(StgArrWords) + DOUBLE_MANTISSA_SIZE)
701 FN_(decodeDoublezh_fast)
708 /* arguments: D1 = Double# */
711 HP_CHK_GEN(ARR_SIZE, NO_PTRS, decodeDoublezh_fast,);
712 TICK_ALLOC_PRIM(sizeof(StgArrWords),DOUBLE_MANTISSA_SIZE,0);
713 CCS_ALLOC(CCCS,ARR_SIZE); /* ccs prof */
715 /* Be prepared to tell Lennart-coded __decodeDouble */
716 /* where mantissa.d can be put (it does not care about the rest) */
717 p = stgCast(StgArrWords*,Hp-ARR_SIZE+1);
718 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, DOUBLE_MANTISSA_SIZE);
719 mantissa._mp_d = (void *)BYTE_ARR_CTS(p);
721 /* Perform the operation */
722 STGCALL3(__decodeDouble,&mantissa,&exponent,arg);
724 /* returns: (Int# (expn), Int#, ByteArray#) */
725 TICK_RET_UNBOXED_TUP(3);
726 RET_NNP(exponent,mantissa._mp_size,p);
730 /* -----------------------------------------------------------------------------
731 * Concurrency primitives
732 * -------------------------------------------------------------------------- */
737 /* args: R1 = closure to spark */
739 if (closure_SHOULD_SPARK(stgCast(StgClosure*,R1.p))) {
741 MAYBE_GC(R1_PTR, forkzh_fast);
743 /* create it right now, return ThreadID in R1 */
744 R1.t = RET_STGCALL2(StgTSO *, createIOThread,
745 RtsFlags.GcFlags.initialStkSize, R1.cl);
747 /* switch at the earliest opportunity */
751 JMP_(ENTRY_CODE(Sp[0]));
755 FN_(killThreadzh_fast)
758 /* args: R1.p = TSO to kill */
760 /* The thread is dead, but the TSO sticks around for a while. That's why
761 * we don't have to explicitly remove it from any queues it might be on.
763 STGCALL1(deleteThread, (StgTSO *)R1.p);
765 /* We might have killed ourselves. In which case, better return to the
768 if ((StgTSO *)R1.p == CurrentTSO) {
769 JMP_(stg_stop_thread_entry); /* leave semi-gracefully */
772 JMP_(ENTRY_CODE(Sp[0]));
783 HP_CHK_GEN(sizeofW(StgMVar), NO_PTRS, newMVarzh_fast,);
784 TICK_ALLOC_PRIM(sizeofW(StgMutVar)-1, // consider head,tail,link as admin wds
786 CCS_ALLOC(CCCS,sizeofW(StgMVar)); /* ccs prof */
788 mvar = (StgMVar *) (Hp - sizeofW(StgMVar) + 1);
789 SET_INFO(mvar,&EMPTY_MVAR_info);
790 mvar->head = mvar->tail = (StgTSO *)&END_TSO_QUEUE_closure;
791 mvar->value = (StgClosure *)&END_TSO_QUEUE_closure;
793 TICK_RET_UNBOXED_TUP(1);
804 /* args: R1 = MVar closure */
806 mvar = (StgMVar *)R1.p;
808 /* If the MVar is empty, put ourselves on its blocking queue,
809 * and wait until we're woken up.
811 if (GET_INFO(mvar) != &FULL_MVAR_info) {
812 if (mvar->head == (StgTSO *)&END_TSO_QUEUE_closure) {
813 mvar->head = CurrentTSO;
815 mvar->tail->link = CurrentTSO;
817 CurrentTSO->link = (StgTSO *)&END_TSO_QUEUE_closure;
818 mvar->tail = CurrentTSO;
820 BLOCK(R1_PTR, takeMVarzh_fast);
823 SET_INFO(mvar,&EMPTY_MVAR_info);
825 mvar->value = (StgClosure *)&END_TSO_QUEUE_closure;
827 TICK_RET_UNBOXED_TUP(1);
838 /* args: R1 = MVar, R2 = value */
840 mvar = (StgMVar *)R1.p;
841 if (GET_INFO(mvar) == &FULL_MVAR_info) {
843 fprintf(stderr, "putMVar#: MVar already full.\n");
844 stg_exit(EXIT_FAILURE);
847 SET_INFO(mvar,&FULL_MVAR_info);
850 /* wake up the first thread on the queue,
851 * it will continue with the takeMVar operation and mark the MVar
855 if (tso != (StgTSO *)&END_TSO_QUEUE_closure) {
856 PUSH_ON_RUN_QUEUE(tso);
857 mvar->head = tso->link;
858 tso->link = (StgTSO *)&END_TSO_QUEUE_closure;
859 if (mvar->head == (StgTSO *)&END_TSO_QUEUE_closure) {
860 mvar->tail = (StgTSO *)&END_TSO_QUEUE_closure;
864 /* ToDo: yield here for better communication performance? */
865 JMP_(ENTRY_CODE(Sp[0]));
869 /* -----------------------------------------------------------------------------
870 Stable pointer primitives
871 ------------------------------------------------------------------------- */
873 FN_(makeStableNamezh_fast)
876 StgStableName *sn_obj;
879 HP_CHK_GEN(sizeofW(StgStableName), R1_PTR, makeStableNamezh_fast,);
880 TICK_ALLOC_PRIM(sizeofW(StgHeader),
881 sizeofW(StgStableName)-sizeofW(StgHeader), 0);
882 CCS_ALLOC(CCCS,sizeofW(StgStableName)); /* ccs prof */
884 index = RET_STGCALL1(StgWord,lookupStableName,R1.p);
886 /* Is there already a StableName for this heap object? */
887 if (stable_ptr_table[index].sn_obj == NULL) {
888 sn_obj = (StgStableName *) (Hp - sizeofW(StgStableName) + 1);
889 sn_obj->header.info = &STABLE_NAME_info;
891 stable_ptr_table[index].sn_obj = (StgClosure *)sn_obj;
893 (StgClosure *)sn_obj = stable_ptr_table[index].sn_obj;
896 TICK_RET_UNBOXED_TUP(1);
900 #endif /* COMPILER */