[project @ 2001-12-12 14:58:26 by simonmar]
[ghc-hetmet.git] / ghc / includes / StgMacros.h
index df6c82c..aeb9f10 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: StgMacros.h,v 1.34 2000/08/15 14:22:24 simonmar Exp $
+ * $Id: StgMacros.h,v 1.45 2001/12/10 18:06:50 sof Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -132,7 +132,6 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 
 #define STK_CHK(headroom,ret,r,layout,tag_assts)               \
        if (Sp - headroom < SpLim) {                            \
-           EXTFUN_RTS(stg_chk_##layout);                       \
            tag_assts                                           \
            (r) = (P_)ret;                                      \
            JMP_(stg_chk_##layout);                             \
@@ -141,20 +140,20 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 #define HP_CHK(headroom,ret,r,layout,tag_assts)                        \
         DO_GRAN_ALLOCATE(headroom)                              \
        if ((Hp += headroom) > HpLim) {                         \
-           EXTFUN_RTS(stg_chk_##layout);                       \
+            HpAlloc = (headroom);                              \
            tag_assts                                           \
            (r) = (P_)ret;                                      \
            JMP_(stg_chk_##layout);                             \
-       }
+       }                                                       
 
 #define HP_STK_CHK(stk_headroom,hp_headroom,ret,r,layout,tag_assts) \
         DO_GRAN_ALLOCATE(hp_headroom)                              \
        if (Sp - stk_headroom < SpLim || (Hp += hp_headroom) > HpLim) { \
-           EXTFUN_RTS(stg_chk_##layout);                       \
+            HpAlloc = (hp_headroom);                           \
            tag_assts                                           \
            (r) = (P_)ret;                                      \
            JMP_(stg_chk_##layout);                             \
-       }
+       }                                                       
 
 /* -----------------------------------------------------------------------------
    A Heap Check in a case alternative are much simpler: everything is
@@ -177,7 +176,6 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 
 #define STK_CHK_NP(headroom,ptrs,tag_assts)                    \
        if ((Sp - (headroom)) < SpLim) {                        \
-           EXTFUN_RTS(stg_gc_enter_##ptrs);                    \
             tag_assts                                          \
            JMP_(stg_gc_enter_##ptrs);                          \
        }
@@ -185,26 +183,26 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 #define HP_CHK_NP(headroom,ptrs,tag_assts)                     \
         DO_GRAN_ALLOCATE(headroom)                              \
        if ((Hp += (headroom)) > HpLim) {                       \
-           EXTFUN_RTS(stg_gc_enter_##ptrs);                    \
+            HpAlloc = (headroom);                              \
             tag_assts                                          \
            JMP_(stg_gc_enter_##ptrs);                          \
-       }
+       }                                                       
 
 #define HP_CHK_SEQ_NP(headroom,ptrs,tag_assts)                 \
         DO_GRAN_ALLOCATE(headroom)                              \
        if ((Hp += (headroom)) > HpLim) {                       \
-           EXTFUN_RTS(stg_gc_seq_##ptrs);                      \
+            HpAlloc = (headroom);                              \
             tag_assts                                          \
            JMP_(stg_gc_seq_##ptrs);                            \
-       }
+       }                                                       
 
 #define HP_STK_CHK_NP(stk_headroom, hp_headroom, ptrs, tag_assts) \
         DO_GRAN_ALLOCATE(hp_headroom)                              \
        if ((Sp - (stk_headroom)) < SpLim || (Hp += (hp_headroom)) > HpLim) { \
-           EXTFUN_RTS(stg_gc_enter_##ptrs);                    \
+            HpAlloc = (hp_headroom);                           \
             tag_assts                                          \
            JMP_(stg_gc_enter_##ptrs);                          \
-       }
+       }                                                       
 
 
 /* Heap checks for branches of a primitive case / unboxed tuple return */
@@ -213,9 +211,10 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
         DO_GRAN_ALLOCATE(headroom)                              \
        if ((Hp += (headroom)) > HpLim) {                       \
            EXTFUN_RTS(lbl);                                    \
+            HpAlloc = (headroom);                              \
             tag_assts                                          \
            JMP_(lbl);                                          \
-       }
+       }                                                       
 
 #define HP_CHK_NOREGS(headroom,tag_assts) \
     GEN_HP_CHK_ALT(headroom,stg_gc_noregs,tag_assts);
@@ -229,7 +228,7 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
     GEN_HP_CHK_ALT(headroom,stg_gc_d1,tag_assts);
 
 #define HP_CHK_L1(headroom,tag_assts)       \
-    GEN_HP_CHK_ALT(headroom,stg_gc_d1,tag_assts);
+    GEN_HP_CHK_ALT(headroom,stg_gc_l1,tag_assts);
 
 #define HP_CHK_UT_ALT(headroom, ptrs, nptrs, r, ret, tag_assts) \
     GEN_HP_CHK_ALT(headroom, stg_gc_ut_##ptrs##_##nptrs, \
@@ -294,12 +293,12 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 
 #define HP_CHK_GEN(headroom,liveness,reentry,tag_assts)        \
    if ((Hp += (headroom)) > HpLim ) {                  \
-       EXTFUN_RTS(stg_gen_chk);                                \
+        HpAlloc = (headroom);                          \
         tag_assts                                      \
        R9.w = (W_)LIVENESS_MASK(liveness);             \
         R10.w = (W_)reentry;                           \
         JMP_(stg_gen_chk);                             \
-   }
+    }                                                       
 
 #define HP_CHK_GEN_TICKY(headroom,liveness,reentry,tag_assts)  \
    HP_CHK_GEN(headroom,liveness,reentry,tag_assts);            \
@@ -307,7 +306,6 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 
 #define STK_CHK_GEN(headroom,liveness,reentry,tag_assts)       \
    if ((Sp - (headroom)) < SpLim) {                            \
-       EXTFUN_RTS(stg_gen_chk);                                        \
         tag_assts                                              \
        R9.w = (W_)LIVENESS_MASK(liveness);                     \
         R10.w = (W_)reentry;                                   \
@@ -316,7 +314,6 @@ static inline int IS_ARG_TAG( StgWord p ) { return p <= ARGTAG_MAX; }
 
 #define MAYBE_GC(liveness,reentry)             \
    if (doYouWantToGC()) {                      \
-       EXTFUN_RTS(stg_gen_hp);                 \
        R9.w = (W_)LIVENESS_MASK(liveness);     \
         R10.w = (W_)reentry;                   \
         JMP_(stg_gen_hp);                      \
@@ -413,8 +410,8 @@ EXTINFO_RTS(stg_gen_chk_info);
         TICK_UPD_BH_UPDATABLE();                               \
         {                                                      \
          bdescr *bd = Bdescr(R1.p);                            \
-          if (bd->back != (bdescr *)BaseReg) {                 \
-             if (bd->gen->no >= 1 || bd->step->no >= 1) {      \
+          if (bd->u.back != (bdescr *)BaseReg) {               \
+             if (bd->gen_no >= 1 || bd->step->no >= 1) {       \
                 LOCK_THUNK(info);                              \
              } else {                                          \
                 EXTFUN_RTS(stg_gc_enter_1_hponly);             \
@@ -422,13 +419,13 @@ EXTINFO_RTS(stg_gen_chk_info);
              }                                                 \
           }                                                    \
        }                                                       \
-        SET_INFO(R1.cl,&BLACKHOLE_info)
+        SET_INFO(R1.cl,&stg_BLACKHOLE_info)
 #    define UPD_BH_SINGLE_ENTRY(info)                          \
         TICK_UPD_BH_SINGLE_ENTRY();                            \
         {                                                      \
          bdescr *bd = Bdescr(R1.p);                            \
-          if (bd->back != (bdescr *)BaseReg) {                 \
-             if (bd->gen->no >= 1 || bd->step->no >= 1) {      \
+          if (bd->u.back != (bdescr *)BaseReg) {               \
+             if (bd->gen_no >= 1 || bd->step->no >= 1) {       \
                 LOCK_THUNK(info);                              \
              } else {                                          \
                 EXTFUN_RTS(stg_gc_enter_1_hponly);             \
@@ -436,14 +433,31 @@ EXTINFO_RTS(stg_gen_chk_info);
              }                                                 \
           }                                                    \
        }                                                       \
-        SET_INFO(R1.cl,&BLACKHOLE_info)
+        SET_INFO(R1.cl,&stg_BLACKHOLE_info)
 #  else
+#   ifndef PROFILING
+#    define UPD_BH_UPDATABLE(info)             \
+        TICK_UPD_BH_UPDATABLE();               \
+        SET_INFO(R1.cl,&stg_BLACKHOLE_info)
+#    define UPD_BH_SINGLE_ENTRY(info)          \
+        TICK_UPD_BH_SINGLE_ENTRY();            \
+        SET_INFO(R1.cl,&stg_SE_BLACKHOLE_info)
+#   else
+// An object is replaced by a blackhole, so we fill the slop with zeros.
+// 
+// Todo: maybe use SET_HDR() and remove LDV_recordCreate()?
+// 
 #    define UPD_BH_UPDATABLE(info)             \
         TICK_UPD_BH_UPDATABLE();               \
-        SET_INFO(R1.cl,&BLACKHOLE_info)
+        LDV_recordDead_FILL_SLOP_DYNAMIC(R1.cl);               \
+        SET_INFO(R1.cl,&stg_BLACKHOLE_info);    \
+        LDV_recordCreate(R1.cl)
 #    define UPD_BH_SINGLE_ENTRY(info)          \
         TICK_UPD_BH_SINGLE_ENTRY();            \
-        SET_INFO(R1.cl,&SE_BLACKHOLE_info)
+        LDV_recordDead_FILL_SLOP_DYNAMIC(R1.cl);               \
+        SET_INFO(R1.cl,&stg_SE_BLACKHOLE_info)  \
+        LDV_recordCreate(R1.cl)
+#   endif /* PROFILING */
 #  endif
 #else /* !EAGER_BLACKHOLING */
 #  define UPD_BH_UPDATABLE(thunk)    /* nothing */
@@ -611,13 +625,36 @@ static inline StgInt64 PK_Int64(W_ p_src[])
     y.iu.dlo = p_src[1];
     return(y.i);
 }
+
+#elif SIZEOF_VOID_P == 8
+
+static inline void ASSIGN_Word64(W_ p_dest[], StgWord64 src)
+{
+       p_dest[0] = src;
+}
+
+static inline StgWord64 PK_Word64(W_ p_src[])
+{
+    return p_src[0];
+}
+
+static inline void ASSIGN_Int64(W_ p_dest[], StgInt64 src)
+{
+    p_dest[0] = src;
+}
+
+static inline StgInt64 PK_Int64(W_ p_src[])
+{
+    return p_src[0];
+}
+
 #endif
 
 /* -----------------------------------------------------------------------------
    Catch frames
    -------------------------------------------------------------------------- */
 
-extern DLL_IMPORT_DATA const StgPolyInfoTable catch_frame_info;
+extern DLL_IMPORT_RTS const StgPolyInfoTable stg_catch_frame_info;
 
 /* -----------------------------------------------------------------------------
    Seq frames
@@ -626,14 +663,14 @@ extern DLL_IMPORT_DATA const StgPolyInfoTable catch_frame_info;
    an update...
    -------------------------------------------------------------------------- */
 
-extern DLL_IMPORT_DATA const StgPolyInfoTable seq_frame_info;
+extern DLL_IMPORT_RTS const StgPolyInfoTable stg_seq_frame_info;
 
 #define PUSH_SEQ_FRAME(sp)                                     \
        {                                                       \
                StgSeqFrame *__frame;                           \
                TICK_SEQF_PUSHED();                             \
                __frame = (StgSeqFrame *)(sp);                  \
-               SET_HDR_(__frame,&seq_frame_info,CCCS);         \
+               SET_HDR((StgClosure *)__frame,(StgInfoTable *)&stg_seq_frame_info,CCCS);\
                __frame->link = Su;                             \
                Su = (StgUpdateFrame *)__frame;                 \
        }
@@ -643,7 +680,11 @@ extern DLL_IMPORT_DATA const StgPolyInfoTable seq_frame_info;
    -------------------------------------------------------------------------- */
 
 #if defined(USE_SPLIT_MARKERS)
+#if defined(cygwin32_TARGET_OS) || defined(mingw32_TARGET_OS)
+#define __STG_SPLIT_MARKER __asm__("\n___stg_split_marker:");
+#else
 #define __STG_SPLIT_MARKER __asm__("\n__stg_split_marker:");
+#endif
 #else
 #define __STG_SPLIT_MARKER /* nothing */
 #endif
@@ -652,11 +693,20 @@ extern DLL_IMPORT_DATA const StgPolyInfoTable seq_frame_info;
    Closure and Info Macros with casting.
 
    We don't want to mess around with casts in the generated C code, so
-   we use these casting versions of the closure/info tables macros.
+   we use this casting versions of the closure macro.
+
+   This version of SET_HDR also includes CCS_ALLOC for profiling - the
+   reason we don't use two separate macros is that the cost centre
+   field is sometimes a non-simple expression and we want to share its
+   value between SET_HDR and CCS_ALLOC.
    -------------------------------------------------------------------------- */
 
-#define SET_HDR_(c,info,ccs) \
-   SET_HDR((StgClosure *)(c),(StgInfoTable *)(info),ccs)
+#define SET_HDR_(c,info,ccs,size)                              \
+  {                                                            \
+      CostCentreStack *tmp = (ccs);                            \
+      SET_HDR((StgClosure *)(c),(StgInfoTable *)(info),tmp);   \
+      CCS_ALLOC(tmp,size);                                     \
+  }
 
 /* -----------------------------------------------------------------------------
    Saving context for exit from the STG world, and loading up context
@@ -760,7 +810,7 @@ LoadThreadState (void)
  * Suspending/resuming threads for doing external C-calls (_ccall_GC).
  * These functions are defined in rts/Schedule.c.
  */
-StgInt        suspendThread ( StgRegTable *cap );
+StgInt        suspendThread ( StgRegTable * );
 StgRegTable * resumeThread  ( StgInt );
 
 #define SUSPEND_THREAD(token)                  \
@@ -768,9 +818,9 @@ StgRegTable * resumeThread  ( StgInt );
    token = suspendThread(BaseReg);
 
 #ifdef SMP
-#define RESUME_THREAD(token)                   \
-   BaseReg = resumeThread(token);              \
-   LoadThreadState();
+#define RESUME_THREAD(token)                   \
+    BaseReg = resumeThread(token);             \
+    LoadThreadState();
 #else
 #define RESUME_THREAD(token)                   \
    (void)resumeThread(token);                  \