Skip to content

Commit bc309ff

Browse files
committed
WIP: Comba multiplication scheme
1 parent fd0aeae commit bc309ff

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/solvers/flattening/bv_utils.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,48 @@ bvt bv_utilst::dadda_tree(const std::vector<bvt> &pps)
806806
return add(a, b);
807807
}
808808

809+
bvt bv_utilst::comba_column_wise(const std::vector<bvt> &pps)
810+
{
811+
PRECONDITION(!pps.empty());
812+
813+
std::vector<bvt> columns(pps.front().size());
814+
for(const auto &pp : pps)
815+
{
816+
PRECONDITION(pp.size() == pps.front().size());
817+
for(std::size_t i = 0; i < pp.size(); ++i)
818+
{
819+
if(!pp[i].is_false())
820+
columns[i].push_back(pp[i]);
821+
}
822+
}
823+
824+
bvt result;
825+
result.reserve(columns.size());
826+
827+
for(std::size_t i = 0; i < columns.size(); ++i)
828+
{
829+
const bvt &column = columns[i];
830+
831+
if(column.empty())
832+
result.push_back(const_literal(false));
833+
else
834+
{
835+
bvt column_sum = popcount(column);
836+
CHECK_RETURN(!column_sum.empty());
837+
result.push_back(column_sum.front());
838+
for(std::size_t j = 1; j < column_sum.size(); ++j)
839+
{
840+
if(i + j >= columns.size())
841+
break;
842+
if(!column_sum[j].is_false())
843+
columns[i + j].push_back(column_sum[j]);
844+
}
845+
}
846+
}
847+
848+
return result;
849+
}
850+
809851
// Wallace tree multiplier. This is disabled, as runtimes have
810852
// been observed to go up by 5%-10%, and on some models even by 20%.
811853
// #define WALLACE_TREE
@@ -958,10 +1000,11 @@ bvt bv_utilst::dadda_tree(const std::vector<bvt> &pps)
9581000
// #define RADIX_MULTIPLIER 8
9591001
// #define USE_KARATSUBA
9601002
// #define USE_TOOM_COOK
961-
#define USE_SCHOENHAGE_STRASSEN
1003+
// #define USE_SCHOENHAGE_STRASSEN
9621004
#ifdef RADIX_MULTIPLIER
9631005
# define DADDA_TREE
9641006
#endif
1007+
#define COMBA
9651008

9661009
#ifdef RADIX_MULTIPLIER
9671010
static bvt unsigned_multiply_by_3(propt &prop, const bvt &op)
@@ -1850,6 +1893,8 @@ bvt bv_utilst::unsigned_multiplier(const bvt &_op0, const bvt &_op1)
18501893
return wallace_tree(pps);
18511894
#elif defined(DADDA_TREE)
18521895
return dadda_tree(pps);
1896+
#elif defined(COMBA)
1897+
return comba_column_wise(pps);
18531898
#else
18541899
bvt product = pps.front();
18551900

@@ -2124,6 +2169,8 @@ bvt bv_utilst::unsigned_toom_cook_multiplier(const bvt &_op0, const bvt &_op1)
21242169
return wallace_tree(c_ops);
21252170
#elif defined(DADDA_TREE)
21262171
return dadda_tree(c_ops);
2172+
#elif defined(COMBA)
2173+
return comba_column_wise(c_ops);
21272174
#else
21282175
bvt product = c_ops.front();
21292176

src/solvers/flattening/bv_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class bv_utilst
254254

255255
bvt wallace_tree(const std::vector<bvt> &pps);
256256
bvt dadda_tree(const std::vector<bvt> &pps);
257+
bvt comba_column_wise(const std::vector<bvt> &pps);
257258
};
258259

259260
#endif // CPROVER_SOLVERS_FLATTENING_BV_UTILS_H

0 commit comments

Comments
 (0)