Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precalculate mask in simulation of ALTRO chip #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/altro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ int Altro::multiply36(int P, int N)
long long temp = 0;
long long AX = 0;
temp = (long long)P * (long long)N;
AX = (( mask(temp, 35, 18) + ((long long)(-P) << 18) ) + mask(temp, 17, 0));
AX = (( mask_35_18(temp) + ((long long)(-P) << 18) ) + mask_17_0(temp));

if ( maskandshift(N, 17, 17) == 1) {
retval = ((maskandshift(AX, 35, 35) << 17) + maskandshift(AX, 32, 16));
if ( maskandshift_17_17(N) == 1) {
retval = (maskandshift_35_35(AX) << 17) + maskandshift_32_16(AX);
}
else {
retval = maskandshift(temp, 32, 16);
retval = maskandshift_32_16(temp);
}

return retval;
Expand Down Expand Up @@ -450,19 +450,19 @@ void Altro::TailCancellationFilter_FixedPoint(int K1, int K2, int K3, int L1, in
din = channelShort[i];

din = (din << 2);
c1n = mask( (mask(din, 17, 0) + multiply36(K1, mask(c1o, 17, 0)) ), 17, 0);
d1 = mask( (mask(c1n, 17, 0) - multiply36(L1, mask(c1o, 17, 0)) ), 17, 0);
c1n = mask_17_0( (mask_17_0(din) + multiply36(K1, mask_17_0(c1o)) ));
d1 = mask_17_0( (mask_17_0(c1n) - multiply36(L1, mask_17_0(c1o)) ));
//d1 = mask( (mask(c1n,17,0) + mask(~multiply36(L1,mask(c1o,17,0))+1,17,0) ) ,17,0);

c2n = mask( (mask(d1, 17, 0) + multiply36(K2, mask(c2o, 17, 0)) ), 17, 0);
d2 = mask( (mask(c2n, 17, 0) - multiply36(L2, mask(c2o, 17, 0)) ), 17, 0);
c2n = mask_17_0( (mask_17_0(d1) + multiply36(K2, mask_17_0(c2o)) ));
d2 = mask_17_0( (mask_17_0(c2n) - multiply36(L2, mask_17_0(c2o)) ));
//d2 = mask( (mask(c2n,17,0) + mask(~multiply36(L2,mask(c2o,17,0))+1,17,0) ) ,17,0);

c3n = mask( (mask(d2, 17, 0) + multiply36(K3, mask(c3o, 17, 0)) ), 17, 0);
dout = mask( (mask(c3n, 17, 0) - multiply36(L3, mask(c3o, 17, 0)) ), 17, 0);
c3n = mask_17_0( (mask_17_0(d2) + multiply36(K3, mask_17_0(c3o)) ));
dout = mask_17_0( (mask_17_0(c3n) - multiply36(L3, mask_17_0(c3o)) ));
//dout = mask( (mask(c3n,17,0) + mask(~multiply36(L3,mask(c3o,17,0))+1,17,0) ) ,17,0);

if ( (maskandshift(dout, 2, 2) == 1) || (maskandshift(dout, 1, 1) == 1)) {
if ( maskandshift_2_2(dout) == 1 || maskandshift_1_1(dout) == 1) {
bit = 1;
}
else {
Expand All @@ -471,12 +471,12 @@ void Altro::TailCancellationFilter_FixedPoint(int K1, int K2, int K3, int L1, in

dout = ((dout >> 3) << 1) + bit;

if (maskandshift(dout, 15, 15) == 1) {
if (maskandshift_15_15(dout) == 1) {
//is needed to get the correct coding when getting negative results
dout = -mask((-mask(dout, 9, 0)), 9, 0);
dout = -mask_9_0(-mask_9_0(dout));
}
else {
dout = mask(dout, 9, 0);
dout = mask_9_0(dout);
}

channelShort[i] = (short) dout;
Expand Down
31 changes: 31 additions & 0 deletions src/altro.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,36 @@ class Altro
short GetKeepChannel(int i);
int multiply36(int P, int N);
long long mask(long long in, int left, int right);

/// Precalculated masks based on the algorithm implemented in
/// `Altro::mask(long long, int left, int right)` and invoked with fixed
/// values for the `left` and `right` arguments.
///@{
/// left=9, right=0
long long mask_9_0(long long in) { return in & 0b000000000000000000000000001111111111; }
/// left=17, right=0
long long mask_17_0(long long in) { return in & 0b000000000000000000111111111111111111; }
/// left=35, right=18
long long mask_35_18(long long in) { return in & 0b111111111111111111000000000000000000; }
///@}

long long maskandshift(long long in, int left, int right);

/// Precalculated masks based on the algorithm implemented in
/// `Altro::maskandshift(long long, int left, int right)` and invoked with
/// fixed values for the `left` and `right` arguments.
///@{
/// left=1, right=1
long long maskandshift_1_1(long long in) { return (in >> 1) & 0b000000000000000001; }
/// left=2, right=2
long long maskandshift_2_2(long long in) { return (in >> 2) & 0b000000000000000001; }
/// left=15, right=15
long long maskandshift_15_15(long long in) { return (in >> 15) & 0b000000000000000001; }
/// left=17, right=17
long long maskandshift_17_17(long long in) { return (in >> 17) & 0b000000000000000001; }
/// left=35, right=35
long long maskandshift_35_35(long long in) { return (in >> 35) & 0b000000000000000001; }
/// left=32, right=16
long long maskandshift_32_16(long long in) { return (in >> 16) & 0b011111111111111111; }
///@}
};