Prepare dph for a vectInfoVar type change
[packages/dph.git] / dph-lifted-copy / Data / Array / Parallel / Prelude / Word8.hs
1 {-# OPTIONS_GHC -fvectorise #-}
2
3 module Data.Array.Parallel.Prelude.Word8 (
4 Word8,
5
6 -- Ord
7 (==), (/=), (<), (<=), (>), (>=), min, max,
8
9 minimumP, maximumP, minIndexP, maxIndexP,
10
11 -- Num
12 (+), (-), (*), negate, abs,
13
14 sumP, productP,
15
16 -- Integral
17 div, mod, sqrt,
18
19 toInt, fromInt
20 ) where
21
22 import Data.Array.Parallel.Prim () -- dependency required by the vectoriser
23
24 import Data.Array.Parallel.Prelude.Base
25
26 import Data.Array.Parallel.PArr
27 import Data.Array.Parallel.Lifted.Scalar
28 import Data.Array.Parallel.Lifted.Closure
29
30 import qualified Prelude as P
31 import Prelude (Int)
32
33 import Data.Word (Word8)
34
35
36 infixl 7 *
37 infixl 6 +, -
38 infix 4 ==, /=, <, <=, >, >=
39 infixl 7 `div`, `mod`
40
41
42 (==), (/=), (<), (<=), (>), (>=) :: Word8 -> Word8 -> Bool
43 (==) = (P.==)
44 (/=) = (P./=)
45 (<=) = (P.<=)
46 (<) = (P.<)
47 (>=) = (P.>=)
48 (>) = (P.>)
49
50 min, max :: Word8 -> Word8 -> Word8
51 min = P.min
52 max = P.max
53
54 minimumP, maximumP :: PArr Word8 -> Word8
55 {-# NOINLINE minimumP #-}
56 minimumP a = a `indexPArr` 0
57 {-# VECTORISE minimumP = minimumP_v #-}
58 {-# NOINLINE maximumP #-}
59 maximumP a = a `indexPArr` 0
60 {-# VECTORISE maximumP = maximumP_v #-}
61
62 minimumP_v, maximumP_v:: PArray Word8 :-> Word8
63 {-# INLINE minimumP_v #-}
64 minimumP_v = closure1 (scalar_fold1 P.min) (scalar_fold1s P.min)
65 {-# NOVECTORISE minimumP_v #-}
66 {-# INLINE maximumP_v #-}
67 maximumP_v = closure1 (scalar_fold1 P.max) (scalar_fold1s P.max)
68 {-# NOVECTORISE maximumP_v #-}
69
70 minIndexP :: PArr Word8 -> Int
71 {-# NOINLINE minIndexP #-}
72 minIndexP _ = 0 -- FIXME: add proper implementation
73 {-# VECTORISE minIndexP = minIndexPA #-}
74
75 minIndexPA :: PArray Word8 :-> Int
76 {-# INLINE minIndexPA #-}
77 minIndexPA = closure1 (scalar_fold1Index min') (scalar_fold1sIndex min')
78 {-# NOVECTORISE minIndexPA #-}
79
80 min' (i,x) (j,y) | x P.<= y = (i,x)
81 | P.otherwise = (j,y)
82 {-# NOVECTORISE min' #-}
83
84 maxIndexP :: PArr Word8 -> Int
85 {-# NOINLINE maxIndexP #-}
86 maxIndexP _ = 0 -- FIXME: add proper implementation
87 {-# VECTORISE maxIndexP = maxIndexPA #-}
88
89 maxIndexPA :: PArray Word8 :-> Int
90 {-# INLINE maxIndexPA #-}
91 maxIndexPA = closure1 (scalar_fold1Index max') (scalar_fold1sIndex max')
92 {-# NOVECTORISE maxIndexPA #-}
93
94 max' (i,x) (j,y) | x P.>= y = (i,x)
95 | P.otherwise = (j,y)
96 {-# NOVECTORISE max' #-}
97
98 (+), (-), (*) :: Word8 -> Word8 -> Word8
99 (+) = (P.+)
100 (-) = (P.-)
101 (*) = (P.*)
102
103 negate, abs :: Word8 -> Word8
104 negate = P.negate
105 abs = P.abs
106
107 sumP, productP :: PArr Word8 -> Word8
108 {-# NOINLINE sumP #-}
109 sumP a = a `indexPArr` 0
110 {-# VECTORISE sumP = sumP_v #-}
111 {-# NOINLINE productP #-}
112 productP a = a `indexPArr` 0
113 {-# VECTORISE productP = productP_v #-}
114
115 sumP_v, productP_v:: PArray Word8 :-> Word8
116 {-# INLINE sumP_v #-}
117 sumP_v = closure1 (scalar_fold (+) 0) (scalar_folds (+) 0)
118 {-# NOVECTORISE sumP_v #-}
119 {-# INLINE productP_v #-}
120 productP_v = closure1 (scalar_fold (*) 1) (scalar_folds (*) 1)
121 {-# NOVECTORISE productP_v #-}
122
123 div, mod :: Word8 -> Word8 -> Word8
124 div = P.div
125 mod = P.mod
126
127 sqrt :: Word8 -> Word8
128 sqrt n = P.floor (P.sqrt (P.fromIntegral n) :: P.Double)
129
130 toInt :: Word8 -> Int
131 toInt = P.fromIntegral
132
133 fromInt :: Int -> Word8
134 fromInt = P.fromIntegral