2 -- (c) The University of Glasgow 2003
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,
15 #include "HsVersions.h"
16 #include "../includes/MachDeps.h"
23 A bitmap represented by a sequence of 'StgWord's on the /target/
24 architecture. These are used for bitmaps in info tables and other
25 generated code which need to be emitted as sequences of StgWords.
27 type Bitmap = [StgWord]
29 -- | Make a bitmap from a sequence of bits
30 mkBitmap :: [Bool] -> Bitmap
32 mkBitmap stuff = chunkToBitmap chunk : mkBitmap rest
33 where (chunk, rest) = splitAt wORD_SIZE_IN_BITS stuff
35 chunkToBitmap :: [Bool] -> StgWord
37 foldr (.|.) 0 [ 1 `shiftL` n | (True,n) <- zip chunk [0..] ]
39 -- | Make a bitmap where the slots specified are the /ones/ in the bitmap.
40 -- eg. @[1,2,4], size 4 ==> 0xb@.
42 -- The list of @Int@s /must/ be already sorted.
43 intsToBitmap :: Int -> [Int] -> Bitmap
44 intsToBitmap size slots{- must be sorted -}
47 (foldr (.|.) 0 (map (1 `shiftL`) these)) :
48 intsToBitmap (size - wORD_SIZE_IN_BITS)
49 (map (\x -> x - wORD_SIZE_IN_BITS) rest)
50 where (these,rest) = span (<wORD_SIZE_IN_BITS) slots
52 -- | Make a bitmap where the slots specified are the /zeros/ in the bitmap.
53 -- eg. @[1,2,4], size 4 ==> 0x8@ (we leave any bits outside the size as zero,
54 -- just to make the bitmap easier to read).
56 -- The list of @Int@s /must/ be already sorted.
57 intsToReverseBitmap :: Int -> [Int] -> Bitmap
58 intsToReverseBitmap size slots{- must be sorted -}
61 (foldr xor init (map (1 `shiftL`) these)) :
62 intsToReverseBitmap (size - wORD_SIZE_IN_BITS)
63 (map (\x -> x - wORD_SIZE_IN_BITS) rest)
64 where (these,rest) = span (<wORD_SIZE_IN_BITS) slots
66 | size >= wORD_SIZE_IN_BITS = complement 0
67 | otherwise = (1 `shiftL` size) - 1
70 Magic number, must agree with @BITMAP_BITS_SHIFT@ in InfoTables.h.
71 Some kinds of bitmap pack a size/bitmap into a single word if
72 possible, or fall back to an external pointer when the bitmap is too
73 large. This value represents the largest size of bitmap that can be
74 packed into a single word.
76 mAX_SMALL_BITMAP_SIZE :: Int
77 mAX_SMALL_BITMAP_SIZE | wORD_SIZE == 4 = 27