{-# LANGUAGE ForeignFunctionInterface #-}
module Data.ByteString.Base64.Internal.SIMD
( encodePrefix
, decodePrefix
) where
import Foreign.C.Types (CSize(..))
import Foreign.Ptr (Ptr)
import Data.Word (Word8)
foreign import ccall unsafe "hs_base64_simd_encode"
c_encodePrefix :: Ptr Word8 -> CSize -> Ptr Word8 -> Ptr Word8 -> IO CSize
foreign import ccall unsafe "hs_base64_simd_decode"
c_decodePrefix :: Ptr Word8 -> CSize -> Ptr Word8 -> Ptr Word8 -> IO CSize
encodePrefix :: Ptr Word8 -> Int -> Ptr Word8 -> Ptr Word8 -> IO Int
encodePrefix :: Ptr Word8 -> Int -> Ptr Word8 -> Ptr Word8 -> IO Int
encodePrefix Ptr Word8
src Int
len Ptr Word8
dst Ptr Word8
alphabet
| Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
96 = Int -> IO Int
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0
| Bool
otherwise = CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CSize -> Int) -> IO CSize -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word8 -> CSize -> Ptr Word8 -> Ptr Word8 -> IO CSize
c_encodePrefix Ptr Word8
src (Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len) Ptr Word8
dst Ptr Word8
alphabet
{-# INLINE encodePrefix #-}
decodePrefix :: Ptr Word8 -> Int -> Ptr Word8 -> Ptr Word8 -> IO Int
decodePrefix :: Ptr Word8 -> Int -> Ptr Word8 -> Ptr Word8 -> IO Int
decodePrefix Ptr Word8
src Int
len Ptr Word8
dst Ptr Word8
table
| Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
128 = Int -> IO Int
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0
| Bool
otherwise = CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CSize -> Int) -> IO CSize -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word8 -> CSize -> Ptr Word8 -> Ptr Word8 -> IO CSize
c_decodePrefix Ptr Word8
src (Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len) Ptr Word8
dst Ptr Word8
table
{-# INLINE decodePrefix #-}