1 /* -----------------------------------------------------------------------------
2 * $Id: PrimOps.hc,v 1.20 1999/03/03 19:11:43 sof 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];
35 /* -----------------------------------------------------------------------------
36 Macros for Hand-written primitives.
37 -------------------------------------------------------------------------- */
40 * Horrible macros for returning unboxed tuples.
42 * How an unboxed tuple is returned depends on two factors:
43 * - the number of real registers we have available
44 * - the boxedness of the returned fields.
46 * To return an unboxed tuple from a primitive operation, we have macros
47 * RET_<layout> where <layout> describes the boxedness of each field of the
48 * unboxed tuple: N indicates a non-pointer field, and P indicates a pointer.
50 * We only define the cases actually used, to avoid having too much
51 * garbage in this section. Warning: any bugs in here will be hard to
55 /*------ All Regs available */
57 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
58 # define RET_N(a) RET_P(a)
60 # define RET_PP(a,b) R1.w = (W_)(a); R2.w = (W_)(b); JMP_(ENTRY_CODE(Sp[0]));
61 # define RET_NN(a,b) RET_PP(a,b)
62 # define RET_NP(a,b) RET_PP(a,b)
64 # define RET_PPP(a,b,c) \
65 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); JMP_(ENTRY_CODE(Sp[0]));
66 # define RET_NNP(a,b,c) RET_PPP(a,b,c)
68 # define RET_NNNP(a,b,c,d) \
69 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); R4.w = (W_)d; \
70 JMP_(ENTRY_CODE(Sp[0]));
72 # define RET_NPNP(a,b,c,d) \
73 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); R4.w = (W_)(d); \
74 JMP_(ENTRY_CODE(Sp[0]));
76 # define RET_NNPNNP(a,b,c,d,e,f) \
77 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); \
78 R4.w = (W_)(d); R5.w = (W_)(e); R6.w = (W_)(f); \
79 JMP_(ENTRY_CODE(Sp[0]));
83 #if defined(REG_R7) || defined(REG_R6) || defined(REG_R5) || \
84 defined(REG_R4) || defined(REG_R3) || defined(REG_R2)
85 # error RET_n macros not defined for this setup.
88 /*------ 1 Register available */
90 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
91 # define RET_N(a) RET_P(a)
93 # define RET_PP(a,b) R1.w = (W_)(a); Sp[-1] = (W_)(b); Sp -= 1; \
94 JMP_(ENTRY_CODE(Sp[1]));
95 # define RET_NN(a,b) R1.w = (W_)(a); Sp[-1] = (W_)(b); Sp -= 2; \
96 JMP_(ENTRY_CODE(Sp[2]));
97 # define RET_NP(a,b) RET_PP(a,b)
99 # define RET_PPP(a,b,c) \
100 R1.w = (W_)(a); Sp[-2] = (W_)(b); Sp[-1] = (W_)(c); Sp -= 2; \
101 JMP_(ENTRY_CODE(Sp[2]));
102 # define RET_NNP(a,b,c) \
103 R1.w = (W_)(a); Sp[-2] = (W_)(b); Sp[-1] = (W_)(c); Sp -= 3; \
104 JMP_(ENTRY_CODE(Sp[3]));
106 # define RET_NNNP(a,b,c,d) \
108 /* Sp[-5] = ARGTAG(1); */ \
110 /* Sp[-3] = ARGTAG(1); */ \
114 JMP_(ENTRY_CODE(Sp[5]));
116 # define RET_NPNP(a,b,c,d) \
119 /* Sp[-3] = ARGTAG(1); */ \
123 JMP_(ENTRY_CODE(Sp[4]));
125 # define RET_NNPNNP(a,b,c,d,e,f) \
129 /* Sp[-3] = ARGTAG(1); */ \
131 /* Sp[-5] = ARGTAG(1); */ \
134 /* Sp[-8] = ARGTAG(1); */ \
136 JMP_(ENTRY_CODE(Sp[8]));
138 #else /* 0 Regs available */
140 #define PUSH_P(o,x) Sp[-o] = (W_)(x)
141 #define PUSH_N(o,x) Sp[1-o] = (W_)(x); /* Sp[-o] = ARGTAG(1) */
142 #define PUSHED(m) Sp -= (m); JMP_(ENTRY_CODE(Sp[m]));
144 /* Here's how to construct these macros:
146 * N = number of N's in the name;
147 * P = number of P's in the name;
149 * while (nonNull(name)) {
150 * if (nextChar == 'P') {
161 # define RET_P(a) PUSH_P(1,a); PUSHED(1)
162 # define RET_N(a) PUSH_N(2,a); PUSHED(2)
164 # define RET_PP(a,b) PUSH_P(2,a); PUSH_P(1,b); PUSHED(2)
165 # define RET_NN(a,b) PUSH_N(4,a); PUSH_N(2,b); PUSHED(4)
166 # define RET_NP(a,b) PUSH_N(3,a); PUSH_P(1,b); PUSHED(3)
168 # define RET_PPP(a,b,c) PUSH_P(3,a); PUSH_P(2,b); PUSH_P(1,c); PUSHED(3)
169 # define RET_NNP(a,b,c) PUSH_N(6,a); PUSH_N(4,b); PUSH_N(2,c); PUSHED(6)
171 # 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)
172 # 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)
173 # 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)
180 /*-----------------------------------------------------------------------------
183 Basically just new*Array - the others are all inline macros.
185 The size arg is always passed in R1, and the result returned in R1.
187 The slow entry point is for returning from a heap check, the saved
188 size argument must be re-loaded from the stack.
189 -------------------------------------------------------------------------- */
191 /* for objects that are *less* than the size of a word, make sure we
192 * round up to the nearest word for the size of the array.
195 #define BYTES_TO_STGWORDS(n) ((n) + sizeof(W_) - 1)/sizeof(W_)
197 #define newByteArray(ty,scale) \
198 FN_(new##ty##Arrayzh_fast) \
200 W_ stuff_size, size, n; \
203 MAYBE_GC(NO_PTRS,new##ty##Arrayzh_fast); \
205 stuff_size = BYTES_TO_STGWORDS(n*scale); \
206 size = sizeofW(StgArrWords)+ stuff_size; \
207 p = (StgArrWords *)RET_STGCALL1(P_,allocate,size); \
208 TICK_ALLOC_PRIM(sizeofW(StgArrWords),stuff_size,0); \
209 SET_HDR(p, &ARR_WORDS_info, CCCS); \
210 p->words = stuff_size; \
211 TICK_RET_UNBOXED_TUP(1) \
216 newByteArray(Char, sizeof(C_))
217 newByteArray(Int, sizeof(I_));
218 newByteArray(Word, sizeof(W_));
219 newByteArray(Addr, sizeof(P_));
220 newByteArray(Float, sizeof(StgFloat));
221 newByteArray(Double, sizeof(StgDouble));
222 newByteArray(StablePtr, sizeof(StgStablePtr));
232 MAYBE_GC(R2_PTR,newArrayzh_fast);
234 size = sizeofW(StgMutArrPtrs) + n;
235 arr = (StgMutArrPtrs *)RET_STGCALL1(P_, allocate, size);
236 TICK_ALLOC_PRIM(sizeofW(StgMutArrPtrs), n, 0);
238 SET_HDR(arr,&MUT_ARR_PTRS_info,CCCS);
242 for (p = (P_)arr + sizeofW(StgMutArrPtrs);
243 p < (P_)arr + size; p++) {
247 TICK_RET_UNBOXED_TUP(1);
252 FN_(newMutVarzh_fast)
255 /* Args: R1.p = initialisation value */
258 HP_CHK_GEN(sizeofW(StgMutVar), R1_PTR, newMutVarzh_fast,);
259 TICK_ALLOC_PRIM(sizeofW(StgHeader)+1,1, 0); /* hack, dependent on rep. */
260 CCS_ALLOC(CCCS,sizeofW(StgMutVar));
262 mv = (StgMutVar *)(Hp-sizeofW(StgMutVar)+1);
263 SET_HDR(mv,&MUT_VAR_info,CCCS);
266 TICK_RET_UNBOXED_TUP(1);
271 /* -----------------------------------------------------------------------------
272 Foreign Object Primitives
274 -------------------------------------------------------------------------- */
277 FN_(makeForeignObjzh_fast)
279 /* R1.p = ptr to foreign object,
281 StgForeignObj *result;
284 HP_CHK_GEN(sizeofW(StgForeignObj), NO_PTRS, makeForeignObjzh_fast,);
285 TICK_ALLOC_PRIM(sizeofW(StgHeader),
286 sizeofW(StgForeignObj)-sizeofW(StgHeader), 0);
287 CCS_ALLOC(CCCS,sizeofW(StgForeignObj)); /* ccs prof */
289 result = (StgForeignObj *) (Hp + 1 - sizeofW(StgForeignObj));
290 SET_HDR(result,&FOREIGN_info,CCCS);
293 /* returns (# s#, ForeignObj# #) */
294 TICK_RET_UNBOXED_TUP(1);
300 /* -----------------------------------------------------------------------------
301 Weak Pointer Primitives
302 -------------------------------------------------------------------------- */
315 HP_CHK_GEN(sizeofW(StgWeak), R1_PTR|R2_PTR|R3_PTR, mkWeakzh_fast,);
316 TICK_ALLOC_PRIM(sizeofW(StgHeader)+1, // +1 is for the link field
317 sizeofW(StgWeak)-sizeofW(StgHeader)-1, 0);
318 CCS_ALLOC(CCCS,sizeofW(StgWeak)); /* ccs prof */
320 w = (StgWeak *) (Hp + 1 - sizeofW(StgWeak));
321 SET_HDR(w, &WEAK_info, CCCS);
326 w->finalizer = R3.cl;
328 w->finalizer = &NO_FINALIZER_closure;
331 w->link = weak_ptr_list;
333 IF_DEBUG(weak, fprintf(stderr,"New weak pointer at %p\n",w));
335 TICK_RET_UNBOXED_TUP(1);
340 FN_(finalizzeWeakzh_fast)
347 TICK_RET_UNBOXED_TUP(0);
348 w = (StgDeadWeak *)R1.p;
351 if (w->header.info == &DEAD_WEAK_info) {
352 RET_NP(0,&NO_FINALIZER_closure);
356 w->header.info = &DEAD_WEAK_info;
357 f = ((StgWeak *)w)->finalizer;
358 w->link = ((StgWeak *)w)->link;
360 /* return the finalizer */
361 if (f == &NO_FINALIZER_closure) {
362 RET_NP(0,&NO_FINALIZER_closure);
371 /* -----------------------------------------------------------------------------
372 Arbitrary-precision Integer operations.
373 -------------------------------------------------------------------------- */
375 FN_(int2Integerzh_fast)
377 /* arguments: R1 = Int# */
379 I_ val, s; /* to avoid aliasing */
380 StgArrWords* p; /* address of array result */
384 HP_CHK_GEN(sizeofW(StgArrWords)+1, NO_PTRS, int2Integerzh_fast,);
385 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
386 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
388 p = stgCast(StgArrWords*,Hp)-1;
389 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, 1);
391 /* mpz_set_si is inlined here, makes things simpler */
395 } else if (val > 0) {
402 /* returns (# size :: Int#,
406 TICK_RET_UNBOXED_TUP(2);
411 FN_(word2Integerzh_fast)
413 /* arguments: R1 = Word# */
415 W_ val; /* to avoid aliasing */
417 StgArrWords* p; /* address of array result */
421 HP_CHK_GEN(sizeofW(StgArrWords)+1, NO_PTRS, word2Integerzh_fast,)
422 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
423 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
425 p = stgCast(StgArrWords*,Hp)-1;
426 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, 1);
435 /* returns (# size :: Int#,
439 TICK_RET_UNBOXED_TUP(2);
444 FN_(addr2Integerzh_fast)
450 MAYBE_GC(NO_PTRS,addr2Integerzh_fast);
452 /* args: R1 :: Addr# */
455 /* Perform the operation */
456 if (RET_STGCALL3(int, mpz_init_set_str,&result,(str),/*base*/10))
459 /* returns (# size :: Int#,
463 TICK_RET_UNBOXED_TUP(2);
464 RET_NP(result._mp_size,
465 result._mp_d - sizeofW(StgArrWords));
470 * 'long long' primops for converting to/from Integers.
473 #ifdef SUPPORT_LONG_LONGS
475 FN_(int64ToIntegerzh_fast)
477 /* arguments: L1 = Int64# */
479 StgInt64 val; /* to avoid aliasing */
481 I_ s, neg, words_needed;
482 StgArrWords* p; /* address of array result */
488 if ( val >= 0x100000000LL || val <= -0x100000000LL ) {
491 /* minimum is one word */
494 HP_CHK_GEN(sizeofW(StgArrWords)+words_needed, NO_PTRS, int64ToIntegerzh_fast,)
495 TICK_ALLOC_PRIM(sizeofW(StgArrWords),words_needed,0);
496 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+words_needed); /* ccs prof */
498 p = stgCast(StgArrWords*,(Hp-words_needed+1))-1;
499 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, words_needed);
506 hi = (W_)((LW_)val / 0x100000000ULL);
508 if ( words_needed == 2 ) {
512 } else if ( val != 0 ) {
515 } else /* val==0 */ {
518 s = ( neg ? -s : s );
520 /* returns (# size :: Int#,
524 TICK_RET_UNBOXED_TUP(2);
529 FN_(word64ToIntegerzh_fast)
531 /* arguments: L1 = Word64# */
533 StgWord64 val; /* to avoid aliasing */
536 StgArrWords* p; /* address of array result */
540 if ( val >= 0x100000000ULL ) {
545 HP_CHK_GEN(sizeofW(StgArrWords)+words_needed, NO_PTRS, word64ToIntegerzh_fast,)
546 TICK_ALLOC_PRIM(sizeofW(StgArrWords),words_needed,0);
547 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+words_needed); /* ccs prof */
549 p = stgCast(StgArrWords*,(Hp-words_needed+1))-1;
550 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, words_needed);
552 hi = (W_)((LW_)val / 0x100000000ULL);
553 if ( val >= 0x100000000ULL ) {
557 } else if ( val != 0 ) {
560 } else /* val==0 */ {
564 /* returns (# size :: Int#,
568 TICK_RET_UNBOXED_TUP(2);
574 #endif /* HAVE_LONG_LONG */
576 /* ToDo: this is shockingly inefficient */
578 #define GMP_TAKE2_RET1(name,mp_fun) \
581 MP_INT arg1, arg2, result; \
587 /* call doYouWantToGC() */ \
588 MAYBE_GC(R2_PTR | R4_PTR, name); \
590 d1 = (StgArrWords *)R2.p; \
592 d2 = (StgArrWords *)R4.p; \
595 arg1._mp_alloc = d1->words; \
596 arg1._mp_size = (s1); \
597 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
598 arg2._mp_alloc = d2->words; \
599 arg2._mp_size = (s2); \
600 arg2._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d2)); \
602 STGCALL1(mpz_init,&result); \
604 /* Perform the operation */ \
605 STGCALL3(mp_fun,&result,&arg1,&arg2); \
607 TICK_RET_UNBOXED_TUP(2); \
608 RET_NP(result._mp_size, \
609 result._mp_d-sizeofW(StgArrWords)); \
613 #define GMP_TAKE2_RET2(name,mp_fun) \
616 MP_INT arg1, arg2, result1, result2; \
622 /* call doYouWantToGC() */ \
623 MAYBE_GC(R2_PTR | R4_PTR, name); \
625 d1 = (StgArrWords *)R2.p; \
627 d2 = (StgArrWords *)R4.p; \
630 arg1._mp_alloc = d1->words; \
631 arg1._mp_size = (s1); \
632 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
633 arg2._mp_alloc = d2->words; \
634 arg2._mp_size = (s2); \
635 arg2._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d2)); \
637 STGCALL1(mpz_init,&result1); \
638 STGCALL1(mpz_init,&result2); \
640 /* Perform the operation */ \
641 STGCALL4(mp_fun,&result1,&result2,&arg1,&arg2); \
643 TICK_RET_UNBOXED_TUP(4); \
644 RET_NPNP(result1._mp_size, \
645 result1._mp_d-sizeofW(StgArrWords), \
647 result2._mp_d-sizeofW(StgArrWords)); \
651 GMP_TAKE2_RET1(plusIntegerzh_fast, mpz_add);
652 GMP_TAKE2_RET1(minusIntegerzh_fast, mpz_sub);
653 GMP_TAKE2_RET1(timesIntegerzh_fast, mpz_mul);
654 GMP_TAKE2_RET1(gcdIntegerzh_fast, mpz_gcd);
656 GMP_TAKE2_RET2(quotRemIntegerzh_fast, mpz_tdiv_qr);
657 GMP_TAKE2_RET2(divModIntegerzh_fast, mpz_fdiv_qr);
659 #ifndef FLOATS_AS_DOUBLES
660 FN_(decodeFloatzh_fast)
668 /* arguments: F1 = Float# */
671 HP_CHK_GEN(sizeof(StgArrWords)+1, NO_PTRS, decodeFloatzh_fast,);
672 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
673 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
675 /* Be prepared to tell Lennart-coded __decodeFloat */
676 /* where mantissa._mp_d can be put (it does not care about the rest) */
677 p = stgCast(StgArrWords*,Hp)-1;
678 SET_ARR_HDR(p,&ARR_WORDS_info,CCCS,1)
679 mantissa._mp_d = (void *)BYTE_ARR_CTS(p);
681 /* Perform the operation */
682 STGCALL3(__decodeFloat,&mantissa,&exponent,arg);
684 /* returns: (Int# (expn), Int#, ByteArray#) */
685 TICK_RET_UNBOXED_TUP(3);
686 RET_NNP(exponent,mantissa._mp_size,p);
689 #endif /* !FLOATS_AS_DOUBLES */
691 #define DOUBLE_MANTISSA_SIZE (sizeof(StgDouble)/sizeof(W_))
692 #define ARR_SIZE (sizeof(StgArrWords) + DOUBLE_MANTISSA_SIZE)
694 FN_(decodeDoublezh_fast)
701 /* arguments: D1 = Double# */
704 HP_CHK_GEN(ARR_SIZE, NO_PTRS, decodeDoublezh_fast,);
705 TICK_ALLOC_PRIM(sizeof(StgArrWords),DOUBLE_MANTISSA_SIZE,0);
706 CCS_ALLOC(CCCS,ARR_SIZE); /* ccs prof */
708 /* Be prepared to tell Lennart-coded __decodeDouble */
709 /* where mantissa.d can be put (it does not care about the rest) */
710 p = stgCast(StgArrWords*,Hp-ARR_SIZE+1);
711 SET_ARR_HDR(p, &ARR_WORDS_info, CCCS, DOUBLE_MANTISSA_SIZE);
712 mantissa._mp_d = (void *)BYTE_ARR_CTS(p);
714 /* Perform the operation */
715 STGCALL3(__decodeDouble,&mantissa,&exponent,arg);
717 /* returns: (Int# (expn), Int#, ByteArray#) */
718 TICK_RET_UNBOXED_TUP(3);
719 RET_NNP(exponent,mantissa._mp_size,p);
723 /* -----------------------------------------------------------------------------
724 * Concurrency primitives
725 * -------------------------------------------------------------------------- */
730 /* args: R1 = closure to spark */
732 if (closure_SHOULD_SPARK(stgCast(StgClosure*,R1.p))) {
734 MAYBE_GC(R1_PTR, forkzh_fast);
736 /* create it right now, return ThreadID in R1 */
737 R1.t = RET_STGCALL2(StgTSO *, createIOThread,
738 RtsFlags.GcFlags.initialStkSize, R1.cl);
740 /* switch at the earliest opportunity */
744 JMP_(ENTRY_CODE(Sp[0]));
748 FN_(killThreadzh_fast)
751 /* args: R1.p = TSO to kill */
753 /* The thread is dead, but the TSO sticks around for a while. That's why
754 * we don't have to explicitly remove it from any queues it might be on.
756 STGCALL1(deleteThread, (StgTSO *)R1.p);
758 /* We might have killed ourselves. In which case, better return to the
761 if ((StgTSO *)R1.p == CurrentTSO) {
762 JMP_(stg_stop_thread_entry); /* leave semi-gracefully */
765 JMP_(ENTRY_CODE(Sp[0]));
776 HP_CHK_GEN(sizeofW(StgMVar), NO_PTRS, newMVarzh_fast,);
777 TICK_ALLOC_PRIM(sizeofW(StgMutVar)-1, // consider head,tail,link as admin wds
779 CCS_ALLOC(CCCS,sizeofW(StgMVar)); /* ccs prof */
781 mvar = (StgMVar *) (Hp - sizeofW(StgMVar) + 1);
782 SET_INFO(mvar,&EMPTY_MVAR_info);
783 mvar->head = mvar->tail = (StgTSO *)&END_TSO_QUEUE_closure;
784 mvar->value = (StgClosure *)&END_TSO_QUEUE_closure;
786 TICK_RET_UNBOXED_TUP(1);
797 /* args: R1 = MVar closure */
799 mvar = (StgMVar *)R1.p;
801 /* If the MVar is empty, put ourselves on its blocking queue,
802 * and wait until we're woken up.
804 if (GET_INFO(mvar) != &FULL_MVAR_info) {
805 if (mvar->head == (StgTSO *)&END_TSO_QUEUE_closure) {
806 mvar->head = CurrentTSO;
808 mvar->tail->link = CurrentTSO;
810 CurrentTSO->link = (StgTSO *)&END_TSO_QUEUE_closure;
811 mvar->tail = CurrentTSO;
813 BLOCK(R1_PTR, takeMVarzh_fast);
816 SET_INFO(mvar,&EMPTY_MVAR_info);
818 mvar->value = (StgClosure *)&END_TSO_QUEUE_closure;
820 TICK_RET_UNBOXED_TUP(1);
831 /* args: R1 = MVar, R2 = value */
833 mvar = (StgMVar *)R1.p;
834 if (GET_INFO(mvar) == &FULL_MVAR_info) {
836 fprintf(stderr, "putMVar#: MVar already full.\n");
837 stg_exit(EXIT_FAILURE);
840 SET_INFO(mvar,&FULL_MVAR_info);
843 /* wake up the first thread on the queue,
844 * it will continue with the takeMVar operation and mark the MVar
848 if (tso != (StgTSO *)&END_TSO_QUEUE_closure) {
849 PUSH_ON_RUN_QUEUE(tso);
850 mvar->head = tso->link;
851 tso->link = (StgTSO *)&END_TSO_QUEUE_closure;
852 if (mvar->head == (StgTSO *)&END_TSO_QUEUE_closure) {
853 mvar->tail = (StgTSO *)&END_TSO_QUEUE_closure;
857 /* ToDo: yield here for better communication performance? */
858 JMP_(ENTRY_CODE(Sp[0]));
862 /* -----------------------------------------------------------------------------
863 Stable pointer primitives
864 ------------------------------------------------------------------------- */
866 FN_(makeStableNamezh_fast)
869 StgStableName *sn_obj;
872 HP_CHK_GEN(sizeofW(StgStableName), R1_PTR, makeStableNamezh_fast,);
873 TICK_ALLOC_PRIM(sizeofW(StgHeader),
874 sizeofW(StgStableName)-sizeofW(StgHeader), 0);
875 CCS_ALLOC(CCCS,sizeofW(StgStableName)); /* ccs prof */
877 index = RET_STGCALL1(StgWord,lookupStableName,R1.p);
879 /* Is there already a StableName for this heap object? */
880 if (stable_ptr_table[index].sn_obj == NULL) {
881 sn_obj = (StgStableName *) (Hp - sizeofW(StgStableName) + 1);
882 sn_obj->header.info = &STABLE_NAME_info;
884 stable_ptr_table[index].sn_obj = (StgClosure *)sn_obj;
886 (StgClosure *)sn_obj = stable_ptr_table[index].sn_obj;
889 TICK_RET_UNBOXED_TUP(1);
893 #endif /* COMPILER */