Commit b9c41a90 authored by Rob Cameron's avatar Rob Cameron
Browse files

Bixnum masked create method

parent 951c5f6a
......@@ -26,6 +26,8 @@ class BixNumCompiler {
public:
BixNumCompiler(PabloBuilder & pb) : mPB(pb) {}
BixNum Create(unsigned val);
// Create a bixnum of the given value at mask positions, 0 elsewhere.
BixNum Create(PabloAST * mask, unsigned val);
PabloAST * EQ(BixNum value, unsigned test, const llvm::StringRef &Name = "");
PabloAST * EQ(BixNum value, BixNum test, const llvm::StringRef &Name = "");
PabloAST * NEQ(BixNum value, unsigned test, const llvm::StringRef &Name = "");
......
......@@ -186,7 +186,8 @@ BixNum BixNumCompiler::HighBits(BixNum value, unsigned highBitCount) {
}
BixNum BixNumCompiler::Create(unsigned value) {
unsigned value_bits = floor_log2(value)+1;
unsigned value_bits = 1;
if (value > 0) value_bits = floor_log2(value)+1;
BixNum v(value_bits);
for (unsigned i = 0; i < value_bits; i++) {
if ((value & (1<<i)) == 0) {
......@@ -198,6 +199,20 @@ BixNum BixNumCompiler::Create(unsigned value) {
return v;
}
BixNum BixNumCompiler::Create(PabloAST * mask, unsigned value) {
unsigned value_bits = 1;
if (value > 0) value_bits = floor_log2(value)+1;
BixNum v(value_bits);
for (unsigned i = 0; i < value_bits; i++) {
if ((value & (1<<i)) == 0) {
v[i] = mPB.createZeroes();
} else {
v[i] = mask;
}
}
return v;
}
BixNum BixNumCompiler::AddModular(BixNum augend, unsigned addend) {
addend = addend & ((1 << augend.size()) - 1);
if (addend == 0) return augend;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment