module Data.Primitive.SIMD.Int8X16 (Int8X16) where
import Data.Primitive.SIMD.Class
import GHC.Int
import GHC.Types
import GHC.Prim
import GHC.Ptr
import GHC.ST
import Foreign.Storable
import Control.Monad.Primitive
import Data.Primitive.Types
import Data.Primitive.ByteArray
import Data.Primitive.Addr
import Data.Monoid
import Data.Typeable
import qualified Data.Vector.Primitive as PV
import qualified Data.Vector.Primitive.Mutable as PMV
import Data.Vector.Unboxed (Unbox)
import qualified Data.Vector.Unboxed as UV
import Data.Vector.Generic (Vector(..))
import Data.Vector.Generic.Mutable (MVector(..))
data Int8X16 = Int8X16 Int8X16# deriving Typeable
abs' :: Int8 -> Int8
abs' (I8# x) = I8# (abs# x)
abs# :: Int# -> Int#
abs# x = case abs (I8# x) of
I8# y -> y
signum' :: Int8 -> Int8
signum' (I8# x) = I8# (signum# x)
signum# :: Int# -> Int#
signum# x = case signum (I8# x) of
I8# y -> y
instance Eq Int8X16 where
a == b = case unpackInt8X16 a of
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) -> case unpackInt8X16 b of
(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16) -> x1 == y1 && x2 == y2 && x3 == y3 && x4 == y4 && x5 == y5 && x6 == y6 && x7 == y7 && x8 == y8 && x9 == y9 && x10 == y10 && x11 == y11 && x12 == y12 && x13 == y13 && x14 == y14 && x15 == y15 && x16 == y16
instance Ord Int8X16 where
a `compare` b = case unpackInt8X16 a of
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) -> case unpackInt8X16 b of
(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16) -> x1 `compare` y1 <> x2 `compare` y2 <> x3 `compare` y3 <> x4 `compare` y4 <> x5 `compare` y5 <> x6 `compare` y6 <> x7 `compare` y7 <> x8 `compare` y8 <> x9 `compare` y9 <> x10 `compare` y10 <> x11 `compare` y11 <> x12 `compare` y12 <> x13 `compare` y13 <> x14 `compare` y14 <> x15 `compare` y15 <> x16 `compare` y16
instance Show Int8X16 where
showsPrec _ a s = case unpackInt8X16 a of
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) -> "Int8X16 (" ++ shows x1 (", " ++ shows x2 (", " ++ shows x3 (", " ++ shows x4 (", " ++ shows x5 (", " ++ shows x6 (", " ++ shows x7 (", " ++ shows x8 (", " ++ shows x9 (", " ++ shows x10 (", " ++ shows x11 (", " ++ shows x12 (", " ++ shows x13 (", " ++ shows x14 (", " ++ shows x15 (", " ++ shows x16 (")" ++ s))))))))))))))))
instance Num Int8X16 where
(+) = plusInt8X16
() = minusInt8X16
(*) = timesInt8X16
negate = negateInt8X16
abs = mapVector abs'
signum = mapVector signum'
fromInteger = broadcastVector . fromInteger
instance Bounded Int8X16 where
minBound = broadcastVector minBound
maxBound = broadcastVector maxBound
instance Storable Int8X16 where
sizeOf x = vectorSize x * elementSize x
alignment = sizeOf
peek (Ptr a) = readOffAddr (Addr a) 0
poke (Ptr a) = writeOffAddr (Addr a) 0
instance SIMDVector Int8X16 where
type Elem Int8X16 = Int8
type ElemTuple Int8X16 = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8)
nullVector = broadcastVector 0
vectorSize _ = 16
elementSize _ = 1
broadcastVector = broadcastInt8X16
unsafeInsertVector = unsafeInsertInt8X16
packVector = packInt8X16
unpackVector = unpackInt8X16
mapVector = mapInt8X16
zipVector = zipInt8X16
foldVector = foldInt8X16
instance SIMDIntVector Int8X16 where
quotVector = quotInt8X16
remVector = remInt8X16
instance Prim Int8X16 where
sizeOf# a = let !(I# x) = sizeOf a in x
alignment# a = let !(I# x) = alignment a in x
indexByteArray# ba i = indexInt8X16Array (ByteArray ba) (I# i)
readByteArray# mba i s = let (ST r) = readInt8X16Array (MutableByteArray mba) (I# i) in r s
writeByteArray# mba i v s = let (ST r) = writeInt8X16Array (MutableByteArray mba) (I# i) v in case r s of { (# s', _ #) -> s' }
setByteArray# mba off n v s = let (ST r) = setByteArrayGeneric (MutableByteArray mba) (I# off) (I# n) v in case r s of { (# s', _ #) -> s' }
indexOffAddr# addr i = indexInt8X16OffAddr (Addr addr) (I# i)
readOffAddr# addr i s = let (ST r) = readInt8X16OffAddr (Addr addr) (I# i) in r s
writeOffAddr# addr i v s = let (ST r) = writeInt8X16OffAddr (Addr addr) (I# i) v in case r s of { (# s', _ #) -> s' }
setOffAddr# addr off n v s = let (ST r) = setOffAddrGeneric (Addr addr) (I# off) (I# n) v in case r s of { (# s', _ #) -> s' }
newtype instance UV.Vector Int8X16 = V_Int8X16 (PV.Vector Int8X16)
newtype instance UV.MVector s Int8X16 = MV_Int8X16 (PMV.MVector s Int8X16)
instance Vector UV.Vector Int8X16 where
basicUnsafeFreeze (MV_Int8X16 v) = V_Int8X16 <$> PV.unsafeFreeze v
basicUnsafeThaw (V_Int8X16 v) = MV_Int8X16 <$> PV.unsafeThaw v
basicLength (V_Int8X16 v) = PV.length v
basicUnsafeSlice start len (V_Int8X16 v) = V_Int8X16(PV.unsafeSlice start len v)
basicUnsafeIndexM (V_Int8X16 v) = PV.unsafeIndexM v
basicUnsafeCopy (MV_Int8X16 m) (V_Int8X16 v) = PV.unsafeCopy m v
elemseq _ = seq
instance MVector UV.MVector Int8X16 where
basicLength (MV_Int8X16 v) = PMV.length v
basicUnsafeSlice start len (MV_Int8X16 v) = MV_Int8X16(PMV.unsafeSlice start len v)
basicOverlaps (MV_Int8X16 v) (MV_Int8X16 w) = PMV.overlaps v w
basicUnsafeNew len = MV_Int8X16 <$> PMV.unsafeNew len
#if MIN_VERSION_vector(0,11,0)
basicInitialize (MV_Int8X16 v) = basicInitialize v
#endif
basicUnsafeRead (MV_Int8X16 v) = PMV.unsafeRead v
basicUnsafeWrite (MV_Int8X16 v) = PMV.unsafeWrite v
instance Unbox Int8X16
broadcastInt8X16 :: Int8 -> Int8X16
broadcastInt8X16 (I8# x) = Int8X16 (broadcastInt8X16# x)
packInt8X16 :: (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8) -> Int8X16
packInt8X16 (I8# x1, I8# x2, I8# x3, I8# x4, I8# x5, I8# x6, I8# x7, I8# x8, I8# x9, I8# x10, I8# x11, I8# x12, I8# x13, I8# x14, I8# x15, I8# x16) = Int8X16 (packInt8X16# (# x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16 #))
unpackInt8X16 :: Int8X16 -> (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8)
unpackInt8X16 (Int8X16 m1) = case unpackInt8X16# m1 of
(# x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16 #) -> (I8# x1, I8# x2, I8# x3, I8# x4, I8# x5, I8# x6, I8# x7, I8# x8, I8# x9, I8# x10, I8# x11, I8# x12, I8# x13, I8# x14, I8# x15, I8# x16)
unsafeInsertInt8X16 :: Int8X16 -> Int8 -> Int -> Int8X16
unsafeInsertInt8X16 (Int8X16 m1) (I8# y) _i@(I# ip) = Int8X16 (insertInt8X16# m1 y (ip -# 0#))
mapInt8X16 :: (Int8 -> Int8) -> Int8X16 -> Int8X16
mapInt8X16 f = mapInt8X16# (\ x -> case f (I8# x) of { I8# y -> y})
mapInt8X16# :: (Int# -> Int#) -> Int8X16 -> Int8X16
mapInt8X16# f = \ v -> case unpackInt8X16 v of
(I8# x1, I8# x2, I8# x3, I8# x4, I8# x5, I8# x6, I8# x7, I8# x8, I8# x9, I8# x10, I8# x11, I8# x12, I8# x13, I8# x14, I8# x15, I8# x16) -> packInt8X16 (I8# (f x1), I8# (f x2), I8# (f x3), I8# (f x4), I8# (f x5), I8# (f x6), I8# (f x7), I8# (f x8), I8# (f x9), I8# (f x10), I8# (f x11), I8# (f x12), I8# (f x13), I8# (f x14), I8# (f x15), I8# (f x16))
zipInt8X16 :: (Int8 -> Int8 -> Int8) -> Int8X16 -> Int8X16 -> Int8X16
zipInt8X16 f = \ v1 v2 -> case unpackInt8X16 v1 of
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) -> case unpackInt8X16 v2 of
(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16) -> packInt8X16 (f x1 y1, f x2 y2, f x3 y3, f x4 y4, f x5 y5, f x6 y6, f x7 y7, f x8 y8, f x9 y9, f x10 y10, f x11 y11, f x12 y12, f x13 y13, f x14 y14, f x15 y15, f x16 y16)
foldInt8X16 :: (Int8 -> Int8 -> Int8) -> Int8X16 -> Int8
foldInt8X16 f' = \ v -> case unpackInt8X16 v of
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) -> x1 `f` x2 `f` x3 `f` x4 `f` x5 `f` x6 `f` x7 `f` x8 `f` x9 `f` x10 `f` x11 `f` x12 `f` x13 `f` x14 `f` x15 `f` x16
where f !x !y = f' x y
plusInt8X16 :: Int8X16 -> Int8X16 -> Int8X16
plusInt8X16 (Int8X16 m1_1) (Int8X16 m1_2) = Int8X16 (plusInt8X16# m1_1 m1_2)
minusInt8X16 :: Int8X16 -> Int8X16 -> Int8X16
minusInt8X16 (Int8X16 m1_1) (Int8X16 m1_2) = Int8X16 (minusInt8X16# m1_1 m1_2)
timesInt8X16 :: Int8X16 -> Int8X16 -> Int8X16
timesInt8X16 (Int8X16 m1_1) (Int8X16 m1_2) = Int8X16 (timesInt8X16# m1_1 m1_2)
quotInt8X16 :: Int8X16 -> Int8X16 -> Int8X16
quotInt8X16 (Int8X16 m1_1) (Int8X16 m1_2) = Int8X16 (quotInt8X16# m1_1 m1_2)
remInt8X16 :: Int8X16 -> Int8X16 -> Int8X16
remInt8X16 (Int8X16 m1_1) (Int8X16 m1_2) = Int8X16 (remInt8X16# m1_1 m1_2)
negateInt8X16 :: Int8X16 -> Int8X16
negateInt8X16 (Int8X16 m1_1) = Int8X16 (negateInt8X16# m1_1)
indexInt8X16Array :: ByteArray -> Int -> Int8X16
indexInt8X16Array (ByteArray a) (I# i) = Int8X16 (indexInt8X16Array# a i)
readInt8X16Array :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> m Int8X16
readInt8X16Array (MutableByteArray a) (I# i) = primitive (\ s0 -> case readInt8X16Array# a ((i *# 1#) +# 0#) s0 of
(# s1, m1 #) -> (# s1, Int8X16 m1 #))
writeInt8X16Array :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> Int8X16 -> m ()
writeInt8X16Array (MutableByteArray a) (I# i) (Int8X16 m1) = primitive_ (writeInt8X16Array# a ((i *# 1#) +# 0#) m1)
indexInt8X16OffAddr :: Addr -> Int -> Int8X16
indexInt8X16OffAddr (Addr a) (I# i) = Int8X16 (indexInt8X16OffAddr# (plusAddr# a (i *# 16#)) 0#)
readInt8X16OffAddr :: PrimMonad m => Addr -> Int -> m Int8X16
readInt8X16OffAddr (Addr a) (I# i) = primitive (\ s0 -> case (\ addr i' -> readInt8X16OffAddr# (plusAddr# addr i') 0#) a ((i *# 16#) +# 0#) s0 of
(# s1, m1 #) -> (# s1, Int8X16 m1 #))
writeInt8X16OffAddr :: PrimMonad m => Addr -> Int -> Int8X16 -> m ()
writeInt8X16OffAddr (Addr a) (I# i) (Int8X16 m1) = primitive_ (writeInt8X16OffAddr# (plusAddr# a ((i *# 16#) +# 0#)) 0# m1)