2 -- (c) The University of Glasgow 2003-2006
5 -- Functions for constructing bitmaps, which are used in various
6 -- places in generated code (stack frame liveness masks, function
7 -- argument liveness masks, SRT bitmaps).
11 intsToBitmap, intsToReverseBitmap,
12 mAX_SMALL_BITMAP_SIZE,
16 #include "HsVersions.h"
17 #include "../includes/MachDeps.h"
26 A bitmap represented by a sequence of 'StgWord's on the /target/
27 architecture. These are used for bitmaps in info tables and other
28 generated code which need to be emitted as sequences of StgWords.
30 type Bitmap = [StgWord]
32 -- | Make a bitmap from a sequence of bits
33 mkBitmap :: [Bool] -> Bitmap
35 mkBitmap stuff = chunkToBitmap chunk : mkBitmap rest
36 where (chunk, rest) = splitAt wORD_SIZE_IN_BITS stuff
38 chunkToBitmap :: [Bool] -> StgWord
40 foldr (.|.) 0 [ 1 `shiftL` n | (True,n) <- zip chunk [0..] ]
42 -- | Make a bitmap where the slots specified are the /ones/ in the bitmap.
43 -- eg. @[0,1,3], size 4 ==> 0xb@.
45 -- The list of @Int@s /must/ be already sorted.
46 intsToBitmap :: Int -> [Int] -> Bitmap
47 intsToBitmap size slots{- must be sorted -}
50 (foldr (.|.) 0 (map (1 `shiftL`) these)) :
51 intsToBitmap (size - wORD_SIZE_IN_BITS)
52 (map (\x -> x - wORD_SIZE_IN_BITS) rest)
53 where (these,rest) = span (<wORD_SIZE_IN_BITS) slots
55 -- | Make a bitmap where the slots specified are the /zeros/ in the bitmap.
56 -- eg. @[0,1,3], size 4 ==> 0x4@ (we leave any bits outside the size as zero,
57 -- just to make the bitmap easier to read).
59 -- The list of @Int@s /must/ be already sorted.
60 intsToReverseBitmap :: Int -> [Int] -> Bitmap
61 intsToReverseBitmap size slots{- must be sorted -}
64 (foldr xor init (map (1 `shiftL`) these)) :
65 intsToReverseBitmap (size - wORD_SIZE_IN_BITS)
66 (map (\x -> x - wORD_SIZE_IN_BITS) rest)
67 where (these,rest) = span (<wORD_SIZE_IN_BITS) slots
69 | size >= wORD_SIZE_IN_BITS = complement 0
70 | otherwise = (1 `shiftL` size) - 1
73 Magic number, must agree with @BITMAP_BITS_SHIFT@ in InfoTables.h.
74 Some kinds of bitmap pack a size\/bitmap into a single word if
75 possible, or fall back to an external pointer when the bitmap is too
76 large. This value represents the largest size of bitmap that can be
77 packed into a single word.
79 mAX_SMALL_BITMAP_SIZE :: Int
80 mAX_SMALL_BITMAP_SIZE | wORD_SIZE == 4 = 27
83 seqBitmap :: Bitmap -> a -> a