futhark-0.25.27: An optimising compiler for a functional, array-oriented language.

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.CodeGen.Backends.SimpleRep

Contents

- Primitive value operations
- Storing/restoring values in byte sequences
- Orphan instances

Description

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
- allEqual :: [Exp] -> Exp
- allTrue :: [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.

arrayName :: PrimType -> Signedness -> Int -> Text Source #

The name of exposed array type structs.

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.

csum :: [Exp] -> Exp Source #

Return an expression summing the given expressions. If an empty list is given, the expression `0` is returned.

allEqual :: [Exp] -> Exp Source #

An expression that is true if these expressions are all equal by `==`.

allTrue :: [Exp] -> Exp Source #

An expression that is true if these are also all true.

scalarToPrim :: Text -> (Signedness, PrimType) Source #

The `PrimType` (and sign) corresponding 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.

# Orphan instances

ToExp SubExp Source # |
Instance details Methods toExp :: SubExp -> SrcLoc -> Exp Source #
ToExp VName Source # |
Instance details Methods toExp :: VName -> SrcLoc -> Exp Source #
ToExp FloatValue Source # |
Instance details Methods toExp :: FloatValue -> SrcLoc -> Exp Source #
ToExp IntValue Source # |
Instance details Methods toExp :: IntValue -> SrcLoc -> Exp Source #
ToExp PrimValue Source # |
Instance details Methods toExp :: PrimValue -> SrcLoc -> Exp Source #
ToIdent Name Source # |
Instance details Methods toIdent :: Name -> SrcLoc -> Id Source #
ToIdent VName Source # |
Instance details Methods toIdent :: VName -> SrcLoc -> Id Source #
ToIdent Text Source # |
Instance details Methods toIdent :: Text -> SrcLoc -> Id Source #