cutils.c 1.03 KB
Newer Older
1 2 3 4 5 6
/*
These utility routines are used various
places in the GHC library.
*/

#include "Rts.h"
Simon Marlow's avatar
Simon Marlow committed
7
#if __GLASGOW_HASKELL__ <= 610
8
#include "RtsFlags.h"
Simon Marlow's avatar
Simon Marlow committed
9
#endif
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

#include "HsFFI.h"

#include <string.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

/*
Calling 'strlen' and 'memcpy' directly gives problems with GCC's inliner,
and causes gcc to require too many registers on x84
*/

HsInt
Simon Marlow's avatar
Simon Marlow committed
25
ghc_strlen( HsPtr a )
26 27 28 29 30
{
    return (strlen((char *)a));
}

HsInt
Simon Marlow's avatar
Simon Marlow committed
31
ghc_memcmp( HsPtr a1, HsPtr a2, HsInt len )
32 33 34 35 36
{
    return (memcmp((char *)a1, a2, len));
}

HsInt
Simon Marlow's avatar
Simon Marlow committed
37
ghc_memcmp_off( HsPtr a1, HsInt i, HsPtr a2, HsInt len )
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
{
    return (memcmp((char *)a1 + i, a2, len));
}

void
enableTimingStats( void )	/* called from the driver */
{
    RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
}

void
setHeapSize( HsInt size )
{
    RtsFlags.GcFlags.heapSizeSuggestion = size / BLOCK_SIZE;
    if (RtsFlags.GcFlags.maxHeapSize != 0 &&
	RtsFlags.GcFlags.heapSizeSuggestion > RtsFlags.GcFlags.maxHeapSize) {
	RtsFlags.GcFlags.maxHeapSize = RtsFlags.GcFlags.heapSizeSuggestion;
    }
}