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

Safe HaskellNone

LLVM.Extra.Arithmetic

Contents

Synopsis

arithmetic: generalized and improved type inference

class Zero a => Additive a whereSource

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 :: aSource

add :: a -> a -> CodeGenFunction r aSource

sub :: a -> a -> CodeGenFunction r aSource

neg :: a -> CodeGenFunction r aSource

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 whereSource

Methods

mul :: a -> a -> CodeGenFunction r aSource

type family Scalar vector :: *Source

class PseudoRing a => Field a whereSource

Methods

fdiv :: a -> a -> CodeGenFunction r aSource

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) 

idiv :: IsInteger a => Value a -> Value a -> CodeGenFunction r (Value a)Source

In Haskell terms this is a quot.

class Comparison a whereSource

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 whereSource

Methods

and :: a -> a -> CodeGenFunction r aSource

or :: a -> a -> CodeGenFunction r aSource

xor :: a -> a -> CodeGenFunction r aSource

inv :: a -> CodeGenFunction r aSource

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 whereSource

Methods

min :: a -> a -> CodeGenFunction r aSource

max :: a -> a -> CodeGenFunction r aSource

abs :: a -> CodeGenFunction r aSource

signum :: a -> CodeGenFunction r aSource

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 whereSource

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 aSource

both increment and phase must be non-negative

pointer arithmetic

transcendental functions

class Field a => Algebraic a whereSource

Methods

sqrt :: a -> CodeGenFunction r aSource

Instances

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