llvm-extra-0.7.3: 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) 

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

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

class Additive a => PseudoRing a whereSource

Methods

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

Instances

IsArithmetic v => PseudoRing (Value v) 
IsArithmetic v => PseudoRing (ConstValue v) 
PseudoRing a => PseudoRing (T a) 
PseudoRing a => PseudoRing (T a) 
(Positive n, PseudoRing a) => PseudoRing (T n a) 

square :: PseudoRing a => a -> CodeGenFunction r aSource

type family Scalar vector :: *Source

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

Methods

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

Instances

PseudoModule v => PseudoModule (Value v) 
PseudoModule v => PseudoModule (ConstValue v) 
PseudoModule a => PseudoModule (T a) 
PseudoRing a => PseudoModule (T a) 
(Positive n, PseudoModule a) => PseudoModule (T n a) 

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) 

class IntegerConstant a whereSource

Instances

IntegerConstant a => IntegerConstant (Value a) 
IntegerConstant a => IntegerConstant (ConstValue a) 
IntegerConstant a => IntegerConstant (T a) 
IntegerConstant a => IntegerConstant (T a) 
(Positive n, IntegerConstant a) => IntegerConstant (T n a) 

class IntegerConstant a => RationalConstant a whereSource

Instances

RationalConstant a => RationalConstant (Value a) 
RationalConstant a => RationalConstant (ConstValue a) 
RationalConstant a => RationalConstant (T a) 
RationalConstant a => RationalConstant (T a) 
(Positive n, RationalConstant a) => RationalConstant (T n a) 

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 (Value a) 
(IsFloating a, CmpRet a) => FloatingComparison (ConstValue a) 
FloatingComparison a => FloatingComparison (T a) 
(Positive n, FloatingComparison a) => FloatingComparison (T n 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 (Value a) 
CmpRet a => Comparison (ConstValue a) 
Comparison a => Comparison (T a) 
(Positive n, Comparison a) => Comparison (T n 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 (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

Methods

truncate :: a -> CodeGenFunction r aSource

fraction :: a -> CodeGenFunction r aSource

Instances

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

signedFraction :: Fraction a => a -> CodeGenFunction r aSource

addToPhase :: Fraction a => a -> a -> CodeGenFunction r aSource

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

both increment and phase must be non-negative

pointer arithmetic

advanceArrayElementPtr :: Value (Ptr a) -> CodeGenFunction r (Value (Ptr a))Source

decreaseArrayElementPtr :: Value (Ptr a) -> CodeGenFunction r (Value (Ptr a))Source

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) 

class Algebraic a => Transcendental a whereSource

Methods

pi :: CodeGenFunction r aSource

sin, log, exp, cos :: a -> CodeGenFunction r aSource

pow :: a -> a -> CodeGenFunction r aSource

Instances

(IsFloating a, TranscendentalConstant a) => Transcendental (Value a) 
Transcendental a => Transcendental (T a) 
Transcendental a => Transcendental (T a) 
(Positive n, Transcendental a) => Transcendental (T n a)