1 /* -----------------------------------------------------------------------------
2 * $Id: PrimOps.hc,v 1.106 2003/03/24 14:46:54 simonmar Exp $
4 * (c) The GHC Team, 1998-2002
6 * Primitive functions / data
8 * ---------------------------------------------------------------------------*/
14 #include "StgStartup.h"
19 #include "BlockAlloc.h" /* tmp */
20 #include "StablePriv.h"
22 #include "Timer.h" /* TICK_MILLISECS */
24 #ifndef mingw32_TARGET_OS
25 #include "Itimer.h" /* getourtimeofday() */
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
34 #ifdef mingw32_TARGET_OS
36 #include "win32/AsyncIO.h"
41 classes CCallable and CReturnable don't really exist, but the
42 compiler insists on generating dictionaries containing references
43 to GHC_ZcCCallable_static_info etc., so we provide dummy symbols
44 for these. Some C compilers can't cope with zero-length static arrays,
45 so we have to make these one element long.
48 StgWord GHC_ZCCCallable_static_info[1];
49 StgWord GHC_ZCCReturnable_static_info[1];
51 /* -----------------------------------------------------------------------------
52 Macros for Hand-written primitives.
53 -------------------------------------------------------------------------- */
56 * Horrible macros for returning unboxed tuples.
58 * How an unboxed tuple is returned depends on two factors:
59 * - the number of real registers we have available
60 * - the boxedness of the returned fields.
62 * To return an unboxed tuple from a primitive operation, we have macros
63 * RET_<layout> where <layout> describes the boxedness of each field of the
64 * unboxed tuple: N indicates a non-pointer field, and P indicates a pointer.
66 * We only define the cases actually used, to avoid having too much
67 * garbage in this section. Warning: any bugs in here will be hard to
70 * The return convention for an unboxed tuple is as follows:
71 * - fit as many fields as possible in registers (as per the
72 * function fast-entry point calling convention).
73 * - sort the rest of the fields into pointers and non-pointers.
74 * push the pointers on the stack, followed by the non-pointers.
75 * (so the pointers have higher addresses).
78 /*------ All Regs available */
79 #if MAX_REAL_VANILLA_REG == 8
80 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
81 # define RET_N(a) RET_P(a)
83 # define RET_PP(a,b) R1.w = (W_)(a); R2.w = (W_)(b); JMP_(ENTRY_CODE(Sp[0]));
84 # define RET_NN(a,b) RET_PP(a,b)
85 # define RET_NP(a,b) RET_PP(a,b)
87 # define RET_PPP(a,b,c) \
88 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); JMP_(ENTRY_CODE(Sp[0]));
89 # define RET_NNP(a,b,c) RET_PPP(a,b,c)
91 # define RET_NNNP(a,b,c,d) \
92 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); R4.w = (W_)d; \
93 JMP_(ENTRY_CODE(Sp[0]));
95 # define RET_NPNP(a,b,c,d) \
96 R1.w = (W_)(a); R2.w = (W_)(b); R3.w = (W_)(c); R4.w = (W_)(d); \
97 JMP_(ENTRY_CODE(Sp[0]));
99 #elif MAX_REAL_VANILLA_REG > 2 && MAX_REAL_VANILLA_REG < 8
100 # error RET_n macros not defined for this setup.
102 /*------ 2 Registers available */
103 #elif MAX_REAL_VANILLA_REG == 2
105 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
106 # define RET_N(a) RET_P(a)
108 # define RET_PP(a,b) R1.w = (W_)(a); R2.w = (W_)(b); \
109 JMP_(ENTRY_CODE(Sp[0]));
110 # define RET_NN(a,b) RET_PP(a,b)
111 # define RET_NP(a,b) RET_PP(a,b)
113 # define RET_PPP(a,b,c) \
118 JMP_(ENTRY_CODE(Sp[1]));
120 # define RET_NNP(a,b,c) \
125 JMP_(ENTRY_CODE(Sp[1]));
127 # define RET_NNNP(a,b,c,d) \
133 JMP_(ENTRY_CODE(Sp[2]));
135 # define RET_NPNP(a,b,c,d) \
141 JMP_(ENTRY_CODE(Sp[2]));
143 /*------ 1 Register available */
144 #elif MAX_REAL_VANILLA_REG == 1
145 # define RET_P(a) R1.w = (W_)(a); JMP_(ENTRY_CODE(Sp[0]));
146 # define RET_N(a) RET_P(a)
148 # define RET_PP(a,b) R1.w = (W_)(a); Sp[-1] = (W_)(b); Sp -= 1; \
149 JMP_(ENTRY_CODE(Sp[1]));
150 # define RET_NN(a,b) R1.w = (W_)(a); Sp[-1] = (W_)(b); Sp -= 2; \
151 JMP_(ENTRY_CODE(Sp[2]));
152 # define RET_NP(a,b) RET_PP(a,b)
154 # define RET_PPP(a,b,c) \
159 JMP_(ENTRY_CODE(Sp[2]));
161 # define RET_NNP(a,b,c) \
166 JMP_(ENTRY_CODE(Sp[2]));
168 # define RET_NNNP(a,b,c,d) \
174 JMP_(ENTRY_CODE(Sp[3]));
176 # define RET_NPNP(a,b,c,d) \
182 JMP_(ENTRY_CODE(Sp[3]));
184 #else /* 0 Regs available */
186 #define PUSH(o,x) Sp[-o] = (W_)(x)
188 #define PUSHED(m) Sp -= (m); JMP_(ENTRY_CODE(Sp[m]));
190 # define RET_P(a) PUSH(1,a); PUSHED(1)
191 # define RET_N(a) PUSH(1,a); PUSHED(2)
193 # define RET_PP(a,b) PUSH(2,a); PUSH(1,b); PUSHED(2)
194 # define RET_NN(a,b) PUSH(2,a); PUSH(1,b); PUSHED(2)
195 # define RET_NP(a,b) PUSH(2,a); PUSH(1,b); PUSHED(2)
197 # define RET_PPP(a,b,c) PUSH(3,a); PUSH(2,b); PUSH(1,c); PUSHED(3)
198 # define RET_NNP(a,b,c) PUSH(3,a); PUSH(2,b); PUSH(1,c); PUSHED(3)
200 # define RET_NNNP(a,b,c,d) PUSH(4,a); PUSH(3,b); PUSH(2,c); PUSH(1,d); PUSHED(4)
201 # define RET_NPNP(a,b,c,d) PUSH(4,a); PUSH(3,c); PUSH(2,b); PUSH(1,d); PUSHED(4)
204 /*-----------------------------------------------------------------------------
207 Basically just new*Array - the others are all inline macros.
209 The size arg is always passed in R1, and the result returned in R1.
211 The slow entry point is for returning from a heap check, the saved
212 size argument must be re-loaded from the stack.
213 -------------------------------------------------------------------------- */
215 /* for objects that are *less* than the size of a word, make sure we
216 * round up to the nearest word for the size of the array.
219 #define BYTES_TO_STGWORDS(n) ((n) + sizeof(W_) - 1)/sizeof(W_)
221 FN_(newByteArrayzh_fast)
223 W_ size, stuff_size, n;
226 MAYBE_GC(NO_PTRS,newByteArrayzh_fast);
228 stuff_size = BYTES_TO_STGWORDS(n);
229 size = sizeofW(StgArrWords)+ stuff_size;
230 p = (StgArrWords *)RET_STGCALL1(P_,allocate,size);
231 TICK_ALLOC_PRIM(sizeofW(StgArrWords),stuff_size,0);
232 SET_HDR(p, &stg_ARR_WORDS_info, CCCS);
233 p->words = stuff_size;
234 TICK_RET_UNBOXED_TUP(1)
239 FN_(newPinnedByteArrayzh_fast)
241 W_ size, stuff_size, n;
244 MAYBE_GC(NO_PTRS,newPinnedByteArrayzh_fast);
246 stuff_size = BYTES_TO_STGWORDS(n);
248 // We want an 8-byte aligned array. allocatePinned() gives us
249 // 8-byte aligned memory by default, but we want to align the
250 // *goods* inside the ArrWords object, so we have to check the
251 // size of the ArrWords header and adjust our size accordingly.
252 size = sizeofW(StgArrWords)+ stuff_size;
253 if ((sizeof(StgArrWords) & 7) != 0) {
257 p = (StgArrWords *)RET_STGCALL1(P_,allocatePinned,size);
258 TICK_ALLOC_PRIM(sizeofW(StgArrWords),stuff_size,0);
260 // Again, if the ArrWords header isn't a multiple of 8 bytes, we
261 // have to push the object forward one word so that the goods
262 // fall on an 8-byte boundary.
263 if ((sizeof(StgArrWords) & 7) != 0) {
267 SET_HDR(p, &stg_ARR_WORDS_info, CCCS);
268 p->words = stuff_size;
269 TICK_RET_UNBOXED_TUP(1)
282 MAYBE_GC(R2_PTR,newArrayzh_fast);
284 size = sizeofW(StgMutArrPtrs) + n;
285 arr = (StgMutArrPtrs *)RET_STGCALL1(P_, allocate, size);
286 TICK_ALLOC_PRIM(sizeofW(StgMutArrPtrs), n, 0);
288 SET_HDR(arr,&stg_MUT_ARR_PTRS_info,CCCS);
292 for (p = (P_)arr + sizeofW(StgMutArrPtrs);
293 p < (P_)arr + size; p++) {
297 TICK_RET_UNBOXED_TUP(1);
302 FN_(newMutVarzh_fast)
305 /* Args: R1.p = initialisation value */
308 HP_CHK_GEN_TICKY(sizeofW(StgMutVar), R1_PTR, newMutVarzh_fast);
309 TICK_ALLOC_PRIM(sizeofW(StgHeader)+1,1, 0); /* hack, dependent on rep. */
310 CCS_ALLOC(CCCS,sizeofW(StgMutVar));
312 mv = (StgMutVar *)(Hp-sizeofW(StgMutVar)+1);
313 SET_HDR(mv,&stg_MUT_VAR_info,CCCS);
316 TICK_RET_UNBOXED_TUP(1);
321 FN_(atomicModifyMutVarzh_fast)
324 StgClosure *z, *x, *y, *r;
326 /* Args: R1.p :: MutVar#, R2.p :: a -> (a,b) */
328 /* If x is the current contents of the MutVar#, then
329 We want to make the new contents point to
333 and the return value is
337 obviously we can share (f x).
339 z = [stg_ap_2 f x] (max (HS + 2) MIN_UPD_SIZE)
340 y = [stg_sel_0 z] (max (HS + 1) MIN_UPD_SIZE)
341 r = [stg_sel_1 z] (max (HS + 1) MIN_UPD_SIZE)
344 #define THUNK_SIZE(n) (sizeofW(StgHeader) + stg_max((n), MIN_UPD_SIZE))
345 #define SIZE (THUNK_SIZE(2) + THUNK_SIZE(1) + THUNK_SIZE(1))
347 HP_CHK_GEN_TICKY(SIZE, R1_PTR|R2_PTR, atomicModifyMutVarzh_fast);
348 CCS_ALLOC(CCCS,SIZE);
350 x = ((StgMutVar *)R1.cl)->var;
352 TICK_ALLOC_UP_THK(2,0); // XXX
353 z = (StgClosure *) Hp - THUNK_SIZE(2) + 1;
354 SET_HDR(z, (StgInfoTable *)&stg_ap_2_upd_info, CCCS);
355 z->payload[0] = R2.cl;
358 TICK_ALLOC_UP_THK(1,1); // XXX
359 y = (StgClosure *) (StgPtr)z - THUNK_SIZE(1);
360 SET_HDR(y, &stg_sel_0_upd_info, CCCS);
363 ((StgMutVar *)R1.cl)->var = y;
365 TICK_ALLOC_UP_THK(1,1); // XXX
366 r = (StgClosure *) (StgPtr)y - THUNK_SIZE(1);
367 SET_HDR(r, &stg_sel_1_upd_info, CCCS);
371 JMP_(ENTRY_CODE(Sp[0]));
375 /* -----------------------------------------------------------------------------
376 Foreign Object Primitives
377 -------------------------------------------------------------------------- */
379 FN_(mkForeignObjzh_fast)
381 /* R1.p = ptr to foreign object,
383 StgForeignObj *result;
386 HP_CHK_GEN_TICKY(sizeofW(StgForeignObj), NO_PTRS, mkForeignObjzh_fast);
387 TICK_ALLOC_PRIM(sizeofW(StgHeader),
388 sizeofW(StgForeignObj)-sizeofW(StgHeader), 0);
389 CCS_ALLOC(CCCS,sizeofW(StgForeignObj)); /* ccs prof */
391 result = (StgForeignObj *) (Hp + 1 - sizeofW(StgForeignObj));
392 SET_HDR(result,&stg_FOREIGN_info,CCCS);
395 /* returns (# s#, ForeignObj# #) */
396 TICK_RET_UNBOXED_TUP(1);
401 /* These two are out-of-line for the benefit of the NCG */
402 FN_(unsafeThawArrayzh_fast)
405 SET_INFO((StgClosure *)R1.cl,&stg_MUT_ARR_PTRS_info);
406 recordMutable((StgMutClosure*)R1.cl);
408 TICK_RET_UNBOXED_TUP(1);
413 /* -----------------------------------------------------------------------------
414 Weak Pointer Primitives
415 -------------------------------------------------------------------------- */
421 R3.p = finalizer (or NULL)
427 R3.cl = &stg_NO_FINALIZER_closure;
430 HP_CHK_GEN_TICKY(sizeofW(StgWeak),R1_PTR|R2_PTR|R3_PTR, mkWeakzh_fast);
431 TICK_ALLOC_PRIM(sizeofW(StgHeader)+1, // +1 is for the link field
432 sizeofW(StgWeak)-sizeofW(StgHeader)-1, 0);
433 CCS_ALLOC(CCCS,sizeofW(StgWeak)); /* ccs prof */
435 w = (StgWeak *) (Hp + 1 - sizeofW(StgWeak));
436 SET_HDR(w, &stg_WEAK_info, CCCS);
440 w->finalizer = R3.cl;
442 w->link = weak_ptr_list;
444 IF_DEBUG(weak, fprintf(stderr,"New weak pointer at %p\n",w));
446 TICK_RET_UNBOXED_TUP(1);
451 FN_(finalizzeWeakzh_fast)
458 TICK_RET_UNBOXED_TUP(0);
459 w = (StgDeadWeak *)R1.p;
462 if (w->header.info == &stg_DEAD_WEAK_info) {
463 RET_NP(0,&stg_NO_FINALIZER_closure);
469 // A weak pointer is inherently used, so we do not need to call
470 // LDV_recordDead_FILL_SLOP_DYNAMIC():
471 // LDV_recordDead_FILL_SLOP_DYNAMIC((StgClosure *)w);
472 // or, LDV_recordDead():
473 // LDV_recordDead((StgClosure *)w, sizeofW(StgWeak) - sizeofW(StgProfHeader));
474 // Furthermore, when PROFILING is turned on, dead weak pointers are exactly as
475 // large as weak pointers, so there is no need to fill the slop, either.
476 // See stg_DEAD_WEAK_info in StgMiscClosures.hc.
479 // Todo: maybe use SET_HDR() and remove LDV_recordCreate()?
481 w->header.info = &stg_DEAD_WEAK_info;
484 LDV_recordCreate((StgClosure *)w);
486 f = ((StgWeak *)w)->finalizer;
487 w->link = ((StgWeak *)w)->link;
489 /* return the finalizer */
490 if (f == &stg_NO_FINALIZER_closure) {
491 RET_NP(0,&stg_NO_FINALIZER_closure);
498 FN_(deRefWeakzh_fast)
500 /* R1.p = weak ptr */
506 if (w->header.info == &stg_WEAK_info) {
508 val = (P_)((StgWeak *)w)->value;
517 /* -----------------------------------------------------------------------------
518 Arbitrary-precision Integer operations.
519 -------------------------------------------------------------------------- */
521 FN_(int2Integerzh_fast)
523 /* arguments: R1 = Int# */
525 I_ val, s; /* to avoid aliasing */
526 StgArrWords* p; /* address of array result */
530 HP_CHK_GEN_TICKY(sizeofW(StgArrWords)+1, NO_PTRS, int2Integerzh_fast);
531 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
532 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
534 p = (StgArrWords *)Hp - 1;
535 SET_ARR_HDR(p, &stg_ARR_WORDS_info, CCCS, 1);
537 /* mpz_set_si is inlined here, makes things simpler */
541 } else if (val > 0) {
548 /* returns (# size :: Int#,
552 TICK_RET_UNBOXED_TUP(2);
557 FN_(word2Integerzh_fast)
559 /* arguments: R1 = Word# */
561 W_ val; /* to avoid aliasing */
563 StgArrWords* p; /* address of array result */
567 HP_CHK_GEN_TICKY(sizeofW(StgArrWords)+1, NO_PTRS, word2Integerzh_fast)
568 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
569 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
571 p = (StgArrWords *)Hp - 1;
572 SET_ARR_HDR(p, &stg_ARR_WORDS_info, CCCS, 1);
581 /* returns (# size :: Int#,
585 TICK_RET_UNBOXED_TUP(2);
592 * 'long long' primops for converting to/from Integers.
595 #ifdef SUPPORT_LONG_LONGS
597 FN_(int64ToIntegerzh_fast)
599 /* arguments: L1 = Int64# */
601 StgInt64 val; /* to avoid aliasing */
603 I_ s, neg, words_needed;
604 StgArrWords* p; /* address of array result */
610 if ( val >= 0x100000000LL || val <= -0x100000000LL ) {
613 /* minimum is one word */
616 HP_CHK_GEN_TICKY(sizeofW(StgArrWords)+words_needed, NO_PTRS, int64ToIntegerzh_fast)
617 TICK_ALLOC_PRIM(sizeofW(StgArrWords),words_needed,0);
618 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+words_needed); /* ccs prof */
620 p = (StgArrWords *)(Hp-words_needed+1) - 1;
621 SET_ARR_HDR(p, &stg_ARR_WORDS_info, CCCS, words_needed);
628 hi = (W_)((LW_)val / 0x100000000ULL);
630 if ( words_needed == 2 ) {
634 } else if ( val != 0 ) {
637 } else /* val==0 */ {
640 s = ( neg ? -s : s );
642 /* returns (# size :: Int#,
646 TICK_RET_UNBOXED_TUP(2);
651 FN_(word64ToIntegerzh_fast)
653 /* arguments: L1 = Word64# */
655 StgWord64 val; /* to avoid aliasing */
658 StgArrWords* p; /* address of array result */
662 if ( val >= 0x100000000ULL ) {
667 HP_CHK_GEN_TICKY(sizeofW(StgArrWords)+words_needed, NO_PTRS, word64ToIntegerzh_fast)
668 TICK_ALLOC_PRIM(sizeofW(StgArrWords),words_needed,0);
669 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+words_needed); /* ccs prof */
671 p = (StgArrWords *)(Hp-words_needed+1) - 1;
672 SET_ARR_HDR(p, &stg_ARR_WORDS_info, CCCS, words_needed);
674 hi = (W_)((LW_)val / 0x100000000ULL);
675 if ( val >= 0x100000000ULL ) {
679 } else if ( val != 0 ) {
682 } else /* val==0 */ {
686 /* returns (# size :: Int#,
690 TICK_RET_UNBOXED_TUP(2);
696 #endif /* SUPPORT_LONG_LONGS */
698 /* ToDo: this is shockingly inefficient */
700 #define GMP_TAKE2_RET1(name,mp_fun) \
703 MP_INT arg1, arg2, result; \
709 /* call doYouWantToGC() */ \
710 MAYBE_GC(R2_PTR | R4_PTR, name); \
712 d1 = (StgArrWords *)R2.p; \
714 d2 = (StgArrWords *)R4.p; \
717 arg1._mp_alloc = d1->words; \
718 arg1._mp_size = (s1); \
719 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
720 arg2._mp_alloc = d2->words; \
721 arg2._mp_size = (s2); \
722 arg2._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d2)); \
724 STGCALL1(mpz_init,&result); \
726 /* Perform the operation */ \
727 STGCALL3(mp_fun,&result,&arg1,&arg2); \
729 TICK_RET_UNBOXED_TUP(2); \
730 RET_NP(result._mp_size, \
731 result._mp_d-sizeofW(StgArrWords)); \
735 #define GMP_TAKE1_RET1(name,mp_fun) \
738 MP_INT arg1, result; \
743 /* call doYouWantToGC() */ \
744 MAYBE_GC(R2_PTR, name); \
746 d1 = (StgArrWords *)R2.p; \
749 arg1._mp_alloc = d1->words; \
750 arg1._mp_size = (s1); \
751 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
753 STGCALL1(mpz_init,&result); \
755 /* Perform the operation */ \
756 STGCALL2(mp_fun,&result,&arg1); \
758 TICK_RET_UNBOXED_TUP(2); \
759 RET_NP(result._mp_size, \
760 result._mp_d-sizeofW(StgArrWords)); \
764 #define GMP_TAKE2_RET2(name,mp_fun) \
767 MP_INT arg1, arg2, result1, result2; \
773 /* call doYouWantToGC() */ \
774 MAYBE_GC(R2_PTR | R4_PTR, name); \
776 d1 = (StgArrWords *)R2.p; \
778 d2 = (StgArrWords *)R4.p; \
781 arg1._mp_alloc = d1->words; \
782 arg1._mp_size = (s1); \
783 arg1._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d1)); \
784 arg2._mp_alloc = d2->words; \
785 arg2._mp_size = (s2); \
786 arg2._mp_d = (unsigned long int *) (BYTE_ARR_CTS(d2)); \
788 STGCALL1(mpz_init,&result1); \
789 STGCALL1(mpz_init,&result2); \
791 /* Perform the operation */ \
792 STGCALL4(mp_fun,&result1,&result2,&arg1,&arg2); \
794 TICK_RET_UNBOXED_TUP(4); \
795 RET_NPNP(result1._mp_size, \
796 result1._mp_d-sizeofW(StgArrWords), \
798 result2._mp_d-sizeofW(StgArrWords)); \
802 GMP_TAKE2_RET1(plusIntegerzh_fast, mpz_add);
803 GMP_TAKE2_RET1(minusIntegerzh_fast, mpz_sub);
804 GMP_TAKE2_RET1(timesIntegerzh_fast, mpz_mul);
805 GMP_TAKE2_RET1(gcdIntegerzh_fast, mpz_gcd);
806 GMP_TAKE2_RET1(quotIntegerzh_fast, mpz_tdiv_q);
807 GMP_TAKE2_RET1(remIntegerzh_fast, mpz_tdiv_r);
808 GMP_TAKE2_RET1(divExactIntegerzh_fast, mpz_divexact);
809 GMP_TAKE2_RET1(andIntegerzh_fast, mpz_and);
810 GMP_TAKE2_RET1(orIntegerzh_fast, mpz_ior);
811 GMP_TAKE2_RET1(xorIntegerzh_fast, mpz_xor);
812 GMP_TAKE1_RET1(complementIntegerzh_fast, mpz_com);
814 GMP_TAKE2_RET2(quotRemIntegerzh_fast, mpz_tdiv_qr);
815 GMP_TAKE2_RET2(divModIntegerzh_fast, mpz_fdiv_qr);
820 /* R1 = the first Int#; R2 = the second Int# */
824 aa = (mp_limb_t)(R1.i);
825 r = RET_STGCALL3(StgInt, mpn_gcd_1, (mp_limb_t *)(&aa), 1, (mp_limb_t)(R2.i));
828 /* Result parked in R1, return via info-pointer at TOS */
829 JMP_(ENTRY_CODE(Sp[0]));
833 FN_(gcdIntegerIntzh_fast)
835 /* R1 = s1; R2 = d1; R3 = the int */
838 r = RET_STGCALL3(StgInt,mpn_gcd_1,(mp_limb_t *)(BYTE_ARR_CTS(R2.p)), R1.i, R3.i);
841 /* Result parked in R1, return via info-pointer at TOS */
842 JMP_(ENTRY_CODE(Sp[0]));
846 FN_(cmpIntegerIntzh_fast)
848 /* R1 = s1; R2 = d1; R3 = the int */
859 // paraphrased from mpz_cmp_si() in the GMP sources
862 } else if (v_digit < 0) {
867 if (usize != vsize) {
868 R1.i = usize - vsize; JMP_(ENTRY_CODE(Sp[0]));
872 R1.i = 0; JMP_(ENTRY_CODE(Sp[0]));
875 u_digit = *(mp_limb_t *)(BYTE_ARR_CTS(R2.p));
877 if (u_digit == (mp_limb_t) (unsigned long) v_digit) {
878 R1.i = 0; JMP_(ENTRY_CODE(Sp[0]));
881 if (u_digit > (mp_limb_t) (unsigned long) v_digit) {
887 JMP_(ENTRY_CODE(Sp[0]));
891 FN_(cmpIntegerzh_fast)
893 /* R1 = s1; R2 = d1; R3 = s2; R4 = d2 */
901 // paraphrased from mpz_cmp() in the GMP sources
905 if (usize != vsize) {
906 R1.i = usize - vsize; JMP_(ENTRY_CODE(Sp[0]));
910 R1.i = 0; JMP_(ENTRY_CODE(Sp[0]));
915 up = BYTE_ARR_CTS(R2.p);
916 vp = BYTE_ARR_CTS(R4.p);
918 cmp = RET_STGCALL3(I_, mpn_cmp, (mp_limb_t *)up, (mp_limb_t *)vp, size);
921 R1.i = 0; JMP_(ENTRY_CODE(Sp[0]));
924 if ((cmp < 0) == (usize < 0)) {
929 /* Result parked in R1, return via info-pointer at TOS */
930 JMP_(ENTRY_CODE(Sp[0]));
934 FN_(integer2Intzh_fast)
943 r = ((mp_limb_t *) (BYTE_ARR_CTS(R2.p)))[0];
946 /* Result parked in R1, return via info-pointer at TOS */
948 JMP_(ENTRY_CODE(Sp[0]));
952 FN_(integer2Wordzh_fast)
962 r = ((mp_limb_t *) (BYTE_ARR_CTS(R2.p)))[0];
965 /* Result parked in R1, return via info-pointer at TOS */
967 JMP_(ENTRY_CODE(Sp[0]));
972 FN_(decodeFloatzh_fast)
980 /* arguments: F1 = Float# */
983 HP_CHK_GEN_TICKY(sizeofW(StgArrWords)+1, NO_PTRS, decodeFloatzh_fast);
984 TICK_ALLOC_PRIM(sizeofW(StgArrWords),1,0);
985 CCS_ALLOC(CCCS,sizeofW(StgArrWords)+1); /* ccs prof */
987 /* Be prepared to tell Lennart-coded __decodeFloat */
988 /* where mantissa._mp_d can be put (it does not care about the rest) */
989 p = (StgArrWords *)Hp - 1;
990 SET_ARR_HDR(p,&stg_ARR_WORDS_info,CCCS,1)
991 mantissa._mp_d = (void *)BYTE_ARR_CTS(p);
993 /* Perform the operation */
994 STGCALL3(__decodeFloat,&mantissa,&exponent,arg);
996 /* returns: (Int# (expn), Int#, ByteArray#) */
997 TICK_RET_UNBOXED_TUP(3);
998 RET_NNP(exponent,mantissa._mp_size,p);
1002 #define DOUBLE_MANTISSA_SIZE (sizeofW(StgDouble))
1003 #define ARR_SIZE (sizeofW(StgArrWords) + DOUBLE_MANTISSA_SIZE)
1005 FN_(decodeDoublezh_fast)
1012 /* arguments: D1 = Double# */
1015 HP_CHK_GEN_TICKY(ARR_SIZE, NO_PTRS, decodeDoublezh_fast);
1016 TICK_ALLOC_PRIM(sizeofW(StgArrWords),DOUBLE_MANTISSA_SIZE,0);
1017 CCS_ALLOC(CCCS,ARR_SIZE); /* ccs prof */
1019 /* Be prepared to tell Lennart-coded __decodeDouble */
1020 /* where mantissa.d can be put (it does not care about the rest) */
1021 p = (StgArrWords *)(Hp-ARR_SIZE+1);
1022 SET_ARR_HDR(p, &stg_ARR_WORDS_info, CCCS, DOUBLE_MANTISSA_SIZE);
1023 mantissa._mp_d = (void *)BYTE_ARR_CTS(p);
1025 /* Perform the operation */
1026 STGCALL3(__decodeDouble,&mantissa,&exponent,arg);
1028 /* returns: (Int# (expn), Int#, ByteArray#) */
1029 TICK_RET_UNBOXED_TUP(3);
1030 RET_NNP(exponent,mantissa._mp_size,p);
1034 /* -----------------------------------------------------------------------------
1035 * Concurrency primitives
1036 * -------------------------------------------------------------------------- */
1041 /* args: R1 = closure to spark */
1043 MAYBE_GC(R1_PTR, forkzh_fast);
1045 /* create it right now, return ThreadID in R1 */
1046 R1.t = RET_STGCALL2(StgTSO *, createIOThread,
1047 RtsFlags.GcFlags.initialStkSize, R1.cl);
1048 STGCALL1(scheduleThread, R1.t);
1050 /* switch at the earliest opportunity */
1057 FN_(forkProcesszh_fast)
1065 R1.i = RET_STGCALL1(StgInt, forkProcess, CurrentTSO);
1067 JMP_(ENTRY_CODE(Sp[0]));
1075 JMP_(stg_yield_noregs);
1079 FN_(myThreadIdzh_fast)
1083 RET_P((P_)CurrentTSO);
1087 FN_(labelThreadzh_fast)
1094 STGCALL2(labelThread,R1.p,(char *)R2.p);
1096 JMP_(ENTRY_CODE(Sp[0]));
1101 /* -----------------------------------------------------------------------------
1104 * take & putMVar work as follows. Firstly, an important invariant:
1106 * If the MVar is full, then the blocking queue contains only
1107 * threads blocked on putMVar, and if the MVar is empty then the
1108 * blocking queue contains only threads blocked on takeMVar.
1111 * MVar empty : then add ourselves to the blocking queue
1112 * MVar full : remove the value from the MVar, and
1113 * blocking queue empty : return
1114 * blocking queue non-empty : perform the first blocked putMVar
1115 * from the queue, and wake up the
1116 * thread (MVar is now full again)
1118 * putMVar is just the dual of the above algorithm.
1120 * How do we "perform a putMVar"? Well, we have to fiddle around with
1121 * the stack of the thread waiting to do the putMVar. See
1122 * stg_block_putmvar and stg_block_takemvar in HeapStackCheck.c for
1123 * the stack layout, and the PerformPut and PerformTake macros below.
1125 * It is important that a blocked take or put is woken up with the
1126 * take/put already performed, because otherwise there would be a
1127 * small window of vulnerability where the thread could receive an
1128 * exception and never perform its take or put, and we'd end up with a
1131 * -------------------------------------------------------------------------- */
1133 FN_(isEmptyMVarzh_fast)
1135 /* args: R1 = MVar closure */
1138 r = (I_)((GET_INFO((StgMVar*)(R1.p))) == &stg_EMPTY_MVAR_info);
1151 HP_CHK_GEN_TICKY(sizeofW(StgMVar), NO_PTRS, newMVarzh_fast);
1152 TICK_ALLOC_PRIM(sizeofW(StgMutVar)-1, // consider head,tail,link as admin wds
1154 CCS_ALLOC(CCCS,sizeofW(StgMVar)); /* ccs prof */
1156 mvar = (StgMVar *) (Hp - sizeofW(StgMVar) + 1);
1157 SET_HDR(mvar,&stg_EMPTY_MVAR_info,CCCS);
1158 mvar->head = mvar->tail = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1159 mvar->value = (StgClosure *)&stg_END_TSO_QUEUE_closure;
1161 TICK_RET_UNBOXED_TUP(1);
1166 /* If R1 isn't available, pass it on the stack */
1168 #define PerformTake(tso, value) ({ \
1169 (tso)->sp[1] = (W_)value; \
1170 (tso)->sp[0] = (W_)&stg_gc_unpt_r1_info; \
1173 #define PerformTake(tso, value) ({ \
1174 (tso)->sp[1] = (W_)value; \
1175 (tso)->sp[0] = (W_)&stg_ut_1_0_unreg_info; \
1180 #define PerformPut(tso) ({ \
1181 StgClosure *val = (StgClosure *)(tso)->sp[2]; \
1186 FN_(takeMVarzh_fast)
1190 const StgInfoTable *info;
1193 /* args: R1 = MVar closure */
1195 mvar = (StgMVar *)R1.p;
1198 info = LOCK_CLOSURE(mvar);
1200 info = GET_INFO(mvar);
1203 /* If the MVar is empty, put ourselves on its blocking queue,
1204 * and wait until we're woken up.
1206 if (info == &stg_EMPTY_MVAR_info) {
1207 if (mvar->head == (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1208 mvar->head = CurrentTSO;
1210 mvar->tail->link = CurrentTSO;
1212 CurrentTSO->link = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1213 CurrentTSO->why_blocked = BlockedOnMVar;
1214 CurrentTSO->block_info.closure = (StgClosure *)mvar;
1215 mvar->tail = CurrentTSO;
1218 /* unlock the MVar */
1219 mvar->header.info = &stg_EMPTY_MVAR_info;
1221 JMP_(stg_block_takemvar);
1224 /* we got the value... */
1227 if (mvar->head != (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1228 /* There are putMVar(s) waiting...
1229 * wake up the first thread on the queue
1231 ASSERT(mvar->head->why_blocked == BlockedOnMVar);
1233 /* actually perform the putMVar for the thread that we just woke up */
1234 mvar->value = PerformPut(mvar->head);
1236 #if defined(GRAN) || defined(PAR)
1237 /* ToDo: check 2nd arg (mvar) is right */
1238 mvar->head = RET_STGCALL2(StgTSO *,unblockOne,mvar->head,mvar);
1240 mvar->head = RET_STGCALL1(StgTSO *,unblockOne,mvar->head);
1242 if (mvar->head == (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1243 mvar->tail = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1246 /* unlock in the SMP case */
1247 SET_INFO(mvar,&stg_FULL_MVAR_info);
1249 TICK_RET_UNBOXED_TUP(1);
1252 /* No further putMVars, MVar is now empty */
1254 /* do this last... we might have locked the MVar in the SMP case,
1255 * and writing the info pointer will unlock it.
1257 SET_INFO(mvar,&stg_EMPTY_MVAR_info);
1258 mvar->value = (StgClosure *)&stg_END_TSO_QUEUE_closure;
1259 TICK_RET_UNBOXED_TUP(1);
1265 FN_(tryTakeMVarzh_fast)
1269 const StgInfoTable *info;
1272 /* args: R1 = MVar closure */
1274 mvar = (StgMVar *)R1.p;
1277 info = LOCK_CLOSURE(mvar);
1279 info = GET_INFO(mvar);
1282 if (info == &stg_EMPTY_MVAR_info) {
1285 /* unlock the MVar */
1286 SET_INFO(mvar,&stg_EMPTY_MVAR_info);
1289 /* HACK: we need a pointer to pass back,
1290 * so we abuse NO_FINALIZER_closure
1292 RET_NP(0, &stg_NO_FINALIZER_closure);
1295 /* we got the value... */
1298 if (mvar->head != (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1299 /* There are putMVar(s) waiting...
1300 * wake up the first thread on the queue
1302 ASSERT(mvar->head->why_blocked == BlockedOnMVar);
1304 /* actually perform the putMVar for the thread that we just woke up */
1305 mvar->value = PerformPut(mvar->head);
1307 #if defined(GRAN) || defined(PAR)
1308 /* ToDo: check 2nd arg (mvar) is right */
1309 mvar->head = RET_STGCALL2(StgTSO *,unblockOne,mvar->head,mvar);
1311 mvar->head = RET_STGCALL1(StgTSO *,unblockOne,mvar->head);
1313 if (mvar->head == (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1314 mvar->tail = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1317 /* unlock in the SMP case */
1318 SET_INFO(mvar,&stg_FULL_MVAR_info);
1321 /* No further putMVars, MVar is now empty */
1322 mvar->value = (StgClosure *)&stg_END_TSO_QUEUE_closure;
1324 /* do this last... we might have locked the MVar in the SMP case,
1325 * and writing the info pointer will unlock it.
1327 SET_INFO(mvar,&stg_EMPTY_MVAR_info);
1330 TICK_RET_UNBOXED_TUP(1);
1338 const StgInfoTable *info;
1341 /* args: R1 = MVar, R2 = value */
1343 mvar = (StgMVar *)R1.p;
1346 info = LOCK_CLOSURE(mvar);
1348 info = GET_INFO(mvar);
1351 if (info == &stg_FULL_MVAR_info) {
1352 if (mvar->head == (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1353 mvar->head = CurrentTSO;
1355 mvar->tail->link = CurrentTSO;
1357 CurrentTSO->link = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1358 CurrentTSO->why_blocked = BlockedOnMVar;
1359 CurrentTSO->block_info.closure = (StgClosure *)mvar;
1360 mvar->tail = CurrentTSO;
1363 /* unlock the MVar */
1364 SET_INFO(mvar,&stg_FULL_MVAR_info);
1366 JMP_(stg_block_putmvar);
1369 if (mvar->head != (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1370 /* There are takeMVar(s) waiting: wake up the first one
1372 ASSERT(mvar->head->why_blocked == BlockedOnMVar);
1374 /* actually perform the takeMVar */
1375 PerformTake(mvar->head, R2.cl);
1377 #if defined(GRAN) || defined(PAR)
1378 /* ToDo: check 2nd arg (mvar) is right */
1379 mvar->head = RET_STGCALL2(StgTSO *,unblockOne,mvar->head,mvar);
1381 mvar->head = RET_STGCALL1(StgTSO *,unblockOne,mvar->head);
1383 if (mvar->head == (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1384 mvar->tail = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1387 /* unlocks the MVar in the SMP case */
1388 SET_INFO(mvar,&stg_EMPTY_MVAR_info);
1390 JMP_(ENTRY_CODE(Sp[0]));
1392 /* No further takes, the MVar is now full. */
1393 mvar->value = R2.cl;
1394 /* unlocks the MVar in the SMP case */
1395 SET_INFO(mvar,&stg_FULL_MVAR_info);
1396 JMP_(ENTRY_CODE(Sp[0]));
1399 /* ToDo: yield afterward for better communication performance? */
1403 FN_(tryPutMVarzh_fast)
1406 const StgInfoTable *info;
1409 /* args: R1 = MVar, R2 = value */
1411 mvar = (StgMVar *)R1.p;
1414 info = LOCK_CLOSURE(mvar);
1416 info = GET_INFO(mvar);
1419 if (info == &stg_FULL_MVAR_info) {
1422 /* unlock the MVar */
1423 mvar->header.info = &stg_FULL_MVAR_info;
1429 if (mvar->head != (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1430 /* There are takeMVar(s) waiting: wake up the first one
1432 ASSERT(mvar->head->why_blocked == BlockedOnMVar);
1434 /* actually perform the takeMVar */
1435 PerformTake(mvar->head, R2.cl);
1437 #if defined(GRAN) || defined(PAR)
1438 /* ToDo: check 2nd arg (mvar) is right */
1439 mvar->head = RET_STGCALL2(StgTSO *,unblockOne,mvar->head,mvar);
1441 mvar->head = RET_STGCALL1(StgTSO *,unblockOne,mvar->head);
1443 if (mvar->head == (StgTSO *)&stg_END_TSO_QUEUE_closure) {
1444 mvar->tail = (StgTSO *)&stg_END_TSO_QUEUE_closure;
1447 /* unlocks the MVar in the SMP case */
1448 SET_INFO(mvar,&stg_EMPTY_MVAR_info);
1450 JMP_(ENTRY_CODE(Sp[0]));
1452 /* No further takes, the MVar is now full. */
1453 mvar->value = R2.cl;
1454 /* unlocks the MVar in the SMP case */
1455 SET_INFO(mvar,&stg_FULL_MVAR_info);
1456 JMP_(ENTRY_CODE(Sp[0]));
1459 /* ToDo: yield afterward for better communication performance? */
1463 /* -----------------------------------------------------------------------------
1464 Stable pointer primitives
1465 ------------------------------------------------------------------------- */
1467 FN_(makeStableNamezh_fast)
1470 StgStableName *sn_obj;
1473 HP_CHK_GEN_TICKY(sizeofW(StgStableName), R1_PTR, makeStableNamezh_fast);
1474 TICK_ALLOC_PRIM(sizeofW(StgHeader),
1475 sizeofW(StgStableName)-sizeofW(StgHeader), 0);
1476 CCS_ALLOC(CCCS,sizeofW(StgStableName)); /* ccs prof */
1478 index = RET_STGCALL1(StgWord,lookupStableName,R1.p);
1480 /* Is there already a StableName for this heap object? */
1481 if (stable_ptr_table[index].sn_obj == NULL) {
1482 sn_obj = (StgStableName *) (Hp - sizeofW(StgStableName) + 1);
1483 SET_HDR(sn_obj,&stg_STABLE_NAME_info,CCCS);
1485 stable_ptr_table[index].sn_obj = (StgClosure *)sn_obj;
1487 (StgClosure *)sn_obj = stable_ptr_table[index].sn_obj;
1490 TICK_RET_UNBOXED_TUP(1);
1495 FN_(makeStablePtrzh_fast)
1500 MAYBE_GC(R1_PTR, makeStablePtrzh_fast);
1501 sp = RET_STGCALL1(StgStablePtr,getStablePtr,R1.p);
1506 FN_(deRefStablePtrzh_fast)
1508 /* Args: R1 = the stable ptr */
1512 sp = (StgStablePtr)R1.w;
1513 r = stable_ptr_table[(StgWord)sp].addr;
1518 /* -----------------------------------------------------------------------------
1519 Bytecode object primitives
1520 ------------------------------------------------------------------------- */
1533 StgArrWords *bitmap_arr;
1536 bitmap_arr = (StgArrWords *)R6.cl;
1537 size = sizeofW(StgBCO) + bitmap_arr->words;
1538 HP_CHK_GEN_TICKY(size,R1_PTR|R2_PTR|R3_PTR|R4_PTR|R6_PTR, newBCOzh_fast);
1539 TICK_ALLOC_PRIM(size, size-sizeofW(StgHeader), 0);
1540 CCS_ALLOC(CCCS,size); /* ccs prof */
1541 bco = (StgBCO *) (Hp + 1 - size);
1542 SET_HDR(bco, (const StgInfoTable *)&stg_BCO_info, CCCS);
1544 bco->instrs = (StgArrWords*)R1.cl;
1545 bco->literals = (StgArrWords*)R2.cl;
1546 bco->ptrs = (StgMutArrPtrs*)R3.cl;
1547 bco->itbls = (StgArrWords*)R4.cl;
1551 // Copy the arity/bitmap info into the BCO
1554 for (i = 0; i < bitmap_arr->words; i++) {
1555 bco->bitmap[i] = bitmap_arr->payload[i];
1559 TICK_RET_UNBOXED_TUP(1);
1564 FN_(mkApUpd0zh_fast)
1566 // R1.p = the BCO# for the AP
1571 // This function is *only* used to wrap zero-arity BCOs in an
1572 // updatable wrapper (see ByteCodeLink.lhs). An AP thunk is always
1573 // saturated and always points directly to a FUN or BCO.
1574 ASSERT(get_itbl(R1.cl)->type == BCO && ((StgBCO *)R1.p)->arity == 0);
1576 HP_CHK_GEN_TICKY(PAP_sizeW(0), R1_PTR, mkApUpd0zh_fast);
1577 TICK_ALLOC_PRIM(sizeofW(StgHeader), PAP_sizeW(0)-sizeofW(StgHeader), 0);
1578 CCS_ALLOC(CCCS,PAP_sizeW(0)); /* ccs prof */
1579 ap = (StgPAP *) (Hp + 1 - PAP_sizeW(0));
1580 SET_HDR(ap, &stg_AP_info, CCCS);
1585 TICK_RET_UNBOXED_TUP(1);
1590 /* -----------------------------------------------------------------------------
1591 Thread I/O blocking primitives
1592 -------------------------------------------------------------------------- */
1594 FN_(waitReadzh_fast)
1598 ASSERT(CurrentTSO->why_blocked == NotBlocked);
1599 CurrentTSO->why_blocked = BlockedOnRead;
1600 CurrentTSO->block_info.fd = R1.i;
1601 ACQUIRE_LOCK(&sched_mutex);
1602 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
1603 RELEASE_LOCK(&sched_mutex);
1604 JMP_(stg_block_noregs);
1608 FN_(waitWritezh_fast)
1612 ASSERT(CurrentTSO->why_blocked == NotBlocked);
1613 CurrentTSO->why_blocked = BlockedOnWrite;
1614 CurrentTSO->block_info.fd = R1.i;
1615 ACQUIRE_LOCK(&sched_mutex);
1616 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
1617 RELEASE_LOCK(&sched_mutex);
1618 JMP_(stg_block_noregs);
1624 #ifdef mingw32_TARGET_OS
1625 StgAsyncIOResult* ares;
1633 ASSERT(CurrentTSO->why_blocked == NotBlocked);
1634 CurrentTSO->why_blocked = BlockedOnDelay;
1636 ACQUIRE_LOCK(&sched_mutex);
1637 #ifdef mingw32_TARGET_OS
1638 /* could probably allocate this on the heap instead */
1639 ares = (StgAsyncIOResult*)RET_STGCALL2(P_,stgMallocBytes,sizeof(StgAsyncIOResult), "asyncWritezh_fast");
1640 reqID = RET_STGCALL1(W_,addDelayRequest,R1.i);
1641 ares->reqID = reqID;
1644 CurrentTSO->block_info.async_result = ares;
1645 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
1647 target = (R1.i / (TICK_MILLISECS*1000)) + getourtimeofday();
1648 CurrentTSO->block_info.target = target;
1650 /* Insert the new thread in the sleeping queue. */
1653 while (t != END_TSO_QUEUE && t->block_info.target < target) {
1658 CurrentTSO->link = t;
1660 sleeping_queue = CurrentTSO;
1662 prev->link = CurrentTSO;
1665 RELEASE_LOCK(&sched_mutex);
1666 JMP_(stg_block_noregs);
1670 #ifdef mingw32_TARGET_OS
1671 FN_(asyncReadzh_fast)
1673 StgAsyncIOResult* ares;
1676 /* args: R1.i = fd, R2.i = isSock, R3.i = len, R4.p = buf */
1677 ASSERT(CurrentTSO->why_blocked == NotBlocked);
1678 CurrentTSO->why_blocked = BlockedOnRead;
1679 ACQUIRE_LOCK(&sched_mutex);
1680 /* could probably allocate this on the heap instead */
1681 ares = (StgAsyncIOResult*)RET_STGCALL2(P_,stgMallocBytes,sizeof(StgAsyncIOResult), "asyncWritezh_fast");
1682 reqID = RET_STGCALL5(W_,addIORequest,R1.i,FALSE,R2.i,R3.i,(char*)R4.p);
1683 ares->reqID = reqID;
1686 CurrentTSO->block_info.async_result = ares;
1687 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
1688 RELEASE_LOCK(&sched_mutex);
1689 JMP_(stg_block_async);
1693 FN_(asyncWritezh_fast)
1695 StgAsyncIOResult* ares;
1699 /* args: R1.i = fd, R2.i = isSock, R3.i = len, R4.p = buf */
1700 ASSERT(CurrentTSO->why_blocked == NotBlocked);
1701 CurrentTSO->why_blocked = BlockedOnWrite;
1702 ACQUIRE_LOCK(&sched_mutex);
1703 ares = (StgAsyncIOResult*)RET_STGCALL2(P_,stgMallocBytes,sizeof(StgAsyncIOResult), "asyncWritezh_fast");
1704 reqID = RET_STGCALL5(W_,addIORequest,R1.i,TRUE,R2.i,R3.i,(char*)R4.p);
1705 ares->reqID = reqID;
1708 CurrentTSO->block_info.async_result = ares;
1709 APPEND_TO_BLOCKED_QUEUE(CurrentTSO);
1710 RELEASE_LOCK(&sched_mutex);
1711 JMP_(stg_block_async);