llvm-extra-0.6.0.1: Utility functions for the llvm interface

Safe HaskellNone
LanguageHaskell98

LLVM.Extra.Arithmetic

Contents

Synopsis

arithmetic: generalized and improved type inference

class Zero a => Additive a where Source

This and the following type classes are intended for arithmetic operations on wrappers around LLVM types. E.g. you might define a fixed point fraction type by

newtype Fixed = Fixed Int32

and then use the same methods for floating point and fixed point arithmetic.

In contrast to the arithmetic methods in the llvm wrapper, in our methods the types of operands and result match. Advantage: Type inference determines most of the types automatically. Disadvantage: You cannot use constant values directly, but you have to convert them all to Value.

Methods

zero :: a Source

add :: a -> a -> CodeGenFunction r a Source

sub :: a -> a -> CodeGenFunction r a Source

neg :: a -> CodeGenFunction r a Source

Instances

IsArithmetic a => Additive (Value a) 
IsArithmetic a => Additive (ConstValue a) 
Additive a => Additive (T a) 
Additive a => Additive (T a) 
(Additive a, Additive b) => Additive (a, b) 
(Positive n, Additive a) => Additive (T n a) 
(Additive a, Additive b, Additive c) => Additive (a, b, c) 

class Additive a => PseudoRing a where Source

Methods

mul :: a -> a -> CodeGenFunction r a Source

type family Scalar vector :: * Source

Instances

type Scalar (Value a) = Value (Scalar a) 
type Scalar (ConstValue a) = ConstValue (Scalar a) 
type Scalar (T a) = T (Scalar a) 
type Scalar (T a) = T a 
type Scalar (T n a) = T n (Scalar a) 

class PseudoRing a => Field a where Source

Methods

fdiv :: a -> a -> CodeGenFunction r a Source

Instances

IsFloating v => Field (Value v) 
IsFloating v => Field (ConstValue v) 
Field a => Field (T a) 
Field a => Field (T a) 
(Positive n, Field a) => Field (T n a) 

class Comparison a where Source

Associated Types

type CmpResult a :: * Source

Methods

cmp :: CmpPredicate -> a -> a -> CodeGenFunction r (CmpResult a) Source

Instances

data CmpPredicate :: *

Constructors

CmpEQ

equal

CmpNE

not equal

CmpGT

greater than

CmpGE

greater or equal

CmpLT

less than

CmpLE

less or equal

class Logic a where Source

Methods

and :: a -> a -> CodeGenFunction r a Source

or :: a -> a -> CodeGenFunction r a Source

xor :: a -> a -> CodeGenFunction r a Source

inv :: a -> CodeGenFunction r a Source

Instances

IsInteger a => Logic (Value a) 
IsInteger a => Logic (ConstValue a) 
Logic a => Logic (T a) 
(Positive n, Logic a) => Logic (T n a) 

class Additive a => Real a where Source

Methods

min :: a -> a -> CodeGenFunction r a Source

max :: a -> a -> CodeGenFunction r a Source

abs :: a -> CodeGenFunction r a Source

signum :: a -> CodeGenFunction r a Source

Instances

Real a => Real (Value a) 
Real a => Real (T a) 
Real a => Real (T a) 
(Positive n, Real a) => Real (T n a) 

class Real a => Fraction a where Source

Instances

Fraction a => Fraction (Value a) 
Fraction a => Fraction (T a) 
Fraction a => Fraction (T a) 
(Positive n, Fraction a) => Fraction (T n a) 

incPhase :: Fraction a => a -> a -> CodeGenFunction r a Source

both increment and phase must be non-negative

pointer arithmetic

transcendental functions

class Field a => Algebraic a where Source

Methods

sqrt :: a -> CodeGenFunction r a Source

Instances

IsFloating a => Algebraic (Value a) 
Algebraic a => Algebraic (T a) 
Algebraic a => Algebraic (T a) 
(Positive n, Algebraic a) => Algebraic (T n a)