llvm-extra-0.10.1: 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 (ConstValue a) 
IsArithmetic a => Additive (Value 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) 
(Flags flags, Tuple a, Additive a) => Additive (Context flags a) 
(Additive a, Additive b, Additive c) => Additive (a, b, c) 

inc :: (IsArithmetic a, IsConst a, Num a) => Value a -> CodeGenFunction r (Value a)

dec :: (IsArithmetic a, IsConst a, Num a) => Value a -> CodeGenFunction r (Value a)

class Additive a => PseudoRing a whereSource

Methods

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

Instances

IsArithmetic v => PseudoRing (ConstValue v) 
IsArithmetic v => PseudoRing (Value v) 
PseudoRing a => PseudoRing (T a) 
PseudoRing a => PseudoRing (T a) 
(Positive n, PseudoRing a) => PseudoRing (T n a) 
(Flags flags, PseudoRing a, Tuple a) => PseudoRing (Context flags a) 

type family Scalar vector :: *Source

class (PseudoRing (Scalar v), Additive v) => PseudoModule v whereSource

Methods

scale :: Scalar v -> v -> CodeGenFunction r vSource

Instances

class PseudoRing a => Field a whereSource

Methods

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

Instances

IsFloating v => Field (ConstValue v) 
IsFloating v => Field (Value v) 
Field a => Field (T a) 
Field a => Field (T a) 
(Positive n, Field a) => Field (T n a) 
(Flags flags, Tuple v, Field v) => Field (Context flags v) 

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

In Haskell terms this is a quot.

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

class Comparison a => FloatingComparison a whereSource

Methods

fcmp :: FPPredicate -> a -> a -> CodeGenFunction r (CmpResult a)Source

Instances

(IsFloating a, CmpRet a) => FloatingComparison (ConstValue a) 
(IsFloating a, CmpRet a) => FloatingComparison (Value a) 
FloatingComparison a => FloatingComparison (T a) 
(Positive n, FloatingComparison a) => FloatingComparison (T n a) 
(Flags flags, Tuple a, FloatingComparison a) => FloatingComparison (Context flags a) 

class Comparison a whereSource

Associated Types

type CmpResult a :: *Source

Methods

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

Instances

CmpRet a => Comparison (ConstValue a) 
CmpRet a => Comparison (Value a) 
Comparison a => Comparison (T a) 
(Positive n, Comparison a) => Comparison (T n a) 
(Flags flags, Tuple a, Comparison a) => Comparison (Context flags a) 

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 (ConstValue a) 
IsInteger a => Logic (Value 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) 
(Flags flags, Tuple a, Real a) => Real (Context flags 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) 
(Flags flags, Tuple a, Fraction a) => Fraction (Context flags 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) 
(Flags flags, Tuple a, Algebraic a) => Algebraic (Context flags a)