1 {-# OPTIONS_GHC -fvectorise #-}
3 module Data.Array.Parallel.Prelude.Word8 (
4 Word8,
6 -- Ord
7 (==), (/=), (<), (<=), (>), (>=), min, max,
9 minimumP, maximumP, minIndexP, maxIndexP,
11 -- Num
12 (+), (-), (*), negate, abs,
14 sumP, productP,
16 -- Integral
17 div, mod, sqrt,
19 toInt, fromInt
20 ) where
22 import Data.Array.Parallel.Prim () -- dependency required by the vectoriser
24 import Data.Array.Parallel.Prelude.Base
26 import Data.Array.Parallel.PArr
27 import Data.Array.Parallel.Lifted.Scalar
28 import Data.Array.Parallel.Lifted.Closure
30 import qualified Prelude as P
31 import Prelude (Int)
33 import Data.Word (Word8)
36 infixl 7 *
37 infixl 6 +, -
38 infix 4 ==, /=, <, <=, >, >=
39 infixl 7 `div`, `mod`
42 (==), (/=), (<), (<=), (>), (>=) :: Word8 -> Word8 -> Bool
43 (==) = (P.==)
44 (/=) = (P./=)
45 (<=) = (P.<=)
46 (<) = (P.<)
47 (>=) = (P.>=)
48 (>) = (P.>)
50 min, max :: Word8 -> Word8 -> Word8
51 min = P.min
52 max = P.max
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 #-}
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 #-}
70 minIndexP :: PArr Word8 -> Int
71 {-# NOINLINE minIndexP #-}
72 minIndexP _ = 0 -- FIXME: add proper implementation
73 {-# VECTORISE minIndexP = minIndexPA #-}
75 minIndexPA :: PArray Word8 :-> Int
76 {-# INLINE minIndexPA #-}
77 minIndexPA = closure1 (scalar_fold1Index min') (scalar_fold1sIndex min')
78 {-# NOVECTORISE minIndexPA #-}
80 min' (i,x) (j,y) | x P.<= y = (i,x)
81 | P.otherwise = (j,y)
82 {-# NOVECTORISE min' #-}
84 maxIndexP :: PArr Word8 -> Int
85 {-# NOINLINE maxIndexP #-}
86 maxIndexP _ = 0 -- FIXME: add proper implementation
87 {-# VECTORISE maxIndexP = maxIndexPA #-}
89 maxIndexPA :: PArray Word8 :-> Int
90 {-# INLINE maxIndexPA #-}
91 maxIndexPA = closure1 (scalar_fold1Index max') (scalar_fold1sIndex max')
92 {-# NOVECTORISE maxIndexPA #-}
94 max' (i,x) (j,y) | x P.>= y = (i,x)
95 | P.otherwise = (j,y)
96 {-# NOVECTORISE max' #-}
98 (+), (-), (*) :: Word8 -> Word8 -> Word8
99 (+) = (P.+)
100 (-) = (P.-)
101 (*) = (P.*)
103 negate, abs :: Word8 -> Word8
104 negate = P.negate
105 abs = P.abs
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 #-}
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 #-}
123 div, mod :: Word8 -> Word8 -> Word8
124 div = P.div
125 mod = P.mod
127 sqrt :: Word8 -> Word8
128 sqrt n = P.floor (P.sqrt (P.fromIntegral n) :: P.Double)
130 toInt :: Word8 -> Int
131 toInt = P.fromIntegral
133 fromInt :: Int -> Word8
134 fromInt = P.fromIntegral