2 -- The above warning supression flag is a temporary kludge.
3 -- While working on this module you are encouraged to remove it and fix
4 -- any warnings in the module. See
5 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
9 -- (c) The University of Glasgow 2003-2006
12 -- Functions for constructing bitmaps, which are used in various
13 -- places in generated code (stack frame liveness masks, function
14 -- argument liveness masks, SRT bitmaps).
18 intsToBitmap, intsToReverseBitmap,
19 mAX_SMALL_BITMAP_SIZE,
23 #include "HsVersions.h"
24 #include "../includes/MachDeps.h"
33 A bitmap represented by a sequence of 'StgWord's on the /target/
34 architecture. These are used for bitmaps in info tables and other
35 generated code which need to be emitted as sequences of StgWords.
37 type Bitmap = [StgWord]
39 -- | Make a bitmap from a sequence of bits
40 mkBitmap :: [Bool] -> Bitmap
42 mkBitmap stuff = chunkToBitmap chunk : mkBitmap rest
43 where (chunk, rest) = splitAt wORD_SIZE_IN_BITS stuff
45 chunkToBitmap :: [Bool] -> StgWord
47 foldr (.|.) 0 [ 1 `shiftL` n | (True,n) <- zip chunk [0..] ]
49 -- | Make a bitmap where the slots specified are the /ones/ in the bitmap.
50 -- eg. @[0,1,3], size 4 ==> 0xb@.
52 -- The list of @Int@s /must/ be already sorted.
53 intsToBitmap :: Int -> [Int] -> Bitmap
54 intsToBitmap size slots{- must be sorted -}
57 (foldr (.|.) 0 (map (1 `shiftL`) these)) :
58 intsToBitmap (size - wORD_SIZE_IN_BITS)
59 (map (\x -> x - wORD_SIZE_IN_BITS) rest)
60 where (these,rest) = span (<wORD_SIZE_IN_BITS) slots
62 -- | Make a bitmap where the slots specified are the /zeros/ in the bitmap.
63 -- eg. @[0,1,3], size 4 ==> 0x4@ (we leave any bits outside the size as zero,
64 -- just to make the bitmap easier to read).
66 -- The list of @Int@s /must/ be already sorted.
67 intsToReverseBitmap :: Int -> [Int] -> Bitmap
68 intsToReverseBitmap size slots{- must be sorted -}
71 (foldr xor init (map (1 `shiftL`) these)) :
72 intsToReverseBitmap (size - wORD_SIZE_IN_BITS)
73 (map (\x -> x - wORD_SIZE_IN_BITS) rest)
74 where (these,rest) = span (<wORD_SIZE_IN_BITS) slots
76 | size >= wORD_SIZE_IN_BITS = complement 0
77 | otherwise = (1 `shiftL` size) - 1
80 Magic number, must agree with @BITMAP_BITS_SHIFT@ in InfoTables.h.
81 Some kinds of bitmap pack a size\/bitmap into a single word if
82 possible, or fall back to an external pointer when the bitmap is too
83 large. This value represents the largest size of bitmap that can be
84 packed into a single word.
86 mAX_SMALL_BITMAP_SIZE :: Int
87 mAX_SMALL_BITMAP_SIZE | wORD_SIZE == 4 = 27
90 seqBitmap :: Bitmap -> a -> a