From 3160a6546bf6e57d0d5ef7bc084fcbcb10297ff6 Mon Sep 17 00:00:00 2001 From: wolfgang Date: Wed, 10 Nov 2004 02:13:16 +0000 Subject: [PATCH] [project @ 2004-11-10 02:13:12 by wolfgang] 64-bit fixes. Don't assume that sizeof(int) == sizeof(StgInt). This assumption creeped in in many places since 6.2. --- ghc/includes/Cmm.h | 12 +++++++--- ghc/includes/TSO.h | 6 ++--- ghc/includes/Updates.h | 6 ++--- ghc/rts/HeapStackCheck.cmm | 2 +- ghc/rts/Itimer.c | 7 +++--- ghc/rts/Itimer.h | 2 +- ghc/rts/PrimOps.cmm | 57 +++++++++++++++++++++++--------------------- ghc/rts/ProfHeap.c | 2 +- 8 files changed, 52 insertions(+), 42 deletions(-) diff --git a/ghc/includes/Cmm.h b/ghc/includes/Cmm.h index 0dde2c8..486df2f 100644 --- a/ghc/includes/Cmm.h +++ b/ghc/includes/Cmm.h @@ -97,7 +97,7 @@ #if SIZEOF_INT == 4 #define CInt bits32 -#elif SIZEOF_INT = 8 +#elif SIZEOF_INT == 8 #define CInt bits64 #else #error Unknown int size @@ -105,7 +105,7 @@ #if SIZEOF_LONG == 4 #define CLong bits32 -#elif SIZEOF_LONG = 8 +#elif SIZEOF_LONG == 8 #define CLong bits64 #else #error Unknown long size @@ -163,6 +163,12 @@ #define HALF_W_(x) %lobits32(x) #endif +#if SIZEOF_INT == 4 && SIZEOF_W == 8 +#define W_TO_INT(x) %lobits32(x) +#elif SIZEOF_INT == SIZEOF_W +#define W_TO_INT(x) (x) +#endif + /* ----------------------------------------------------------------------------- Heap/stack access, and adjusting the heap/stack pointers. -------------------------------------------------------------------------- */ @@ -307,7 +313,7 @@ TICK_ALLOC_HEAP_NOCTR(alloc); #define MAYBE_GC(liveness,reentry) \ - if (CInt[alloc_blocks] >= CInt[alloc_blocks_lim]) { \ + if (W_[alloc_blocks] >= W_[alloc_blocks_lim]) { \ R9 = liveness; \ R10 = reentry; \ jump stg_gc_gen_hp; \ diff --git a/ghc/includes/TSO.h b/ghc/includes/TSO.h index 8592cb8..958527c 100644 --- a/ghc/includes/TSO.h +++ b/ghc/includes/TSO.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: TSO.h,v 1.37 2004/11/08 12:26:57 simonmar Exp $ + * $Id: TSO.h,v 1.38 2004/11/10 02:13:12 wolfgang Exp $ * * (c) The GHC Team, 1998-1999 * @@ -97,11 +97,11 @@ typedef struct { typedef union { StgClosure *closure; struct StgTSO_ *tso; - int fd; + StgInt fd; // StgInt instead of int, so that it's the same size as the ptrs #if defined(mingw32_TARGET_OS) StgAsyncIOResult* async_result; #endif - unsigned int target; + StgWord target; } StgTSOBlockInfo; /* diff --git a/ghc/includes/Updates.h b/ghc/includes/Updates.h index 68241d7..37b8ecc 100644 --- a/ghc/includes/Updates.h +++ b/ghc/includes/Updates.h @@ -238,7 +238,7 @@ extern void awakenBlockedQueue(StgBlockingQueueElement *q, StgClosure *node); inf = %GET_STD_INFO(p); \ np = TO_W_(%INFO_PTRS(inf)); \ nw = TO_W_(%INFO_NPTRS(inf)); \ - if (%INFO_TYPE(inf) != THUNK_SELECTOR::I16) { \ + if (%INFO_TYPE(inf) != HALF_W_(THUNK_SELECTOR)) { \ i = 0; \ for: \ if (i < np + nw) { \ @@ -285,7 +285,7 @@ DEBUG_FILL_SLOP(StgClosure *p) /* ASSERT( p1 != p2 && !closure_IND(p1) ); \ */ LDV_RECORD_DEAD_FILL_SLOP_DYNAMIC(p1); \ bd = Bdescr(p1); \ - if (bdescr_gen_no(bd) == 0) { \ + if (bdescr_gen_no(bd) == 0 :: CInt) { \ StgInd_indirectee(p1) = p2; \ SET_INFO(p1, ind_info); \ LDV_RECORD_CREATE(p1); \ @@ -295,7 +295,7 @@ DEBUG_FILL_SLOP(StgClosure *p) if (info != stg_BLACKHOLE_BQ_info) { \ DEBUG_FILL_SLOP(p1); \ W_ __mut_once_list; \ - __mut_once_list = generation(bdescr_gen_no(bd)) + \ + __mut_once_list = generation(TO_W_(bdescr_gen_no(bd))) + \ OFFSET_generation_mut_once_list; \ StgMutClosure_mut_link(p1) = W_[__mut_once_list]; \ W_[__mut_once_list] = p1; \ diff --git a/ghc/rts/HeapStackCheck.cmm b/ghc/rts/HeapStackCheck.cmm index 7a0828b..a0322cb 100644 --- a/ghc/rts/HeapStackCheck.cmm +++ b/ghc/rts/HeapStackCheck.cmm @@ -55,7 +55,7 @@ CLOSE_NURSERY(); \ CurrentNursery = bdescr_link(CurrentNursery); \ OPEN_NURSERY(); \ - if (CInt[context_switch] != 0) { \ + if (CInt[context_switch] != 0 :: CInt) { \ R1 = ThreadYielding; \ goto sched; \ } else { \ diff --git a/ghc/rts/Itimer.c b/ghc/rts/Itimer.c index 1f98659..50be88d 100644 --- a/ghc/rts/Itimer.c +++ b/ghc/rts/Itimer.c @@ -196,12 +196,13 @@ unblock_vtalrm_signal(void) /* gettimeofday() takes around 1us on our 500MHz PIII. Since we're * only calling it 50 times/s, it shouldn't have any great impact. */ -unsigned int +nat getourtimeofday(void) { struct timeval tv; gettimeofday(&tv, (struct timezone *) NULL); - return (tv.tv_sec * TICK_FREQUENCY + - tv.tv_usec * TICK_FREQUENCY / 1000000); + // cast to nat because nat may be 64 bit when int is only 32 bit + return ((nat)tv.tv_sec * TICK_FREQUENCY + + (nat)tv.tv_usec * TICK_FREQUENCY / 1000000); } diff --git a/ghc/rts/Itimer.h b/ghc/rts/Itimer.h index 8eca9da..47fbbb6 100644 --- a/ghc/rts/Itimer.h +++ b/ghc/rts/Itimer.h @@ -11,7 +11,7 @@ extern int startTicker( nat ms, TickProc handle_tick); extern int stopTicker ( void ); -extern unsigned int getourtimeofday ( void ); +extern nat getourtimeofday ( void ); #if 0 /* unused */ extern void block_vtalrm_signal ( void ); diff --git a/ghc/rts/PrimOps.cmm b/ghc/rts/PrimOps.cmm index 9f69d16..16a3d17 100644 --- a/ghc/rts/PrimOps.cmm +++ b/ghc/rts/PrimOps.cmm @@ -538,20 +538,21 @@ section "bss" { #define GMP_TAKE2_RET1(name,mp_fun) \ name \ { \ - W_ s1, s2, d1, d2; \ + CInt s1, s2; \ + W_ d1, d2; \ \ /* call doYouWantToGC() */ \ MAYBE_GC(R2_PTR & R4_PTR, name); \ \ - s1 = R1; \ + s1 = W_TO_INT(R1); \ d1 = R2; \ - s2 = R3; \ + s2 = W_TO_INT(R3); \ d2 = R4; \ \ - MP_INT__mp_alloc(mp_tmp1) = StgArrWords_words(d1); \ + MP_INT__mp_alloc(mp_tmp1) = W_TO_INT(StgArrWords_words(d1)); \ MP_INT__mp_size(mp_tmp1) = (s1); \ MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(d1); \ - MP_INT__mp_alloc(mp_tmp2) = StgArrWords_words(d2); \ + MP_INT__mp_alloc(mp_tmp2) = W_TO_INT(StgArrWords_words(d2)); \ MP_INT__mp_size(mp_tmp2) = (s2); \ MP_INT__mp_d(mp_tmp2) = BYTE_ARR_CTS(d2); \ \ @@ -560,22 +561,23 @@ name \ /* Perform the operation */ \ foreign "C" mp_fun(result1,mp_tmp1,mp_tmp2); \ \ - RET_NP(MP_INT__mp_size(result1), \ + RET_NP(TO_W_(MP_INT__mp_size(result1)), \ MP_INT__mp_d(result1) - SIZEOF_StgArrWords); \ } #define GMP_TAKE1_RET1(name,mp_fun) \ name \ { \ - W_ s1, d1; \ + CInt s1; \ + W_ d1; \ \ /* call doYouWantToGC() */ \ MAYBE_GC(R2_PTR, name); \ \ d1 = R2; \ - s1 = R1; \ + s1 = W_TO_INT(R1); \ \ - MP_INT__mp_alloc(mp_tmp1) = StgArrWords_words(d1); \ + MP_INT__mp_alloc(mp_tmp1) = W_TO_INT(StgArrWords_words(d1)); \ MP_INT__mp_size(mp_tmp1) = (s1); \ MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(d1); \ \ @@ -584,27 +586,28 @@ name \ /* Perform the operation */ \ foreign "C" mp_fun(result1,mp_tmp1); \ \ - RET_NP(MP_INT__mp_size(result1), \ + RET_NP(TO_W_(MP_INT__mp_size(result1)), \ MP_INT__mp_d(result1) - SIZEOF_StgArrWords); \ } #define GMP_TAKE2_RET2(name,mp_fun) \ name \ { \ - W_ s1, s2, d1, d2; \ + CInt s1, s2; \ + W_ d1, d2; \ \ /* call doYouWantToGC() */ \ MAYBE_GC(R2_PTR & R4_PTR, name); \ \ - s1 = R1; \ + s1 = W_TO_INT(R1); \ d1 = R2; \ - s2 = R3; \ + s2 = W_TO_INT(R3); \ d2 = R4; \ \ - MP_INT__mp_alloc(mp_tmp1) = StgArrWords_words(d1); \ + MP_INT__mp_alloc(mp_tmp1) = W_TO_INT(StgArrWords_words(d1)); \ MP_INT__mp_size(mp_tmp1) = (s1); \ MP_INT__mp_d(mp_tmp1) = BYTE_ARR_CTS(d1); \ - MP_INT__mp_alloc(mp_tmp2) = StgArrWords_words(d2); \ + MP_INT__mp_alloc(mp_tmp2) = W_TO_INT(StgArrWords_words(d2)); \ MP_INT__mp_size(mp_tmp2) = (s2); \ MP_INT__mp_d(mp_tmp2) = BYTE_ARR_CTS(d2); \ \ @@ -614,9 +617,9 @@ name \ /* Perform the operation */ \ foreign "C" mp_fun(result1,result2,mp_tmp1,mp_tmp2); \ \ - RET_NPNP(MP_INT__mp_size(result1), \ + RET_NPNP(TO_W_(MP_INT__mp_size(result1)), \ MP_INT__mp_d(result1) - SIZEOF_StgArrWords, \ - MP_INT__mp_size(result2), \ + TO_W_(MP_INT__mp_size(result2)), \ MP_INT__mp_d(result2) - SIZEOF_StgArrWords); \ } @@ -739,12 +742,12 @@ cmpIntegerzh_fast cmp = foreign "C" mpn_cmp(up "ptr", vp "ptr", size); - if (cmp == 0) { + if (cmp == 0 :: CInt) { R1 = 0; jump %ENTRY_CODE(Sp(0)); } - if (%lt(cmp,0) == %lt(usize,0)) { + if (%lt(cmp,0 :: CInt) == %lt(usize,0)) { R1 = 1; } else { R1 = (-1); @@ -816,7 +819,7 @@ decodeFloatzh_fast foreign "C" __decodeFloat(mp_tmp1,exponent,arg); /* returns: (Int# (expn), Int#, ByteArray#) */ - RET_NNP(W_[exponent], MP_INT__mp_size(mp_tmp1), p); + RET_NNP(W_[exponent], TO_W_(MP_INT__mp_size(mp_tmp1)), p); } #define DOUBLE_MANTISSA_SIZE SIZEOF_DOUBLE @@ -843,7 +846,7 @@ decodeDoublezh_fast foreign "C" __decodeDouble(mp_tmp1,exponent,arg); /* returns: (Int# (expn), Int#, ByteArray#) */ - RET_NNP(W_[exponent], MP_INT__mp_size(mp_tmp1), p); + RET_NNP(W_[exponent], TO_W_(MP_INT__mp_size(mp_tmp1)), p); } /* ----------------------------------------------------------------------------- @@ -862,7 +865,7 @@ forkzh_fast foreign "C" scheduleThread(R1 "ptr"); // switch at the earliest opportunity - CInt[context_switch] = 1; + CInt[context_switch] = 1 :: CInt; RET_P(R1); } @@ -1307,8 +1310,8 @@ mkApUpd0zh_fast // This function is *only* used to wrap zero-arity BCOs in an // updatable wrapper (see ByteCodeLink.lhs). An AP thunk is always // saturated and always points directly to a FUN or BCO. - ASSERT(%INFO_TYPE(%GET_STD_INFO(R1)) == BCO::I16 && - StgBCO_arity(R1) == 0::I16); + ASSERT(%INFO_TYPE(%GET_STD_INFO(R1)) == HALF_W_(BCO) && + StgBCO_arity(R1) == HALF_W_(0)); HP_CHK_GEN_TICKY(SIZEOF_StgAP, R1_PTR, mkApUpd0zh_fast); TICK_ALLOC_UP_THK(0, 0); @@ -1317,7 +1320,7 @@ mkApUpd0zh_fast ap = Hp - SIZEOF_StgAP + WDS(1); SET_HDR(ap, stg_AP_info, W_[CCCS]); - StgAP_n_args(ap) = 0::I16; + StgAP_n_args(ap) = HALF_W_(0); StgAP_fun(ap) = R1; RET_P(ap); @@ -1411,9 +1414,9 @@ delayzh_fast #else - CInt time; + W_ time; time = foreign "C" getourtimeofday(); - target = (R1 / (TICK_MILLISECS*1000)) + TO_W_(time); + target = (R1 / (TICK_MILLISECS*1000)) + time; StgTSO_block_info(CurrentTSO) = target; /* Insert the new thread in the sleeping queue. */ diff --git a/ghc/rts/ProfHeap.c b/ghc/rts/ProfHeap.c index 4e9e7f8..932c069 100644 --- a/ghc/rts/ProfHeap.c +++ b/ghc/rts/ProfHeap.c @@ -46,7 +46,7 @@ * When era reaches max_era, the profiling stops because a closure can * store only up to (max_era - 1) as its creation or last use time. * -------------------------------------------------------------------------- */ -nat era; +unsigned int era; static nat max_era; /* ----------------------------------------------------------------------------- -- 1.7.10.4