{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Synthesizer.LLVM.Filter.SecondOrder (
Parameter(Parameter),
Filt2.c0, Filt2.c1, Filt2.c2, Filt2.d1, Filt2.d2,
bandpassParameter,
bandpassParameterCode,
ParameterStruct, composeParameter, decomposeParameter,
composeParameterMV, decomposeParameterMV,
causalExp,
causal, causalPacked,
) where
import qualified Synthesizer.Plain.Filter.Recursive.SecondOrder as Filt2
import Synthesizer.Plain.Filter.Recursive.SecondOrder (Parameter(Parameter))
import qualified Synthesizer.Plain.Modifier as Modifier
import qualified Synthesizer.LLVM.Causal.Process as CausalExp
import qualified Synthesizer.LLVM.Causal.ProcessValue as Causal
import qualified Synthesizer.LLVM.Frame.SerialVector.Class as Serial
import qualified Synthesizer.LLVM.Value as Value
import qualified LLVM.DSL.Expression as Expr
import qualified LLVM.Extra.Multi.Value.Marshal as MarshalMV
import qualified LLVM.Extra.Multi.Value as MultiValue
import qualified LLVM.Extra.Storable as Storable
import qualified LLVM.Extra.Marshal as Marshal
import qualified LLVM.Extra.Memory as Memory
import qualified LLVM.Extra.Tuple as Tuple
import qualified LLVM.Extra.Arithmetic as A
import qualified LLVM.Core as LLVM
import LLVM.Core (CodeGenFunction, valueOf)
import qualified Type.Data.Num.Decimal as TypeNum
import Type.Data.Num.Decimal (d0, d1, d2, d3, d4)
import qualified Control.Monad.HT as M
import qualified Control.Applicative.HT as App
import Control.Arrow (arr, (<<<), (&&&))
import Control.Monad (liftM2, foldM)
import Control.Applicative (pure, liftA2, (<$>), (<*>))
import qualified Data.Foldable as Fold
import Data.Traversable (traverse)
import qualified Algebra.Transcendental as Trans
import qualified Algebra.Module as Module
import NumericPrelude.Numeric
import NumericPrelude.Base
instance (Tuple.Phi a) => Tuple.Phi (Parameter a) where
phi :: forall r.
BasicBlock -> Parameter a -> CodeGenFunction r (Parameter a)
phi = BasicBlock -> Parameter a -> CodeGenFunction r (Parameter a)
forall a (f :: * -> *) r.
(Phi a, Traversable f) =>
BasicBlock -> f a -> CodeGenFunction r (f a)
Tuple.phiTraversable
addPhi :: forall r.
BasicBlock -> Parameter a -> Parameter a -> CodeGenFunction r ()
addPhi = BasicBlock -> Parameter a -> Parameter a -> CodeGenFunction r ()
forall a (f :: * -> *) r.
(Phi a, Foldable f, Applicative f) =>
BasicBlock -> f a -> f a -> CodeGenFunction r ()
Tuple.addPhiFoldable
instance Tuple.Undefined a => Tuple.Undefined (Parameter a) where
undef :: Parameter a
undef = Parameter a
forall a (f :: * -> *). (Undefined a, Applicative f) => f a
Tuple.undefPointed
instance (Tuple.Value a) => Tuple.Value (Parameter a) where
type ValueOf (Parameter a) = Parameter (Tuple.ValueOf a)
valueOf :: Parameter a -> ValueOf (Parameter a)
valueOf = Parameter a -> ValueOf (Parameter a)
Parameter a -> Parameter (ValueOf a)
forall h (f :: * -> *).
(Value h, Functor f) =>
f h -> f (ValueOf h)
Tuple.valueOfFunctor
type ParameterStruct a = LLVM.Struct (a, (a, (a, (a, (a, ())))))
parameterMemory ::
(Memory.C a) =>
Memory.Record r (ParameterStruct (Memory.Struct a)) (Parameter a)
parameterMemory :: forall a r.
C a =>
Record r (ParameterStruct (Struct a)) (Parameter a)
parameterMemory =
(a -> a -> a -> a -> a -> Parameter a)
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
-> Element
r (ParameterStruct (Struct a)) (Parameter a) (Parameter a)
forall (m :: * -> *) a b c d e r.
Applicative m =>
(a -> b -> c -> d -> e -> r)
-> m a -> m b -> m c -> m d -> m e -> m r
App.lift5 a -> a -> a -> a -> a -> Parameter a
forall a. a -> a -> a -> a -> a -> Parameter a
Parameter
((Parameter a -> a)
-> Proxy D0
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element Parameter a -> a
forall a. Parameter a -> a
Filt2.c0 Proxy D0
d0)
((Parameter a -> a)
-> Proxy D1
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element Parameter a -> a
forall a. Parameter a -> a
Filt2.c1 Proxy D1
d1)
((Parameter a -> a)
-> Proxy D2
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element Parameter a -> a
forall a. Parameter a -> a
Filt2.c2 Proxy D2
d2)
((Parameter a -> a)
-> Proxy D3
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element Parameter a -> a
forall a. Parameter a -> a
Filt2.d1 Proxy D3
d3)
((Parameter a -> a)
-> Proxy D4
-> Element r (ParameterStruct (Struct a)) (Parameter a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element Parameter a -> a
forall a. Parameter a -> a
Filt2.d2 Proxy D4
d4)
decomposeParameter ::
LLVM.Value (ParameterStruct a) ->
CodeGenFunction r (Filt2.Parameter (LLVM.Value a))
decomposeParameter :: forall a r.
Value (ParameterStruct a)
-> CodeGenFunction r (Parameter (Value a))
decomposeParameter Value (ParameterStruct a)
param =
(Value a
-> Value a -> Value a -> Value a -> Value a -> Parameter (Value a))
-> CodeGenFunction
r
(Value a
-> Value a -> Value a -> Value a -> Value a -> Parameter (Value a))
forall a. a -> CodeGenFunction r a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value a
-> Value a -> Value a -> Value a -> Value a -> Parameter (Value a)
forall a. a -> a -> a -> a -> a -> Parameter a
Filt2.Parameter
CodeGenFunction
r
(Value a
-> Value a -> Value a -> Value a -> Value a -> Parameter (Value a))
-> CodeGenFunction r (Value a)
-> CodeGenFunction
r (Value a -> Value a -> Value a -> Value a -> Parameter (Value a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value (ParameterStruct a)
-> Proxy D0
-> CodeGenFunction
r (Value (ValueType (ParameterStruct a) (Proxy D0)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (ParameterStruct a)
param Proxy D0
TypeNum.d0
CodeGenFunction
r (Value a -> Value a -> Value a -> Value a -> Parameter (Value a))
-> CodeGenFunction r (Value a)
-> CodeGenFunction
r (Value a -> Value a -> Value a -> Parameter (Value a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value (ParameterStruct a)
-> Proxy D1
-> CodeGenFunction
r (Value (ValueType (ParameterStruct a) (Proxy D1)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (ParameterStruct a)
param Proxy D1
TypeNum.d1
CodeGenFunction
r (Value a -> Value a -> Value a -> Parameter (Value a))
-> CodeGenFunction r (Value a)
-> CodeGenFunction r (Value a -> Value a -> Parameter (Value a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value (ParameterStruct a)
-> Proxy D2
-> CodeGenFunction
r (Value (ValueType (ParameterStruct a) (Proxy D2)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (ParameterStruct a)
param Proxy D2
TypeNum.d2
CodeGenFunction r (Value a -> Value a -> Parameter (Value a))
-> CodeGenFunction r (Value a)
-> CodeGenFunction r (Value a -> Parameter (Value a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value (ParameterStruct a)
-> Proxy D3
-> CodeGenFunction
r (Value (ValueType (ParameterStruct a) (Proxy D3)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (ParameterStruct a)
param Proxy D3
TypeNum.d3
CodeGenFunction r (Value a -> Parameter (Value a))
-> CodeGenFunction r (Value a)
-> CodeGenFunction r (Parameter (Value a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value (ParameterStruct a)
-> Proxy D4
-> CodeGenFunction
r (Value (ValueType (ParameterStruct a) (Proxy D4)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (ParameterStruct a)
param Proxy D4
TypeNum.d4
decomposeParameterMV ::
(MarshalMV.C a) =>
LLVM.Value (MarshalMV.Struct (Parameter a)) ->
CodeGenFunction r (Filt2.Parameter (MultiValue.T a))
decomposeParameterMV :: forall a r.
C a =>
Value (Struct (Parameter a)) -> CodeGenFunction r (Parameter (T a))
decomposeParameterMV Value (Struct (Parameter a))
param =
(T a -> T a -> T a -> T a -> T a -> Parameter (T a))
-> CodeGenFunction
r (T a -> T a -> T a -> T a -> T a -> Parameter (T a))
forall a. a -> CodeGenFunction r a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a -> T a -> T a -> T a -> T a -> Parameter (T a)
forall a. a -> a -> a -> a -> a -> Parameter a
Filt2.Parameter
CodeGenFunction
r (T a -> T a -> T a -> T a -> T a -> Parameter (T a))
-> CodeGenFunction r (T a)
-> CodeGenFunction r (T a -> T a -> T a -> T a -> Parameter (T a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Value (Struct (Repr a)) -> CodeGenFunction r (T a)
Value (Struct (T a)) -> CodeGenFunction r (T a)
forall llvmValue r.
C llvmValue =>
Value (Struct llvmValue) -> CodeGenFunction r llvmValue
forall r. Value (Struct (T a)) -> CodeGenFunction r (T a)
Memory.decompose (Value (Struct (Repr a)) -> CodeGenFunction r (T a))
-> CodeGenFunction r (Value (Struct (Repr a)))
-> CodeGenFunction r (T a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value (ParameterStruct (Struct (Repr a)))
-> Proxy D0
-> CodeGenFunction
r
(Value (ValueType (ParameterStruct (Struct (Repr a))) (Proxy D0)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (Struct (Parameter a))
Value (ParameterStruct (Struct (Repr a)))
param Proxy D0
TypeNum.d0)
CodeGenFunction r (T a -> T a -> T a -> T a -> Parameter (T a))
-> CodeGenFunction r (T a)
-> CodeGenFunction r (T a -> T a -> T a -> Parameter (T a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Value (Struct (Repr a)) -> CodeGenFunction r (T a)
Value (Struct (T a)) -> CodeGenFunction r (T a)
forall llvmValue r.
C llvmValue =>
Value (Struct llvmValue) -> CodeGenFunction r llvmValue
forall r. Value (Struct (T a)) -> CodeGenFunction r (T a)
Memory.decompose (Value (Struct (Repr a)) -> CodeGenFunction r (T a))
-> CodeGenFunction r (Value (Struct (Repr a)))
-> CodeGenFunction r (T a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value (ParameterStruct (Struct (Repr a)))
-> Proxy D1
-> CodeGenFunction
r
(Value (ValueType (ParameterStruct (Struct (Repr a))) (Proxy D1)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (Struct (Parameter a))
Value (ParameterStruct (Struct (Repr a)))
param Proxy D1
TypeNum.d1)
CodeGenFunction r (T a -> T a -> T a -> Parameter (T a))
-> CodeGenFunction r (T a)
-> CodeGenFunction r (T a -> T a -> Parameter (T a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Value (Struct (Repr a)) -> CodeGenFunction r (T a)
Value (Struct (T a)) -> CodeGenFunction r (T a)
forall llvmValue r.
C llvmValue =>
Value (Struct llvmValue) -> CodeGenFunction r llvmValue
forall r. Value (Struct (T a)) -> CodeGenFunction r (T a)
Memory.decompose (Value (Struct (Repr a)) -> CodeGenFunction r (T a))
-> CodeGenFunction r (Value (Struct (Repr a)))
-> CodeGenFunction r (T a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value (ParameterStruct (Struct (Repr a)))
-> Proxy D2
-> CodeGenFunction
r
(Value (ValueType (ParameterStruct (Struct (Repr a))) (Proxy D2)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (Struct (Parameter a))
Value (ParameterStruct (Struct (Repr a)))
param Proxy D2
TypeNum.d2)
CodeGenFunction r (T a -> T a -> Parameter (T a))
-> CodeGenFunction r (T a)
-> CodeGenFunction r (T a -> Parameter (T a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Value (Struct (Repr a)) -> CodeGenFunction r (T a)
Value (Struct (T a)) -> CodeGenFunction r (T a)
forall llvmValue r.
C llvmValue =>
Value (Struct llvmValue) -> CodeGenFunction r llvmValue
forall r. Value (Struct (T a)) -> CodeGenFunction r (T a)
Memory.decompose (Value (Struct (Repr a)) -> CodeGenFunction r (T a))
-> CodeGenFunction r (Value (Struct (Repr a)))
-> CodeGenFunction r (T a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value (ParameterStruct (Struct (Repr a)))
-> Proxy D3
-> CodeGenFunction
r
(Value (ValueType (ParameterStruct (Struct (Repr a))) (Proxy D3)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (Struct (Parameter a))
Value (ParameterStruct (Struct (Repr a)))
param Proxy D3
TypeNum.d3)
CodeGenFunction r (T a -> Parameter (T a))
-> CodeGenFunction r (T a) -> CodeGenFunction r (Parameter (T a))
forall a b.
CodeGenFunction r (a -> b)
-> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Value (Struct (Repr a)) -> CodeGenFunction r (T a)
Value (Struct (T a)) -> CodeGenFunction r (T a)
forall llvmValue r.
C llvmValue =>
Value (Struct llvmValue) -> CodeGenFunction r llvmValue
forall r. Value (Struct (T a)) -> CodeGenFunction r (T a)
Memory.decompose (Value (Struct (Repr a)) -> CodeGenFunction r (T a))
-> CodeGenFunction r (Value (Struct (Repr a)))
-> CodeGenFunction r (T a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value (ParameterStruct (Struct (Repr a)))
-> Proxy D4
-> CodeGenFunction
r
(Value (ValueType (ParameterStruct (Struct (Repr a))) (Proxy D4)))
forall r agg i.
GetValue agg i =>
Value agg -> i -> CodeGenFunction r (Value (ValueType agg i))
LLVM.extractvalue Value (Struct (Parameter a))
Value (ParameterStruct (Struct (Repr a)))
param Proxy D4
TypeNum.d4)
composeParameter ::
(LLVM.IsSized a) =>
Filt2.Parameter (LLVM.Value a) ->
CodeGenFunction r (LLVM.Value (ParameterStruct a))
composeParameter :: forall a r.
IsSized a =>
Parameter (Value a)
-> CodeGenFunction r (Value (ParameterStruct a))
composeParameter (Filt2.Parameter Value a
c0_ Value a
c1_ Value a
c2_ Value a
d1_ Value a
d2_) =
(\Value (ParameterStruct a)
param -> Value (ParameterStruct a)
-> Value (ValueType (ParameterStruct a) (Proxy D0))
-> Proxy D0
-> CodeGenFunction r (Value (ParameterStruct a))
forall r agg i.
GetValue agg i =>
Value agg
-> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
LLVM.insertvalue Value (ParameterStruct a)
param Value a
Value (ValueType (ParameterStruct a) (Proxy D0))
c0_ Proxy D0
TypeNum.d0) (Value (ParameterStruct a)
-> CodeGenFunction r (Value (ParameterStruct a)))
-> CodeGenFunction r (Value (ParameterStruct a))
-> CodeGenFunction r (Value (ParameterStruct a))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(\Value (ParameterStruct a)
param -> Value (ParameterStruct a)
-> Value (ValueType (ParameterStruct a) (Proxy D1))
-> Proxy D1
-> CodeGenFunction r (Value (ParameterStruct a))
forall r agg i.
GetValue agg i =>
Value agg
-> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
LLVM.insertvalue Value (ParameterStruct a)
param Value a
Value (ValueType (ParameterStruct a) (Proxy D1))
c1_ Proxy D1
TypeNum.d1) (Value (ParameterStruct a)
-> CodeGenFunction r (Value (ParameterStruct a)))
-> CodeGenFunction r (Value (ParameterStruct a))
-> CodeGenFunction r (Value (ParameterStruct a))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(\Value (ParameterStruct a)
param -> Value (ParameterStruct a)
-> Value (ValueType (ParameterStruct a) (Proxy D2))
-> Proxy D2
-> CodeGenFunction r (Value (ParameterStruct a))
forall r agg i.
GetValue agg i =>
Value agg
-> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
LLVM.insertvalue Value (ParameterStruct a)
param Value a
Value (ValueType (ParameterStruct a) (Proxy D2))
c2_ Proxy D2
TypeNum.d2) (Value (ParameterStruct a)
-> CodeGenFunction r (Value (ParameterStruct a)))
-> CodeGenFunction r (Value (ParameterStruct a))
-> CodeGenFunction r (Value (ParameterStruct a))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(\Value (ParameterStruct a)
param -> Value (ParameterStruct a)
-> Value (ValueType (ParameterStruct a) (Proxy D3))
-> Proxy D3
-> CodeGenFunction r (Value (ParameterStruct a))
forall r agg i.
GetValue agg i =>
Value agg
-> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
LLVM.insertvalue Value (ParameterStruct a)
param Value a
Value (ValueType (ParameterStruct a) (Proxy D3))
d1_ Proxy D3
TypeNum.d3) (Value (ParameterStruct a)
-> CodeGenFunction r (Value (ParameterStruct a)))
-> CodeGenFunction r (Value (ParameterStruct a))
-> CodeGenFunction r (Value (ParameterStruct a))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(\Value (ParameterStruct a)
param -> Value (ParameterStruct a)
-> Value (ValueType (ParameterStruct a) (Proxy D4))
-> Proxy D4
-> CodeGenFunction r (Value (ParameterStruct a))
forall r agg i.
GetValue agg i =>
Value agg
-> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
LLVM.insertvalue Value (ParameterStruct a)
param Value a
Value (ValueType (ParameterStruct a) (Proxy D4))
d2_ Proxy D4
TypeNum.d4) (Value (ParameterStruct a)
-> CodeGenFunction r (Value (ParameterStruct a)))
-> CodeGenFunction r (Value (ParameterStruct a))
-> CodeGenFunction r (Value (ParameterStruct a))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
Value (ParameterStruct a)
-> CodeGenFunction r (Value (ParameterStruct a))
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (ConstValue (ParameterStruct a) -> Value (ParameterStruct a)
forall a. ConstValue a -> Value a
LLVM.value ConstValue (ParameterStruct a)
forall a. IsType a => ConstValue a
LLVM.undef)
composeParameterMV ::
(MarshalMV.C a) =>
Filt2.Parameter (MultiValue.T a) ->
CodeGenFunction r (LLVM.Value (MarshalMV.Struct (Parameter a)))
composeParameterMV :: forall a r.
C a =>
Parameter (T a) -> CodeGenFunction r (Value (Struct (Parameter a)))
composeParameterMV (Filt2.Parameter T a
c0_ T a
c1_ T a
c2_ T a
d1_ T a
d2_) =
let insert :: llvmValue -> b -> Value agg -> CodeGenFunction r (Value agg)
insert llvmValue
field b
ix Value agg
param =
llvmValue -> CodeGenFunction r (Value (Struct llvmValue))
forall r. llvmValue -> CodeGenFunction r (Value (Struct llvmValue))
forall llvmValue r.
C llvmValue =>
llvmValue -> CodeGenFunction r (Value (Struct llvmValue))
Memory.compose llvmValue
field CodeGenFunction r (Value (Struct llvmValue))
-> (Value (Struct llvmValue) -> CodeGenFunction r (Value agg))
-> CodeGenFunction r (Value agg)
forall a b.
CodeGenFunction r a
-> (a -> CodeGenFunction r b) -> CodeGenFunction r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Value (Struct llvmValue) -> b -> CodeGenFunction r (Value agg))
-> b -> Value (Struct llvmValue) -> CodeGenFunction r (Value agg)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Value agg
-> Value (ValueType agg b) -> b -> CodeGenFunction r (Value agg)
forall r agg i.
GetValue agg i =>
Value agg
-> Value (ValueType agg i) -> i -> CodeGenFunction r (Value agg)
LLVM.insertvalue Value agg
param) b
ix in
T a
-> Proxy D0
-> Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall {agg} {b} {llvmValue} {r}.
(ValueType agg b ~ Struct llvmValue, C llvmValue,
GetValue agg b) =>
llvmValue -> b -> Value agg -> CodeGenFunction r (Value agg)
insert T a
c0_ Proxy D0
TypeNum.d0 (Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a)))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
T a
-> Proxy D1
-> Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall {agg} {b} {llvmValue} {r}.
(ValueType agg b ~ Struct llvmValue, C llvmValue,
GetValue agg b) =>
llvmValue -> b -> Value agg -> CodeGenFunction r (Value agg)
insert T a
c1_ Proxy D1
TypeNum.d1 (Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a)))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
T a
-> Proxy D2
-> Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall {agg} {b} {llvmValue} {r}.
(ValueType agg b ~ Struct llvmValue, C llvmValue,
GetValue agg b) =>
llvmValue -> b -> Value agg -> CodeGenFunction r (Value agg)
insert T a
c2_ Proxy D2
TypeNum.d2 (Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a)))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
T a
-> Proxy D3
-> Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall {agg} {b} {llvmValue} {r}.
(ValueType agg b ~ Struct llvmValue, C llvmValue,
GetValue agg b) =>
llvmValue -> b -> Value agg -> CodeGenFunction r (Value agg)
insert T a
d1_ Proxy D3
TypeNum.d3 (Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a)))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
T a
-> Proxy D4
-> Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall {agg} {b} {llvmValue} {r}.
(ValueType agg b ~ Struct llvmValue, C llvmValue,
GetValue agg b) =>
llvmValue -> b -> Value agg -> CodeGenFunction r (Value agg)
insert T a
d2_ Proxy D4
TypeNum.d4 (Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a)))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
Value (ParameterStruct (Struct (Repr a)))
-> CodeGenFunction r (Value (ParameterStruct (Struct (Repr a))))
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (ConstValue (ParameterStruct (Struct (Repr a)))
-> Value (ParameterStruct (Struct (Repr a)))
forall a. ConstValue a -> Value a
LLVM.value ConstValue (ParameterStruct (Struct (Repr a)))
forall a. IsType a => ConstValue a
LLVM.undef)
instance (Memory.C a) => Memory.C (Parameter a) where
type Struct (Parameter a) = ParameterStruct (Memory.Struct a)
load :: forall r.
Value (Ptr (Struct (Parameter a)))
-> CodeGenFunction r (Parameter a)
load = Record r (ParameterStruct (Struct a)) (Parameter a)
-> Value (Ptr (ParameterStruct (Struct a)))
-> CodeGenFunction r (Parameter a)
forall r o llvmValue.
Record r o llvmValue
-> Value (Ptr o) -> CodeGenFunction r llvmValue
Memory.loadRecord Record r (ParameterStruct (Struct a)) (Parameter a)
forall a r.
C a =>
Record r (ParameterStruct (Struct a)) (Parameter a)
parameterMemory
store :: forall r.
Parameter a
-> Value (Ptr (Struct (Parameter a))) -> CodeGenFunction r ()
store = Record r (ParameterStruct (Struct a)) (Parameter a)
-> Parameter a
-> Value (Ptr (ParameterStruct (Struct a)))
-> CodeGenFunction r ()
forall r o llvmValue.
Record r o llvmValue
-> llvmValue -> Value (Ptr o) -> CodeGenFunction r ()
Memory.storeRecord Record r (ParameterStruct (Struct a)) (Parameter a)
forall a r.
C a =>
Record r (ParameterStruct (Struct a)) (Parameter a)
parameterMemory
decompose :: forall r.
Value (Struct (Parameter a)) -> CodeGenFunction r (Parameter a)
decompose = Record r (ParameterStruct (Struct a)) (Parameter a)
-> Value (ParameterStruct (Struct a))
-> CodeGenFunction r (Parameter a)
forall r o llvmValue.
Record r o llvmValue -> Value o -> CodeGenFunction r llvmValue
Memory.decomposeRecord Record r (ParameterStruct (Struct a)) (Parameter a)
forall a r.
C a =>
Record r (ParameterStruct (Struct a)) (Parameter a)
parameterMemory
compose :: forall r.
Parameter a -> CodeGenFunction r (Value (Struct (Parameter a)))
compose = Record r (ParameterStruct (Struct a)) (Parameter a)
-> Parameter a
-> CodeGenFunction r (Value (ParameterStruct (Struct a)))
forall o r llvmValue.
IsType o =>
Record r o llvmValue -> llvmValue -> CodeGenFunction r (Value o)
Memory.composeRecord Record r (ParameterStruct (Struct a)) (Parameter a)
forall a r.
C a =>
Record r (ParameterStruct (Struct a)) (Parameter a)
parameterMemory
instance (Marshal.C a) => Marshal.C (Parameter a) where
pack :: Parameter a -> Struct (Parameter a)
pack Parameter a
p =
case a -> Struct a
forall a. C a => a -> Struct a
Marshal.pack (a -> Struct a) -> Parameter a -> Parameter (Struct a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parameter a
p of
Filt2.Parameter Struct a
c0_ Struct a
c1_ Struct a
c2_ Struct a
d1_ Struct a
d2_ ->
Struct a
-> Struct a
-> Struct a
-> Struct a
-> Struct a
-> ParameterStruct (Struct a)
forall f. (ConsStruct f, ConsResult f ~ PartialStruct f) => f
LLVM.consStruct Struct a
c0_ Struct a
c1_ Struct a
c2_ Struct a
d1_ Struct a
d2_
unpack :: Struct (Parameter a) -> Parameter a
unpack = (Struct a -> a) -> Parameter (Struct a) -> Parameter a
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Struct a -> a
forall a. C a => Struct a -> a
Marshal.unpack (Parameter (Struct a) -> Parameter a)
-> (ParameterStruct (Struct a) -> Parameter (Struct a))
-> ParameterStruct (Struct a)
-> Parameter a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Curried
(Struct a, (Struct a, (Struct a, (Struct a, (Struct a, ())))))
(Parameter (Struct a))
-> ParameterStruct (Struct a) -> Parameter (Struct a)
forall a b. CurryStruct a => Curried a b -> Struct a -> b
LLVM.uncurryStruct Curried
(Struct a, (Struct a, (Struct a, (Struct a, (Struct a, ())))))
(Parameter (Struct a))
Struct a
-> Struct a
-> Struct a
-> Struct a
-> Struct a
-> Parameter (Struct a)
forall a. a -> a -> a -> a -> a -> Parameter a
Filt2.Parameter
instance (Storable.C a) => Storable.C (Parameter a) where
load :: forall r.
Value (Ptr (Parameter a))
-> CodeGenFunction r (ValueOf (Parameter a))
load = Value (Ptr (Parameter a))
-> CodeGenFunction r (ValueOf (Parameter a))
Value (Ptr (Parameter a))
-> CodeGenFunction r (Parameter (ValueOf a))
forall (f :: * -> *) a al r.
(Applicative f, Traversable f, C a, ValueOf a ~ al) =>
Value (Ptr (f a)) -> CodeGenFunction r (f al)
Storable.loadApplicative
store :: forall r.
ValueOf (Parameter a)
-> Value (Ptr (Parameter a)) -> CodeGenFunction r ()
store = ValueOf (Parameter a)
-> Value (Ptr (Parameter a)) -> CodeGenFunction r ()
Parameter (ValueOf a)
-> Value (Ptr (Parameter a)) -> CodeGenFunction r ()
forall (f :: * -> *) a al r.
(Foldable f, C a, ValueOf a ~ al) =>
f al -> Value (Ptr (f a)) -> CodeGenFunction r ()
Storable.storeFoldable
instance (Value.Flatten a) => Value.Flatten (Parameter a) where
type Registers (Parameter a) = Parameter (Value.Registers a)
flattenCode :: forall r. Parameter a -> Compute r (Registers (Parameter a))
flattenCode = Parameter a
-> StateT Vault (CodeGenFunction r) (Registers (Parameter a))
Parameter a -> Compute r (Parameter (Registers a))
forall value (f :: * -> *) r.
(Flatten value, Traversable f) =>
f value -> Compute r (f (Registers value))
Value.flattenCodeTraversable
unfoldCode :: T (Registers (Parameter a)) -> Parameter a
unfoldCode = T (Registers (Parameter a)) -> Parameter a
T (Parameter (Registers a)) -> Parameter a
forall value (f :: * -> *).
(Flatten value, Traversable f, Applicative f) =>
T (f (Registers value)) -> f value
Value.unfoldCodeTraversable
instance (MultiValue.C a) => MultiValue.C (Parameter a) where
type Repr (Parameter a) = Parameter (MultiValue.Repr a)
cons :: Parameter a -> T (Parameter a)
cons = Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
parameterMultiValue (Parameter (T a) -> T (Parameter a))
-> (Parameter a -> Parameter (T a))
-> Parameter a
-> T (Parameter a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> T a) -> Parameter a -> Parameter (T a)
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> T a
forall a. C a => a -> T a
MultiValue.cons
undef :: T (Parameter a)
undef = Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
parameterMultiValue (Parameter (T a) -> T (Parameter a))
-> Parameter (T a) -> T (Parameter a)
forall a b. (a -> b) -> a -> b
$ T a -> Parameter (T a)
forall a. a -> Parameter a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a
forall a. C a => T a
MultiValue.undef
zero :: T (Parameter a)
zero = Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
parameterMultiValue (Parameter (T a) -> T (Parameter a))
-> Parameter (T a) -> T (Parameter a)
forall a b. (a -> b) -> a -> b
$ T a -> Parameter (T a)
forall a. a -> Parameter a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a
forall a. C a => T a
MultiValue.zero
phi :: forall r.
BasicBlock
-> T (Parameter a) -> CodeGenFunction r (T (Parameter a))
phi BasicBlock
bb =
(Parameter (T a) -> T (Parameter a))
-> CodeGenFunction r (Parameter (T a))
-> CodeGenFunction r (T (Parameter a))
forall a b. (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
parameterMultiValue (CodeGenFunction r (Parameter (T a))
-> CodeGenFunction r (T (Parameter a)))
-> (T (Parameter a) -> CodeGenFunction r (Parameter (T a)))
-> T (Parameter a)
-> CodeGenFunction r (T (Parameter a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(T a -> CodeGenFunction r (T a))
-> Parameter (T a) -> CodeGenFunction r (Parameter (T a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Parameter a -> f (Parameter b)
traverse (BasicBlock -> T a -> CodeGenFunction r (T a)
forall a r. C a => BasicBlock -> T a -> CodeGenFunction r (T a)
forall r. BasicBlock -> T a -> CodeGenFunction r (T a)
MultiValue.phi BasicBlock
bb) (Parameter (T a) -> CodeGenFunction r (Parameter (T a)))
-> (T (Parameter a) -> Parameter (T a))
-> T (Parameter a)
-> CodeGenFunction r (Parameter (T a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
T (Parameter a) -> Parameter (T a)
forall a. T (Parameter a) -> Parameter (T a)
parameterUnMultiValue
addPhi :: forall r.
BasicBlock
-> T (Parameter a) -> T (Parameter a) -> CodeGenFunction r ()
addPhi BasicBlock
bb T (Parameter a)
a T (Parameter a)
b =
Parameter (CodeGenFunction r ()) -> CodeGenFunction r ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
Fold.sequence_ (Parameter (CodeGenFunction r ()) -> CodeGenFunction r ())
-> Parameter (CodeGenFunction r ()) -> CodeGenFunction r ()
forall a b. (a -> b) -> a -> b
$
(T a -> T a -> CodeGenFunction r ())
-> Parameter (T a)
-> Parameter (T a)
-> Parameter (CodeGenFunction r ())
forall a b c.
(a -> b -> c) -> Parameter a -> Parameter b -> Parameter c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (BasicBlock -> T a -> T a -> CodeGenFunction r ()
forall a r. C a => BasicBlock -> T a -> T a -> CodeGenFunction r ()
forall r. BasicBlock -> T a -> T a -> CodeGenFunction r ()
MultiValue.addPhi BasicBlock
bb)
(T (Parameter a) -> Parameter (T a)
forall a. T (Parameter a) -> Parameter (T a)
parameterUnMultiValue T (Parameter a)
a) (T (Parameter a) -> Parameter (T a)
forall a. T (Parameter a) -> Parameter (T a)
parameterUnMultiValue T (Parameter a)
b)
instance (MarshalMV.C a) => MarshalMV.C (Parameter a) where
pack :: Parameter a -> Struct (Parameter a)
pack Parameter a
p =
case a -> Struct (Repr a)
forall a. C a => a -> Struct a
MarshalMV.pack (a -> Struct (Repr a))
-> Parameter a -> Parameter (Struct (Repr a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parameter a
p of
Filt2.Parameter Struct (Repr a)
c0_ Struct (Repr a)
c1_ Struct (Repr a)
c2_ Struct (Repr a)
d1_ Struct (Repr a)
d2_ ->
Struct (Repr a)
-> Struct (Repr a)
-> Struct (Repr a)
-> Struct (Repr a)
-> Struct (Repr a)
-> ParameterStruct (Struct (Repr a))
forall f. (ConsStruct f, ConsResult f ~ PartialStruct f) => f
LLVM.consStruct Struct (Repr a)
c0_ Struct (Repr a)
c1_ Struct (Repr a)
c2_ Struct (Repr a)
d1_ Struct (Repr a)
d2_
unpack :: Struct (Parameter a) -> Parameter a
unpack = (Struct (Repr a) -> a)
-> Parameter (Struct (Repr a)) -> Parameter a
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Struct (Repr a) -> a
forall a. C a => Struct a -> a
MarshalMV.unpack (Parameter (Struct (Repr a)) -> Parameter a)
-> (ParameterStruct (Struct (Repr a))
-> Parameter (Struct (Repr a)))
-> ParameterStruct (Struct (Repr a))
-> Parameter a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Curried
(Struct (Repr a),
(Struct (Repr a),
(Struct (Repr a), (Struct (Repr a), (Struct (Repr a), ())))))
(Parameter (Struct (Repr a)))
-> ParameterStruct (Struct (Repr a)) -> Parameter (Struct (Repr a))
forall a b. CurryStruct a => Curried a b -> Struct a -> b
LLVM.uncurryStruct Curried
(Struct (Repr a),
(Struct (Repr a),
(Struct (Repr a), (Struct (Repr a), (Struct (Repr a), ())))))
(Parameter (Struct (Repr a)))
Struct (Repr a)
-> Struct (Repr a)
-> Struct (Repr a)
-> Struct (Repr a)
-> Struct (Repr a)
-> Parameter (Struct (Repr a))
forall a. a -> a -> a -> a -> a -> Parameter a
Filt2.Parameter
parameterMultiValue ::
Parameter (MultiValue.T a) -> MultiValue.T (Parameter a)
parameterMultiValue :: forall a. Parameter (T a) -> T (Parameter a)
parameterMultiValue =
Repr (Parameter a) -> T (Parameter a)
Parameter (Repr a) -> T (Parameter a)
forall a. Repr a -> T a
MultiValue.Cons (Parameter (Repr a) -> T (Parameter a))
-> (Parameter (T a) -> Parameter (Repr a))
-> Parameter (T a)
-> T (Parameter a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (T a -> Repr a) -> Parameter (T a) -> Parameter (Repr a)
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(MultiValue.Cons Repr a
a) -> Repr a
a)
parameterUnMultiValue ::
MultiValue.T (Parameter a) -> Parameter (MultiValue.T a)
parameterUnMultiValue :: forall a. T (Parameter a) -> Parameter (T a)
parameterUnMultiValue (MultiValue.Cons Repr (Parameter a)
x) =
(Repr a -> T a) -> Parameter (Repr a) -> Parameter (T a)
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Repr a -> T a
forall a. Repr a -> T a
MultiValue.Cons Repr (Parameter a)
Parameter (Repr a)
x
instance
(Expr.Aggregate e mv) =>
Expr.Aggregate (Parameter e) (Parameter mv) where
type MultiValuesOf (Parameter e) = Parameter (Expr.MultiValuesOf e)
type ExpressionsOf (Parameter mv) = Parameter (Expr.ExpressionsOf mv)
bundle :: forall r. Parameter e -> CodeGenFunction r (Parameter mv)
bundle = (e -> CodeGenFunction r mv)
-> Parameter e -> CodeGenFunction r (Parameter mv)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Parameter a -> f (Parameter b)
traverse e -> CodeGenFunction r mv
forall r. e -> CodeGenFunction r mv
forall exp mv r. Aggregate exp mv => exp -> CodeGenFunction r mv
Expr.bundle
dissect :: Parameter mv -> Parameter e
dissect = (mv -> e) -> Parameter mv -> Parameter e
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap mv -> e
forall exp mv. Aggregate exp mv => mv -> exp
Expr.dissect
instance (Tuple.Phi a) => Tuple.Phi (Filt2.State a) where
phi :: forall r. BasicBlock -> State a -> CodeGenFunction r (State a)
phi = BasicBlock -> State a -> CodeGenFunction r (State a)
forall a (f :: * -> *) r.
(Phi a, Traversable f) =>
BasicBlock -> f a -> CodeGenFunction r (f a)
Tuple.phiTraversable
addPhi :: forall r. BasicBlock -> State a -> State a -> CodeGenFunction r ()
addPhi = BasicBlock -> State a -> State a -> CodeGenFunction r ()
forall a (f :: * -> *) r.
(Phi a, Foldable f, Applicative f) =>
BasicBlock -> f a -> f a -> CodeGenFunction r ()
Tuple.addPhiFoldable
instance Tuple.Undefined a => Tuple.Undefined (Filt2.State a) where
undef :: State a
undef = State a
forall a (f :: * -> *). (Undefined a, Applicative f) => f a
Tuple.undefPointed
type StateStruct a = LLVM.Struct (a, (a, (a, (a, (a, ())))))
stateMemory ::
(Memory.C a) =>
Memory.Record r (StateStruct (Memory.Struct a)) (Filt2.State a)
stateMemory :: forall a r. C a => Record r (StateStruct (Struct a)) (State a)
stateMemory =
(a -> a -> a -> a -> State a)
-> Element r (StateStruct (Struct a)) (State a) a
-> Element r (StateStruct (Struct a)) (State a) a
-> Element r (StateStruct (Struct a)) (State a) a
-> Element r (StateStruct (Struct a)) (State a) a
-> Element r (StateStruct (Struct a)) (State a) (State a)
forall (m :: * -> *) a b c d r.
Applicative m =>
(a -> b -> c -> d -> r) -> m a -> m b -> m c -> m d -> m r
App.lift4 a -> a -> a -> a -> State a
forall a. a -> a -> a -> a -> State a
Filt2.State
((State a -> a)
-> Proxy D0 -> Element r (StateStruct (Struct a)) (State a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element State a -> a
forall a. State a -> a
Filt2.u1 Proxy D0
d0)
((State a -> a)
-> Proxy D1 -> Element r (StateStruct (Struct a)) (State a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element State a -> a
forall a. State a -> a
Filt2.u2 Proxy D1
d1)
((State a -> a)
-> Proxy D2 -> Element r (StateStruct (Struct a)) (State a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element State a -> a
forall a. State a -> a
Filt2.y1 Proxy D2
d2)
((State a -> a)
-> Proxy D3 -> Element r (StateStruct (Struct a)) (State a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element State a -> a
forall a. State a -> a
Filt2.y2 Proxy D3
d3)
instance (Memory.C a) => Memory.C (Filt2.State a) where
type Struct (Filt2.State a) = StateStruct (Memory.Struct a)
load :: forall r.
Value (Ptr (Struct (State a))) -> CodeGenFunction r (State a)
load = Record r (StateStruct (Struct a)) (State a)
-> Value (Ptr (StateStruct (Struct a)))
-> CodeGenFunction r (State a)
forall r o llvmValue.
Record r o llvmValue
-> Value (Ptr o) -> CodeGenFunction r llvmValue
Memory.loadRecord Record r (StateStruct (Struct a)) (State a)
forall a r. C a => Record r (StateStruct (Struct a)) (State a)
stateMemory
store :: forall r.
State a -> Value (Ptr (Struct (State a))) -> CodeGenFunction r ()
store = Record r (StateStruct (Struct a)) (State a)
-> State a
-> Value (Ptr (StateStruct (Struct a)))
-> CodeGenFunction r ()
forall r o llvmValue.
Record r o llvmValue
-> llvmValue -> Value (Ptr o) -> CodeGenFunction r ()
Memory.storeRecord Record r (StateStruct (Struct a)) (State a)
forall a r. C a => Record r (StateStruct (Struct a)) (State a)
stateMemory
decompose :: forall r. Value (Struct (State a)) -> CodeGenFunction r (State a)
decompose = Record r (StateStruct (Struct a)) (State a)
-> Value (StateStruct (Struct a)) -> CodeGenFunction r (State a)
forall r o llvmValue.
Record r o llvmValue -> Value o -> CodeGenFunction r llvmValue
Memory.decomposeRecord Record r (StateStruct (Struct a)) (State a)
forall a r. C a => Record r (StateStruct (Struct a)) (State a)
stateMemory
compose :: forall r. State a -> CodeGenFunction r (Value (Struct (State a)))
compose = Record r (StateStruct (Struct a)) (State a)
-> State a -> CodeGenFunction r (Value (StateStruct (Struct a)))
forall o r llvmValue.
IsType o =>
Record r o llvmValue -> llvmValue -> CodeGenFunction r (Value o)
Memory.composeRecord Record r (StateStruct (Struct a)) (State a)
forall a r. C a => Record r (StateStruct (Struct a)) (State a)
stateMemory
instance (Value.Flatten a) => Value.Flatten (Filt2.State a) where
type Registers (Filt2.State a) = Filt2.State (Value.Registers a)
flattenCode :: forall r. State a -> Compute r (Registers (State a))
flattenCode = State a -> StateT Vault (CodeGenFunction r) (Registers (State a))
State a -> Compute r (State (Registers a))
forall value (f :: * -> *) r.
(Flatten value, Traversable f) =>
f value -> Compute r (f (Registers value))
Value.flattenCodeTraversable
unfoldCode :: T (Registers (State a)) -> State a
unfoldCode = T (Registers (State a)) -> State a
T (State (Registers a)) -> State a
forall value (f :: * -> *).
(Flatten value, Traversable f, Applicative f) =>
T (f (Registers value)) -> f value
Value.unfoldCodeTraversable
instance
(Expr.Aggregate e mv) =>
Expr.Aggregate (Filt2.State e) (Filt2.State mv) where
type MultiValuesOf (Filt2.State e) = Filt2.State (Expr.MultiValuesOf e)
type ExpressionsOf (Filt2.State mv) = Filt2.State (Expr.ExpressionsOf mv)
bundle :: forall r. State e -> CodeGenFunction r (State mv)
bundle = (e -> CodeGenFunction r mv)
-> State e -> CodeGenFunction r (State mv)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> State a -> f (State b)
traverse e -> CodeGenFunction r mv
forall r. e -> CodeGenFunction r mv
forall exp mv r. Aggregate exp mv => exp -> CodeGenFunction r mv
Expr.bundle
dissect :: State mv -> State e
dissect = (mv -> e) -> State mv -> State e
forall a b. (a -> b) -> State a -> State b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap mv -> e
forall exp mv. Aggregate exp mv => mv -> exp
Expr.dissect
{-# DEPRECATED bandpassParameter "only for testing, use Universal or Moog filter for production code" #-}
bandpassParameterCode ::
(A.Transcendental a, A.RationalConstant a) =>
a -> a ->
CodeGenFunction r (Parameter a)
bandpassParameterCode :: forall a r.
(Transcendental a, RationalConstant a) =>
a -> a -> CodeGenFunction r (Parameter a)
bandpassParameterCode a
reson a
cutoff = do
a
rreson <- a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Field a => a -> a -> CodeGenFunction r a
A.fdiv a
forall a. IntegerConstant a => a
A.one a
reson
a
k <- a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.sub a
forall a. IntegerConstant a => a
A.one a
rreson
a
k2 <- a -> CodeGenFunction r a
forall r. a -> CodeGenFunction r a
forall a r. Additive a => a -> CodeGenFunction r a
A.neg (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul a
k a
k
a
kcos <-
a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul (Integer -> a
forall a. IntegerConstant a => Integer -> a
A.fromInteger' Integer
2) (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul a
k (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
a -> CodeGenFunction r a
forall r. a -> CodeGenFunction r a
forall a r. Transcendental a => a -> CodeGenFunction r a
A.cos (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul a
cutoff (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
T a -> forall r. CodeGenFunction r a
forall a. T a -> forall r. CodeGenFunction r a
Value.decons T a
forall a. (Transcendental a, RationalConstant a) => T a
Value.tau
Parameter a -> CodeGenFunction r (Parameter a)
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (Parameter a -> CodeGenFunction r (Parameter a))
-> Parameter a -> CodeGenFunction r (Parameter a)
forall a b. (a -> b) -> a -> b
$ a -> a -> a -> a -> a -> Parameter a
forall a. a -> a -> a -> a -> a -> Parameter a
Filt2.Parameter a
rreson a
forall a. Additive a => a
A.zero a
forall a. Additive a => a
A.zero a
kcos a
k2
bandpassParameter :: (Trans.C a) => a -> a -> Parameter a
bandpassParameter :: forall a. C a => a -> a -> Parameter a
bandpassParameter a
reson a
cutoff =
let rreson :: a
rreson = a -> a
forall a. C a => a -> a
recip a
reson
k :: a
k = a
forall a. C a => a
one a -> a -> a
forall a. C a => a -> a -> a
- a
rreson
in a -> a -> a -> a -> a -> Parameter a
forall a. a -> a -> a -> a -> a -> Parameter a
Filt2.Parameter a
rreson a
forall a. C a => a
zero a
forall a. C a => a
zero (a
2a -> a -> a
forall a. C a => a -> a -> a
*a
ka -> a -> a
forall a. C a => a -> a -> a
*a -> a
forall a. C a => a -> a
cos(a
2a -> a -> a
forall a. C a => a -> a -> a
*a
forall a. C a => a
pia -> a -> a
forall a. C a => a -> a -> a
*a
cutoff)) (-a
ka -> a -> a
forall a. C a => a -> a -> a
*a
k)
modifier ::
(a ~ A.Scalar v, A.PseudoModule v, A.IntegerConstant a) =>
Modifier.Simple
(Filt2.State (Value.T v))
(Parameter (Value.T a))
(Value.T v) (Value.T v)
modifier :: forall a v.
(a ~ Scalar v, PseudoModule v, IntegerConstant a) =>
Simple (State (T v)) (Parameter (T a)) (T v) (T v)
modifier =
Simple (State (T v)) (Parameter (T a)) (T v) (T v)
forall a v. (C a, C a v) => Simple (State v) (Parameter a) v v
Filt2.modifier
causal ::
(a ~ A.Scalar v, A.PseudoModule v, A.IntegerConstant a, Memory.C v) =>
Causal.T (Parameter a, v) v
causal :: forall a v.
(a ~ Scalar v, PseudoModule v, IntegerConstant a, C v) =>
T (Parameter a, v) v
causal =
Simple (State (T v)) (Parameter (T a)) (T v) (T v)
-> T (Parameter a, v) v
forall ah al bh bl ch cl sh sl.
(Flatten ah, Registers ah ~ al, Flatten bh, Registers bh ~ bl,
Flatten ch, Registers ch ~ cl, Flatten sh, Registers sh ~ sl,
C sl) =>
Simple sh ch ah bh -> T (cl, al) bl
Causal.fromModifier Simple (State (T v)) (Parameter (T a)) (T v) (T v)
forall a v.
(a ~ Scalar v, PseudoModule v, IntegerConstant a) =>
Simple (State (T v)) (Parameter (T a)) (T v) (T v)
modifier
causalExp ::
(Expr.Aggregate ae a, Memory.C a, Module.C ae ve,
Expr.Aggregate ve v, Memory.C v) =>
CausalExp.T (Parameter a, v) v
causalExp :: forall ae a ve v.
(Aggregate ae a, C a, C ae ve, Aggregate ve v, C v) =>
T (Parameter a, v) v
causalExp =
Simple (State ve) (Parameter ae) ve ve -> T (Parameter a, v) v
forall ae al be bl ce cl se sl.
(Aggregate ae al, Aggregate be bl, Aggregate ce cl,
Aggregate se sl, C sl) =>
Simple se ce ae be -> T (cl, al) bl
CausalExp.fromModifier Simple (State ve) (Parameter ae) ve ve
forall a v. (C a, C a v) => Simple (State v) (Parameter a) v v
Filt2.modifier
causalPacked,
causalRecursivePacked ::
(Serial.Write v, Serial.Element v ~ a,
Memory.C v, Memory.C a, A.IntegerConstant v, A.IntegerConstant a,
A.PseudoRing v, A.PseudoRing a) =>
Causal.T (Parameter a, v) v
causalPacked :: forall v a.
(Write v, Element v ~ a, C v, C a, IntegerConstant v,
IntegerConstant a, PseudoRing v, PseudoRing a) =>
T (Parameter a, v) v
causalPacked =
T (Parameter a, v) v
forall v a.
(Write v, Element v ~ a, C v, C a, IntegerConstant v,
IntegerConstant a, PseudoRing v, PseudoRing a) =>
T (Parameter a, v) v
causalRecursivePacked T (Parameter a, v) v
-> T (Parameter a, v) (Parameter a, v) -> T (Parameter a, v) v
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<<
(((Parameter a, v) -> Parameter a)
-> T (Parameter a, v) (Parameter a)
forall b c. (b -> c) -> T b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (Parameter a, v) -> Parameter a
forall a b. (a, b) -> a
fst T (Parameter a, v) (Parameter a)
-> T (Parameter a, v) v -> T (Parameter a, v) (Parameter a, v)
forall b c c'. T b c -> T b c' -> T b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& T (Parameter a, v) v
forall v a.
(Write v, Element v ~ a, C a, IntegerConstant v, IntegerConstant a,
PseudoRing v, PseudoRing a) =>
T (Parameter a, v) v
causalNonRecursivePacked)
_causalRecursivePackedAlt,
causalNonRecursivePacked ::
(Serial.Write v, Serial.Element v ~ a,
Memory.C a, A.IntegerConstant v, A.IntegerConstant a,
A.PseudoRing v, A.PseudoRing a) =>
Causal.T (Parameter a, v) v
causalNonRecursivePacked :: forall v a.
(Write v, Element v ~ a, C a, IntegerConstant v, IntegerConstant a,
PseudoRing v, PseudoRing a) =>
T (Parameter a, v) v
causalNonRecursivePacked =
(forall r.
(Parameter a, v) -> (a, a) -> CodeGenFunction r (v, (a, a)))
-> (forall r. CodeGenFunction r (a, a)) -> T (Parameter a, v) v
forall state a b.
C state =>
(forall r. a -> state -> CodeGenFunction r (b, state))
-> (forall r. CodeGenFunction r state) -> T a b
Causal.mapAccum
(\(Parameter a
p, v
v0) (a
x1,a
x2) -> do
(a
u1n,v
v1) <- Element v -> v -> CodeGenFunction r (Element v, v)
forall v r.
Write v =>
Element v -> v -> CodeGenFunction r (Element v, v)
Serial.shiftUp a
Element v
x1 v
v0
(a
u2n,v
v2) <- Element v -> v -> CodeGenFunction r (Element v, v)
forall v r.
Write v =>
Element v -> v -> CodeGenFunction r (Element v, v)
Serial.shiftUp a
Element v
x2 v
v1
v
w0 <- v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
v0 (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (Parameter a -> a
forall a. Parameter a -> a
Filt2.c0 Parameter a
p)
v
w1 <- v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
v1 (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (Parameter a -> a
forall a. Parameter a -> a
Filt2.c1 Parameter a
p)
v
w2 <- v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
v2 (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (Parameter a -> a
forall a. Parameter a -> a
Filt2.c2 Parameter a
p)
v
y <- v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add v
w0 (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add v
w1 v
w2
(v, (a, a)) -> CodeGenFunction r (v, (a, a))
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (v
y, (a
u1n,a
u2n)))
((a, a) -> CodeGenFunction r (a, a)
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
forall a. Additive a => a
A.zero, a
forall a. Additive a => a
A.zero))
causalRecursivePacked :: forall v a.
(Write v, Element v ~ a, C v, C a, IntegerConstant v,
IntegerConstant a, PseudoRing v, PseudoRing a) =>
T (Parameter a, v) v
causalRecursivePacked =
(forall r. (Parameter a, v) -> v -> CodeGenFunction r (v, v))
-> (forall r. CodeGenFunction r v) -> T (Parameter a, v) v
forall state a b.
C state =>
(forall r. a -> state -> CodeGenFunction r (b, state))
-> (forall r. CodeGenFunction r state) -> T a b
Causal.mapAccum
(\(Parameter a
p, v
x0) v
y1v -> do
let size :: Int
size = v -> Int
forall v i. (Sized v, Integral i) => v -> i
Serial.size v
x0
v
d1v <- Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (Parameter a -> a
forall a. Parameter a -> a
Filt2.d1 Parameter a
p)
v
d2v <- Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (Parameter a -> a
forall a. Parameter a -> a
Filt2.d2 Parameter a
p)
v
d2vn <- v -> CodeGenFunction r v
forall r. v -> CodeGenFunction r v
forall a r. Additive a => a -> CodeGenFunction r a
A.neg v
d2v
a
y1 <- v -> CodeGenFunction r (Element v)
forall v r. Read v => v -> CodeGenFunction r (Element v)
Serial.last v
y1v
v
xk1 <-
Value Word32
-> (a -> CodeGenFunction r a) -> v -> CodeGenFunction r v
forall v a r.
(Write v, Element v ~ a) =>
Value Word32
-> (a -> CodeGenFunction r a) -> v -> CodeGenFunction r v
Serial.modify (Word32 -> Value Word32
forall a. IsConst a => a -> Value a
valueOf Word32
0)
(\a
u0 -> a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add a
u0 (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul (Parameter a -> a
forall a. Parameter a -> a
Filt2.d1 Parameter a
p) a
y1) (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add v
x0 (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
d2v (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
Int -> v -> CodeGenFunction r v
forall v r.
(Write v, Additive (Element v)) =>
Int -> v -> CodeGenFunction r v
Serial.shiftDownMultiZero (Int
size Int -> Int -> Int
forall a. C a => a -> a -> a
- Int
2) v
y1v
v
xk2 <-
((v, (v, v)) -> v)
-> CodeGenFunction r (v, (v, v)) -> CodeGenFunction r v
forall a b. (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (v, (v, v)) -> v
forall a b. (a, b) -> a
fst (CodeGenFunction r (v, (v, v)) -> CodeGenFunction r v)
-> CodeGenFunction r (v, (v, v)) -> CodeGenFunction r v
forall a b. (a -> b) -> a -> b
$
((v, (v, v)) -> Int -> CodeGenFunction r (v, (v, v)))
-> (v, (v, v)) -> [Int] -> CodeGenFunction r (v, (v, v))
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM
(\(v
y,(v
a,v
b)) Int
d ->
(v -> (v, v) -> (v, (v, v)))
-> CodeGenFunction r v
-> CodeGenFunction r (v, v)
-> CodeGenFunction r (v, (v, v))
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,)
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add v
y (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(v -> v -> CodeGenFunction r v)
-> CodeGenFunction r v
-> CodeGenFunction r v
-> CodeGenFunction r v
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
M.liftJoin2 v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add
(Int -> v -> CodeGenFunction r v
forall v r.
(Write v, Additive (Element v)) =>
Int -> v -> CodeGenFunction r v
Serial.shiftUpMultiZero Int
d (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
y v
a)
(Int -> v -> CodeGenFunction r v
forall v r.
(Write v, Additive (Element v)) =>
Int -> v -> CodeGenFunction r v
Serial.shiftUpMultiZero (Int
2Int -> Int -> Int
forall a. C a => a -> a -> a
*Int
d) (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
y v
b)) (CodeGenFunction r (v, v) -> CodeGenFunction r (v, (v, v)))
-> CodeGenFunction r (v, v) -> CodeGenFunction r (v, (v, v))
forall a b. (a -> b) -> a -> b
$
(v -> v -> (v, v))
-> CodeGenFunction r v
-> CodeGenFunction r v
-> CodeGenFunction r (v, v)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,)
((v -> v -> CodeGenFunction r v)
-> CodeGenFunction r v
-> CodeGenFunction r v
-> CodeGenFunction r v
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
M.liftJoin2 v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.sub
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
a v
a)
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
b (Integer -> v
forall a. IntegerConstant a => Integer -> a
A.fromInteger' Integer
2)))
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
b v
b))
(v
xk1,(v
d1v,v
d2vn))
((Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
size) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Int -> Int) -> Int -> [Int]
forall a. (a -> a) -> a -> [a]
iterate (Int
2Int -> Int -> Int
forall a. C a => a -> a -> a
*) Int
1)
(v, v) -> CodeGenFunction r (v, v)
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (v
xk2, v
xk2))
(v -> CodeGenFunction r v
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return v
forall a. Additive a => a
A.zero)
_causalRecursivePackedAlt :: forall v a.
(Write v, Element v ~ a, C a, IntegerConstant v, IntegerConstant a,
PseudoRing v, PseudoRing a) =>
T (Parameter a, v) v
_causalRecursivePackedAlt =
(forall r.
(Parameter a, v) -> (a, a) -> CodeGenFunction r (v, (a, a)))
-> (forall r. CodeGenFunction r (a, a)) -> T (Parameter a, v) v
forall state a b.
C state =>
(forall r. a -> state -> CodeGenFunction r (b, state))
-> (forall r. CodeGenFunction r state) -> T a b
Causal.mapAccum
(\(Parameter a
p, v
x0) (a
x1,a
x2) -> do
let size :: Int
size = v -> Int
forall v i. (Sized v, Integral i) => v -> i
Serial.size v
x0
v
xk1 <-
Value Word32
-> (a -> CodeGenFunction r a) -> v -> CodeGenFunction r v
forall v a r.
(Write v, Element v ~ a) =>
Value Word32
-> (a -> CodeGenFunction r a) -> v -> CodeGenFunction r v
Serial.modify (Word32 -> Value Word32
forall a. IsConst a => a -> Value a
valueOf Word32
0)
(\a
u0 ->
a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add a
u0 (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(a -> a -> CodeGenFunction r a)
-> CodeGenFunction r a
-> CodeGenFunction r a
-> CodeGenFunction r a
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
M.liftJoin2 a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add (a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul (Parameter a -> a
forall a. Parameter a -> a
Filt2.d2 Parameter a
p) a
x2) (a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul (Parameter a -> a
forall a. Parameter a -> a
Filt2.d1 Parameter a
p) a
x1)) (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
Value Word32
-> (a -> CodeGenFunction r a) -> v -> CodeGenFunction r v
forall v a r.
(Write v, Element v ~ a) =>
Value Word32
-> (a -> CodeGenFunction r a) -> v -> CodeGenFunction r v
Serial.modify (Word32 -> Value Word32
forall a. IsConst a => a -> Value a
valueOf Word32
1)
(\a
u1 -> a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add a
u1 (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul (Parameter a -> a
forall a. Parameter a -> a
Filt2.d2 Parameter a
p) a
x1)
v
x0
v
d1v <- Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (Parameter a -> a
forall a. Parameter a -> a
Filt2.d1 Parameter a
p)
v
d2v <- a -> CodeGenFunction r v
Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
Serial.upsample (a -> CodeGenFunction r v)
-> CodeGenFunction r a -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< a -> CodeGenFunction r a
forall r. a -> CodeGenFunction r a
forall a r. Additive a => a -> CodeGenFunction r a
A.neg (Parameter a -> a
forall a. Parameter a -> a
Filt2.d2 Parameter a
p)
v
xk2 <-
((v, (v, v)) -> v)
-> CodeGenFunction r (v, (v, v)) -> CodeGenFunction r v
forall a b. (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (v, (v, v)) -> v
forall a b. (a, b) -> a
fst (CodeGenFunction r (v, (v, v)) -> CodeGenFunction r v)
-> CodeGenFunction r (v, (v, v)) -> CodeGenFunction r v
forall a b. (a -> b) -> a -> b
$
((v, (v, v)) -> Int -> CodeGenFunction r (v, (v, v)))
-> (v, (v, v)) -> [Int] -> CodeGenFunction r (v, (v, v))
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM
(\(v
y,(v
a,v
b)) Int
d ->
(v -> (v, v) -> (v, (v, v)))
-> CodeGenFunction r v
-> CodeGenFunction r (v, v)
-> CodeGenFunction r (v, (v, v))
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,)
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add v
y (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(v -> v -> CodeGenFunction r v)
-> CodeGenFunction r v
-> CodeGenFunction r v
-> CodeGenFunction r v
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
M.liftJoin2 v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.add
(Int -> v -> CodeGenFunction r v
forall v r.
(Write v, Additive (Element v)) =>
Int -> v -> CodeGenFunction r v
Serial.shiftUpMultiZero Int
d (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
y v
a)
(Int -> v -> CodeGenFunction r v
forall v r.
(Write v, Additive (Element v)) =>
Int -> v -> CodeGenFunction r v
Serial.shiftUpMultiZero (Int
2Int -> Int -> Int
forall a. C a => a -> a -> a
*Int
d) (v -> CodeGenFunction r v)
-> CodeGenFunction r v -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
y v
b)) (CodeGenFunction r (v, v) -> CodeGenFunction r (v, (v, v)))
-> CodeGenFunction r (v, v) -> CodeGenFunction r (v, (v, v))
forall a b. (a -> b) -> a -> b
$
(v -> v -> (v, v))
-> CodeGenFunction r v
-> CodeGenFunction r v
-> CodeGenFunction r (v, v)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,)
((v -> v -> CodeGenFunction r v)
-> CodeGenFunction r v
-> CodeGenFunction r v
-> CodeGenFunction r v
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
M.liftJoin2 v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. Additive a => a -> a -> CodeGenFunction r a
A.sub
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
a v
a)
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
b (Integer -> v
forall a. IntegerConstant a => Integer -> a
A.fromInteger' Integer
2)))
(v -> v -> CodeGenFunction r v
forall r. v -> v -> CodeGenFunction r v
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul v
b v
b))
(v
xk1,(v
d1v,v
d2v))
((Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
size) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Int -> Int) -> Int -> [Int]
forall a. (a -> a) -> a -> [a]
iterate (Int
2Int -> Int -> Int
forall a. C a => a -> a -> a
*) Int
1)
a
y0 <- Value Word32 -> v -> CodeGenFunction r (Element v)
forall r. Value Word32 -> v -> CodeGenFunction r (Element v)
forall v r.
Read v =>
Value Word32 -> v -> CodeGenFunction r (Element v)
Serial.extract (Word32 -> Value Word32
forall a. IsConst a => a -> Value a
valueOf (Word32 -> Value Word32) -> Word32 -> Value Word32
forall a b. (a -> b) -> a -> b
$ Int -> Word32
forall a b. (C a, C b) => a -> b
fromIntegral Int
size Word32 -> Word32 -> Word32
forall a. C a => a -> a -> a
- Word32
1) v
xk2
a
y1 <- Value Word32 -> v -> CodeGenFunction r (Element v)
forall r. Value Word32 -> v -> CodeGenFunction r (Element v)
forall v r.
Read v =>
Value Word32 -> v -> CodeGenFunction r (Element v)
Serial.extract (Word32 -> Value Word32
forall a. IsConst a => a -> Value a
valueOf (Word32 -> Value Word32) -> Word32 -> Value Word32
forall a b. (a -> b) -> a -> b
$ Int -> Word32
forall a b. (C a, C b) => a -> b
fromIntegral Int
size Word32 -> Word32 -> Word32
forall a. C a => a -> a -> a
- Word32
2) v
xk2
(v, (a, a)) -> CodeGenFunction r (v, (a, a))
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (v
xk2, (a
y0,a
y1)))
((a, a) -> CodeGenFunction r (a, a)
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
forall a. Additive a => a
A.zero, a
forall a. Additive a => a
A.zero))