Add {-# OPTIONS_GHC -w #-} and some blurb to all compiler modules
[ghc-hetmet.git] / compiler / utils / FastTypes.lhs
1 %
2 % (c) The University of Glasgow, 2000-2006
3 %
4 \section{Fast integers and booleans}
5
6 \begin{code}
7 {-# OPTIONS_GHC -w #-}
8 -- The above warning supression flag is a temporary kludge.
9 -- While working on this module you are encouraged to remove it and fix
10 -- any warnings in the module. See
11 --     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
12 -- for details
13
14 module FastTypes (
15     FastInt, _ILIT, iBox, iUnbox,
16     (+#), (-#), (*#), quotFastInt, negateFastInt,
17     (==#), (<#), (<=#), (>=#), (>#),
18
19     FastBool, fastBool, isFastTrue, fastOr, fastAnd
20   ) where
21
22 #include "HsVersions.h"
23
24 #if defined(__GLASGOW_HASKELL__)
25
26 -- Import the beggars
27 import GHC.Exts
28         ( Int(..), Int#, (+#), (-#), (*#), 
29           quotInt#, negateInt#, (==#), (<#), (<=#), (>=#), (>#)
30         )
31
32 type FastInt = Int#
33 _ILIT (I# x) = x
34 iBox x = I# x
35 iUnbox (I# x) = x
36 quotFastInt   = quotInt#
37 negateFastInt = negateInt#
38
39 type FastBool = Int#
40 fastBool True  = 1#
41 fastBool False = 0#
42 isFastTrue x = x ==# 1#
43
44 -- note that fastOr and fastAnd are strict in both arguments
45 -- since they are unboxed
46 fastOr 1# _ = 1#
47 fastOr 0# x = x
48
49 fastAnd 0# x = 0#
50 fastAnd 1# x = x
51
52 #else /* ! __GLASGOW_HASKELL__ */
53
54 type FastInt = Int
55 _ILIT x = x
56 iBox x = x
57 iUnbox x = x
58 (+#) = (+)
59 (-#) = (-)
60 (*#) = (*)
61 quotFastInt   = quot
62 negateFastInt = negate
63 (==#) = (==)
64 (<#)  = (<)
65 (<=#) = (<=)
66 (>=#) = (>=)
67 (>#)  = (>)
68
69 type FastBool = Bool
70 fastBool x = x
71 isFastTrue x = x
72 -- make sure these are as strict as the unboxed version,
73 -- so that the performance characteristics match
74 fastOr False False = False
75 fastOr _ _ = True
76 fastAnd True True = True
77 fastAnd _ _ = False
78
79 --These are among the type-signatures necessary for !ghc to compile
80 -- but break ghc (can't give a signature for an import...)
81 --Note that the comparisons actually do return Bools not FastBools.
82 (+#) :: FastInt -> FastInt -> FastInt
83 (-#) :: FastInt -> FastInt -> FastInt
84 (*#) :: FastInt -> FastInt -> FastInt
85 (==#) :: FastInt -> FastInt -> Bool
86 (<#) :: FastInt -> FastInt -> Bool
87 (<=#) :: FastInt -> FastInt -> Bool
88 (>=#) :: FastInt -> FastInt -> Bool
89 (>#) :: FastInt -> FastInt -> Bool
90
91 #endif /* ! __GLASGOW_HASKELL__ */
92
93 -- type-signatures will improve the non-ghc-specific versions
94 -- and keep things accurate (and ABLE to compile!)
95 _ILIT :: Int -> FastInt
96 iBox :: FastInt -> Int
97 iUnbox :: Int -> FastInt
98
99 quotFastInt :: FastInt -> FastInt -> FastInt
100 negateFastInt :: FastInt -> FastInt
101
102 fastBool :: Bool -> FastBool
103 isFastTrue :: FastBool -> Bool
104 fastOr :: FastBool -> FastBool -> FastBool
105 fastAnd :: FastBool -> FastBool -> FastBool
106
107 \end{code}