Safe Haskell | None |
---|---|
Language | Haskell2010 |
Definitions of primitive types, the values that inhabit these types, and operations on these values. A primitive value can also be called a scalar.
Essentially, this module describes the subset of the (internal) Futhark language that operates on primitive types.
Synopsis
- data IntType
- allIntTypes :: [IntType]
- data FloatType
- allFloatTypes :: [FloatType]
- data PrimType
- allPrimTypes :: [PrimType]
- data IntValue
- = Int8Value !Int8
- | Int16Value !Int16
- | Int32Value !Int32
- | Int64Value !Int64
- intValue :: Integral int => IntType -> int -> IntValue
- intValueType :: IntValue -> IntType
- valueIntegral :: Integral int => IntValue -> int
- data FloatValue
- floatValue :: Real num => FloatType -> num -> FloatValue
- floatValueType :: FloatValue -> FloatType
- data PrimValue
- = IntValue !IntValue
- | FloatValue !FloatValue
- | BoolValue !Bool
- | Checked
- primValueType :: PrimValue -> PrimType
- blankPrimValue :: PrimType -> PrimValue
- data UnOp
- allUnOps :: [UnOp]
- data BinOp
- = Add IntType
- | FAdd FloatType
- | Sub IntType
- | FSub FloatType
- | Mul IntType
- | FMul FloatType
- | UDiv IntType
- | SDiv IntType
- | FDiv FloatType
- | UMod IntType
- | SMod IntType
- | SQuot IntType
- | SRem IntType
- | SMin IntType
- | UMin IntType
- | FMin FloatType
- | SMax IntType
- | UMax IntType
- | FMax FloatType
- | Shl IntType
- | LShr IntType
- | AShr IntType
- | And IntType
- | Or IntType
- | Xor IntType
- | Pow IntType
- | FPow FloatType
- | LogAnd
- | LogOr
- allBinOps :: [BinOp]
- data ConvOp
- allConvOps :: [ConvOp]
- data CmpOp
- allCmpOps :: [CmpOp]
- doUnOp :: UnOp -> PrimValue -> Maybe PrimValue
- doComplement :: IntValue -> IntValue
- doAbs :: IntValue -> IntValue
- doFAbs :: FloatValue -> FloatValue
- doSSignum :: IntValue -> IntValue
- doUSignum :: IntValue -> IntValue
- doBinOp :: BinOp -> PrimValue -> PrimValue -> Maybe PrimValue
- doAdd :: IntValue -> IntValue -> IntValue
- doMul :: IntValue -> IntValue -> IntValue
- doSDiv :: IntValue -> IntValue -> Maybe IntValue
- doSMod :: IntValue -> IntValue -> Maybe IntValue
- doPow :: IntValue -> IntValue -> Maybe IntValue
- doConvOp :: ConvOp -> PrimValue -> Maybe PrimValue
- doZExt :: IntValue -> IntType -> IntValue
- doSExt :: IntValue -> IntType -> IntValue
- doFPConv :: FloatValue -> FloatType -> FloatValue
- doFPToUI :: FloatValue -> IntType -> IntValue
- doFPToSI :: FloatValue -> IntType -> IntValue
- doUIToFP :: IntValue -> FloatType -> FloatValue
- doSIToFP :: IntValue -> FloatType -> FloatValue
- intToInt64 :: IntValue -> Int64
- intToWord64 :: IntValue -> Word64
- doCmpOp :: CmpOp -> PrimValue -> PrimValue -> Maybe Bool
- doCmpEq :: PrimValue -> PrimValue -> Bool
- doCmpUlt :: IntValue -> IntValue -> Bool
- doCmpUle :: IntValue -> IntValue -> Bool
- doCmpSlt :: IntValue -> IntValue -> Bool
- doCmpSle :: IntValue -> IntValue -> Bool
- doFCmpLt :: FloatValue -> FloatValue -> Bool
- doFCmpLe :: FloatValue -> FloatValue -> Bool
- binOpType :: BinOp -> PrimType
- unOpType :: UnOp -> PrimType
- cmpOpType :: CmpOp -> PrimType
- convOpType :: ConvOp -> (PrimType, PrimType)
- primFuns :: Map String ([PrimType], PrimType, [PrimValue] -> Maybe PrimValue)
- zeroIsh :: PrimValue -> Bool
- oneIsh :: PrimValue -> Bool
- negativeIsh :: PrimValue -> Bool
- primBitSize :: PrimType -> Int
- primByteSize :: Num a => PrimType -> a
- intByteSize :: Num a => IntType -> a
- floatByteSize :: Num a => FloatType -> a
- commutativeBinOp :: BinOp -> Bool
- convOpFun :: ConvOp -> String
- prettySigned :: Bool -> PrimType -> String
Types
An integer type, ordered by size. Note that signedness is not a property of the type, but a property of the operations performed on values of these types.
Instances
Bounded IntType Source # | |
Enum IntType Source # | |
Eq IntType Source # | |
Ord IntType Source # | |
Defined in Futhark.Representation.Primitive | |
Show IntType Source # | |
Pretty IntType Source # | |
allIntTypes :: [IntType] Source #
A list of all integer types.
A floating point type.
Instances
Bounded FloatType Source # | |
Enum FloatType Source # | |
Defined in Futhark.Representation.Primitive succ :: FloatType -> FloatType # pred :: FloatType -> FloatType # fromEnum :: FloatType -> Int # enumFrom :: FloatType -> [FloatType] # enumFromThen :: FloatType -> FloatType -> [FloatType] # enumFromTo :: FloatType -> FloatType -> [FloatType] # enumFromThenTo :: FloatType -> FloatType -> FloatType -> [FloatType] # | |
Eq FloatType Source # | |
Ord FloatType Source # | |
Defined in Futhark.Representation.Primitive | |
Show FloatType Source # | |
Pretty FloatType Source # | |
allFloatTypes :: [FloatType] Source #
A list of all floating-point types.
Low-level primitive types.
Instances
Bounded PrimType Source # | |
Enum PrimType Source # | |
Defined in Futhark.Representation.Primitive | |
Eq PrimType Source # | |
Ord PrimType Source # | |
Defined in Futhark.Representation.Primitive | |
Show PrimType Source # | |
Pretty PrimType Source # | |
allPrimTypes :: [PrimType] Source #
A list of all primitive types.
Values
An integer value.
intValueType :: IntValue -> IntType Source #
data FloatValue Source #
A floating-point value.
Instances
floatValue :: Real num => FloatType -> num -> FloatValue Source #
Create a FloatValue
from a type and a Rational
.
floatValueType :: FloatValue -> FloatType Source #
Non-array values.
IntValue !IntValue | |
FloatValue !FloatValue | |
BoolValue !Bool | |
Checked | The only value of type |
primValueType :: PrimValue -> PrimType Source #
The type of a basic value.
blankPrimValue :: PrimType -> PrimValue Source #
A "blank" value of the given primitive type - this is zero, or whatever is close to it. Don't depend on this value, but use it for e.g. creating arrays to be populated by do-loops.
Operations
Various unary operators. It is a bit ad-hoc what is a unary operator and what is a built-in function. Perhaps these should all go away eventually.
Not | E.g., |
Complement IntType | E.g., |
Abs IntType |
|
FAbs FloatType |
|
SSignum IntType | Signed sign function: |
USignum IntType | Unsigned sign function: |
Binary operators. These correspond closely to the binary operators in LLVM. Most are parametrised by their expected input and output types.
Add IntType | Integer addition. |
FAdd FloatType | Floating-point addition. |
Sub IntType | Integer subtraction. |
FSub FloatType | Floating-point subtraction. |
Mul IntType | Integer multiplication. |
FMul FloatType | Floating-point multiplication. |
UDiv IntType | Unsigned integer division. Rounds towards negativity infinity. Note: this is different from LLVM. |
SDiv IntType | Signed integer division. Rounds towards negativity infinity. Note: this is different from LLVM. |
FDiv FloatType | Floating-point division. |
UMod IntType | Unsigned integer modulus; the countepart to |
SMod IntType | Signed integer modulus; the countepart to |
SQuot IntType | Signed integer division. Rounds towards zero.
This corresponds to the |
SRem IntType | Signed integer division. Rounds towards zero.
This corresponds to the |
SMin IntType | Returns the smallest of two signed integers. |
UMin IntType | Returns the smallest of two unsigned integers. |
FMin FloatType | Returns the smallest of two floating-point numbers. |
SMax IntType | Returns the greatest of two signed integers. |
UMax IntType | Returns the greatest of two unsigned integers. |
FMax FloatType | Returns the greatest of two floating-point numbers. |
Shl IntType | Left-shift. |
LShr IntType | Logical right-shift, zero-extended. |
AShr IntType | Arithmetic right-shift, sign-extended. |
And IntType | Bitwise and. |
Or IntType | Bitwise or. |
Xor IntType | Bitwise exclusive-or. |
Pow IntType | Integer exponentiation. |
FPow FloatType | Floating-point exponentiation. |
LogAnd | Boolean and - not short-circuiting. |
LogOr | Boolean or - not short-circuiting. |
Conversion operators try to generalise the from t0 x to t1
instructions from LLVM.
ZExt IntType IntType | Zero-extend the former integer type to the latter. If the new type is smaller, the result is a truncation. |
SExt IntType IntType | Sign-extend the former integer type to the latter. If the new type is smaller, the result is a truncation. |
FPConv FloatType FloatType | Convert value of the former floating-point type to the latter. If the new type is smaller, the result is a truncation. |
FPToUI FloatType IntType | Convert a floating-point value to the nearest unsigned integer (rounding towards zero). |
FPToSI FloatType IntType | Convert a floating-point value to the nearest signed integer (rounding towards zero). |
UIToFP IntType FloatType | Convert an unsigned integer to a floating-point value. |
SIToFP IntType FloatType | Convert a signed integer to a floating-point value. |
IToB IntType | Convert an integer to a boolean value. Zero becomes false; anything else is true. |
BToI IntType | Convert a boolean to an integer. True is converted to 1 and False to 0. |
allConvOps :: [ConvOp] Source #
A list of all conversion operators for all types.
Comparison operators are like BinOp
s, but they return PrimType
s.
The somewhat ugly constructor names are straight out of LLVM.
CmpEq PrimType | All types equality. |
CmpUlt IntType | Unsigned less than. |
CmpUle IntType | Unsigned less than or equal. |
CmpSlt IntType | Signed less than. |
CmpSle IntType | Signed less than or equal. |
FCmpLt FloatType | Floating-point less than. |
FCmpLe FloatType | Floating-point less than or equal. |
CmpLlt | Boolean less than. |
CmpLle | Boolean less than or equal. |
Unary Operations
doComplement :: IntValue -> IntValue Source #
E.g., ~(~1) = 1
.
doFAbs :: FloatValue -> FloatValue Source #
abs(-2.0) = 2.0
.
Binary Operations
doSDiv :: IntValue -> IntValue -> Maybe IntValue Source #
Signed integer division. Rounds towards negativity infinity. Note: this is different from LLVM.
doSMod :: IntValue -> IntValue -> Maybe IntValue Source #
Signed integer modulus; the countepart to SDiv
.
Conversion Operations
doZExt :: IntValue -> IntType -> IntValue Source #
Zero-extend the given integer value to the size of the given type. If the type is smaller than the given value, the result is a truncation.
doSExt :: IntValue -> IntType -> IntValue Source #
Sign-extend the given integer value to the size of the given type. If the type is smaller than the given value, the result is a truncation.
doFPConv :: FloatValue -> FloatType -> FloatValue Source #
Convert the former floating-point type to the latter.
doFPToUI :: FloatValue -> IntType -> IntValue Source #
Convert a floating-point value to the nearest unsigned integer (rounding towards zero).
doFPToSI :: FloatValue -> IntType -> IntValue Source #
Convert a floating-point value to the nearest signed integer (rounding towards zero).
doUIToFP :: IntValue -> FloatType -> FloatValue Source #
Convert an unsigned integer to a floating-point value.
doSIToFP :: IntValue -> FloatType -> FloatValue Source #
Convert a signed integer to a floating-point value.
intToInt64 :: IntValue -> Int64 Source #
intToWord64 :: IntValue -> Word64 Source #
Comparison Operations
doCmpEq :: PrimValue -> PrimValue -> Bool Source #
Compare any two primtive values for exact equality.
doFCmpLt :: FloatValue -> FloatValue -> Bool Source #
Floating-point less than.
doFCmpLe :: FloatValue -> FloatValue -> Bool Source #
Floating-point less than or equal.
Type Of
convOpType :: ConvOp -> (PrimType, PrimType) Source #
The input and output types of a conversion operator.
Primitive functions
primFuns :: Map String ([PrimType], PrimType, [PrimValue] -> Maybe PrimValue) Source #
A mapping from names of primitive functions to their parameter types, their result type, and a function for evaluating them.
Utility
negativeIsh :: PrimValue -> Bool Source #
Is the given value kind of negative?
primBitSize :: PrimType -> Int Source #
The size of a value of a given primitive type in bites.
primByteSize :: Num a => PrimType -> a Source #
The size of a value of a given primitive type in eight-bit bytes.
intByteSize :: Num a => IntType -> a Source #
The size of a value of a given integer type in eight-bit bytes.
floatByteSize :: Num a => FloatType -> a Source #
The size of a value of a given floating-point type in eight-bit bytes.
commutativeBinOp :: BinOp -> Bool Source #
True if the given binary operator is commutative.