remove pows and shifts for optimization

This commit is contained in:
Jordi Baylina
2020-01-23 07:23:17 +07:00
parent 4f11565ca4
commit 2f28fc7002
3 changed files with 273 additions and 6 deletions

View File

@@ -72,19 +72,26 @@ template BinSum(n, ops) {
var k;
var j;
var e2;
e2 = 1;
for (k=0; k<n; k++) {
for (j=0; j<ops; j++) {
lin += in[j][k] * 2**k;
lin += in[j][k] * e2;
}
e2 = e2 + e2;
}
e2 = 1;
for (k=0; k<nout; k++) {
out[k] <-- (lin >> k) & 1;
// Ensure out is binary
out[k] * (out[k] - 1) === 0;
lout += out[k] * 2**k;
lout += out[k] * e2;
e2 = e2+e2;
}
// Ensure the sum;

View File

@@ -26,10 +26,12 @@ template Num2Bits(n) {
signal output out[n];
var lc1=0;
var e2=1;
for (var i = 0; i<n; i++) {
out[i] <-- (in >> i) & 1;
out[i] * (out[i] -1 ) === 0;
lc1 += out[i] * 2**i;
lc1 += out[i] * e2;
e2 = e2+e2;
}
lc1 === in;
@@ -54,8 +56,10 @@ template Bits2Num(n) {
signal output out;
var lc1=0;
var e2 = 1;
for (var i = 0; i<n; i++) {
lc1 += in[i] * 2**i;
lc1 += in[i] * e2;
e2 = e2 + e2;
}
lc1 ==> out;