Commit 04f87a29 authored by Julius Nehring-Wirxel's avatar Julius Nehring-Wirxel
Browse files

Simplified names

Removed conditional inversion when mul and imul are identical, which happens when the length of all words are equal.
parent f61a7c23
......@@ -60,9 +60,8 @@ std::string generate_mul(int w_r, int w_a, int w_b)
std::string result;
result += "template<>\n";
// result += "inline fixed_uint<" + std::to_string(w_r) + "> mul(" + a_type + (w_a > 1 ? " const&" : "") + " lhs, " + b_type + (w_b > 1 ? " const&" : "") + " rhs)\n{\n";
result += "inline fixed_uint<" + std::to_string(w_r) + "> mul(" + a_type + " const&" + " lhs, " + b_type + " const&" + " rhs)\n{\n";
result += " fixed_uint<" + std::to_string(w_r) + "> res;\n";
result += "inline " + out_type + " mul(" + a_type + " lhs, " + b_type + " rhs)\n{\n";
result += " " + out_type + " res;\n";
for (auto i = 0u; i < vars_l.size(); ++i)
result += " u64 " + l_of(vars_l[i]) + " = 0;\n";
......@@ -124,15 +123,15 @@ std::string generate_imul(int w_r, int w_a, int w_b)
auto const h_of = [](std::pair<int, int> const& pair) { return "h" + std::to_string(pair.first) + std::to_string(pair.second); };
auto const lhs_of = [&](int v) {
if (w_a == 1)
return std::string("l");
return std::string("lhs");
else
return "l.d[" + std::to_string(v) + "]";
return "lhs.d[" + std::to_string(v) + "]";
};
auto const rhs_of = [&](int v) {
if (w_b == 1)
return std::string("r");
return std::string("rhs");
else
return "r.d[" + std::to_string(v) + "]";
return "rhs.d[" + std::to_string(v) + "]";
};
for (auto i = 0; i < w_a; ++i)
......@@ -174,18 +173,19 @@ std::string generate_imul(int w_r, int w_a, int w_b)
};
result += "template<>\n";
result += "inline fixed_int<" + std::to_string(w_r) + "> imul(" + a_type + " const&" + " lhs, " + b_type + " const&" + " rhs)\n{\n";
result += "inline " + out_type + " imul(" + a_type + " lhs, " + b_type + " rhs)\n{\n";
// result += "fixed_int<" + std::to_string(w_r) + "> imul(" + a_type + (w_a > 1 ? " const&" : "") + " lhs, " + b_type + (w_b > 1 ? " const&" : "") + " rhs)\n{\n";
result += " fixed_int<" + std::to_string(w_r) + "> res;\n";
result += " " + a_type + " l = lhs;\n";
result += " " + b_type + " r = rhs;\n";
// conditional inversion
if (w_a != w_b || w_a != w_r)
{
result += " u64 s_l = u64(i64(" + lhs_of(w_a - 1) + ") >> 63); // 0 iff > 0, -1 otherwise\n";
result += " u64 s_r = u64(i64(" + rhs_of(w_b - 1) + ") >> 63); // 0 iff > 0, -1 otherwise\n";
result += " u64 s_res = s_l ^ s_r;\n";
// conditional inversion
conditional_invert(lhs_of, "s_l", w_a);
conditional_invert(rhs_of, "s_r", w_b);
}
for (auto i = 0u; i < vars_l.size(); ++i)
result += " u64 " + l_of(vars_l[i]) + " = 0;\n";
......@@ -224,6 +224,7 @@ std::string generate_imul(int w_r, int w_a, int w_b)
}
result += ";\n";
if (w_a != w_b || w_a != w_r)
conditional_invert([](int i) { return "res.d[" + std::to_string(i) + "]"; }, "s_res", w_r);
result += " return res;\n";
......
Supports Markdown
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