Fix warnings in utils/FastTypes
[ghc-hetmet.git] / compiler / utils / FastBool.lhs
1 %
2 % (c) The University of Glasgow, 2000-2006
3 %
4 \section{Fast booleans}
5
6 \begin{code}
7 module FastBool (
8     FastBool, fastBool, isFastTrue, fastOr, fastAnd
9   ) where
10
11 #if defined(__GLASGOW_HASKELL__)
12
13 -- Import the beggars
14 import GHC.Exts
15         ( Int(..), Int#, (+#), (-#), (*#), 
16           quotInt#, negateInt#, (==#), (<#), (<=#), (>=#), (>#)
17         )
18 import Panic
19
20 type FastBool = Int#
21 fastBool True  = 1#
22 fastBool False = 0#
23 isFastTrue x = x ==# 1#
24
25 -- note that fastOr and fastAnd are strict in both arguments
26 -- since they are unboxed
27 fastOr 1# _ = 1#
28 fastOr 0# x = x
29 fastOr _  _ = panic# "FastTypes: fastOr"
30
31 fastAnd 0# _ = 0#
32 fastAnd 1# x = x
33 fastAnd _  _ = panic# "FastTypes: fastAnd"
34
35 #else /* ! __GLASGOW_HASKELL__ */
36
37 type FastBool = Bool
38 fastBool x = x
39 isFastTrue x = x
40 -- make sure these are as strict as the unboxed version,
41 -- so that the performance characteristics match
42 fastOr False False = False
43 fastOr _ _ = True
44 fastAnd True True = True
45 fastAnd _ _ = False
46
47 #endif /* ! __GLASGOW_HASKELL__ */
48
49 fastBool :: Bool -> FastBool
50 isFastTrue :: FastBool -> Bool
51 fastOr :: FastBool -> FastBool -> FastBool
52 fastAnd :: FastBool -> FastBool -> FastBool
53
54 \end{code}