Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
import "primitives/math/float.fil";
/// Multiplication of complex numbers
comp ComplexMult[W, E, ?M=W-E-1]<'G: 1>(
left[2]: ['G, 'G+1] W, // a + bi
right[2]: ['G, 'G+1] W // c + di
) -> (
out[2]: ['G, 'G+1] W
) where
W == E + M + 1,
E > 1,
M > 1
{
// fully combinational
ac := new FMult[W, E, M]<'G>(left{0}, right{0}); // ac
bd := new FMult[W, E, M]<'G>(left{1}, right{1}); // bd
re := new FSub[W, E, M]<'G>(ac.out, bd.out); // ac - bd
ad := new FMult[W, E, M]<'G>(left{0}, right{1}); // ad
bc := new FMult[W, E, M]<'G>(left{1}, right{0}); // bc
im := new FAdd[W, E, M]<'G>(ad.out, bc.out); // ad + bc
out{0} = re.out;
out{1} = im.out;
}
/// Addition of complex numbers
comp ComplexAdd[W, E, ?M=W-E-1]<'G: 1>(
left[2]: ['G, 'G+1] W, // a + bi
right[2]: ['G, 'G+1] W // c + di
) -> (
out[2]: ['G, 'G+1] W
) where
W == E + M + 1,
E > 1,
M > 1
{
// fully combinational
re := new FAdd[W, E, M]<'G>(left{0}, right{0}); // a + c
im := new FAdd[W, E, M]<'G>(left{1}, right{1}); // b + d
out{0} = re.out;
out{1} = im.out;
}
// negation of a complex number
comp ComplexNeg[W, E, ?M=W-E-1]<'G: 1>(
in[2]: ['G, 'G+1] W // a + bi
) -> (
out[2]: ['G, 'G+1] W
) where
W == E + M + 1,
E > 1,
M > 1
{
neg1 := new FNeg[W, E, M]<'G>(in{0}); // -a
neg2 := new FNeg[W, E, M]<'G>(in{1}); // -b
out{0} = neg1.out;
out{1} = neg2.out;
}
// subtraction of complex numbers
comp ComplexSub[W, E, ?M=W-E-1]<'G: 1>(
left[2]: ['G, 'G+1] W,
right[2]: ['G, 'G+1] W
) -> (
out[2]: ['G, 'G+1] W
) where
W == E + M + 1,
E > 1,
M > 1
{
neg := new ComplexNeg[W, E, M]<'G>(right{0..2});
add := new ComplexAdd[W, E, M]<'G>(left{0..2}, neg.out{0..2});
out{0..2} = add.out{0..2};
}7aa19ccf2This file is pinned to the selected release. Download the original to open it in your design tool.