Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Simple C runtime representation.
Most types use the same memory and scalar variable representation.
For those that do not (as of this writing, only Float16
), we use
primStorageType
for the array element representation, and
primTypeToCType
for their scalar representation. Use toStorage
and fromStorage
to convert back and forth.
Synopsis
- tupleField :: Int -> String
- funName :: Name -> Text
- defaultMemBlockType :: Type
- intTypeToCType :: IntType -> Type
- primTypeToCType :: PrimType -> Type
- primStorageType :: PrimType -> Type
- primAPIType :: Signedness -> PrimType -> Type
- arrayName :: PrimType -> Signedness -> Int -> Text
- opaqueName :: Name -> Text
- isValidCName :: Text -> Bool
- escapeName :: Text -> Text
- toStorage :: PrimType -> Exp -> Exp
- fromStorage :: PrimType -> Exp -> Exp
- cproduct :: [Exp] -> Exp
- csum :: [Exp] -> Exp
- scalarToPrim :: Text -> (Signedness, PrimType)
- cScalarDefs :: Text
- storageSize :: PrimType -> Int -> Exp -> Exp
- storeValueHeader :: Signedness -> PrimType -> Int -> Exp -> Exp -> [Stm]
- loadValueHeader :: Signedness -> PrimType -> Int -> Exp -> Exp -> [Stm]
Documentation
tupleField :: Int -> String Source #
tupleField i
is the name of field number i
in a tuple.
funName :: Name -> Text Source #
funName f
is the name of the C function corresponding to
the Futhark function f
.
defaultMemBlockType :: Type Source #
The type of memory blocks in the default memory space.
intTypeToCType :: IntType -> Type Source #
The C type corresponding to a signed integer type.
primTypeToCType :: PrimType -> Type Source #
The C type corresponding to a primitive type. Integers are assumed to be unsigned.
primStorageType :: PrimType -> Type Source #
The C storage type for arrays of this primitive type.
primAPIType :: Signedness -> PrimType -> Type Source #
The C API corresponding to a primitive type. Integers are assumed to have the specified sign.
opaqueName :: Name -> Text Source #
The name of exposed opaque types.
isValidCName :: Text -> Bool Source #
Is this name a valid C identifier? If not, it should be escaped before being emitted into C.
escapeName :: Text -> Text Source #
If the provided text is a valid C identifier, then return it verbatim. Otherwise, escape it such that it becomes valid.
toStorage :: PrimType -> Exp -> Exp Source #
Convert from scalar to storage representation for the given type.
fromStorage :: PrimType -> Exp -> Exp Source #
Convert from storage to scalar representation for the given type.
cproduct :: [Exp] -> Exp Source #
Return an expression multiplying together the given expressions.
If an empty list is given, the expression 1
is returned.
Return an expression summing the given expressions.
If an empty list is given, the expression 0
is returned.
scalarToPrim :: Text -> (Signedness, PrimType) Source #
The PrimType
(and sign) correspond to a human-readable scalar
type name (e.g. f64
). Beware: partial!
Primitive value operations
cScalarDefs :: Text Source #
Implementations of scalar operations.
Storing/restoring values in byte sequences
storageSize :: PrimType -> Int -> Exp -> Exp Source #
storageSize pt rank shape
produces an expression giving size
taken when storing this value in the binary value format. It is
assumed that the shape
is an array with rank
dimensions.
storeValueHeader :: Signedness -> PrimType -> Int -> Exp -> Exp -> [Stm] Source #
Produce code for storing the header (everything besides the actual payload) for a value of this type.
loadValueHeader :: Signedness -> PrimType -> Int -> Exp -> Exp -> [Stm] Source #
Produce code for loading the header (everything besides the actual payload) for a value of this type.