mirror of
https://github.com/YosysHQ/yosys
synced 2025-08-12 14:11:00 +00:00
simplify: std::gcd
This commit is contained in:
parent
c634a4c926
commit
4f77113960
1 changed files with 2 additions and 16 deletions
|
@ -36,25 +36,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <optional>
|
||||
// For std::gcd in C++17
|
||||
// #include <numeric>
|
||||
#include <numeric>
|
||||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
using namespace AST;
|
||||
using namespace AST_INTERNAL;
|
||||
|
||||
// gcd computed by Euclidian division.
|
||||
// To be replaced by C++17 std::gcd
|
||||
template<class I> I gcd(I a, I b) {
|
||||
while (b != 0) {
|
||||
I tmp = b;
|
||||
b = a%b;
|
||||
a = tmp;
|
||||
}
|
||||
return std::abs(a);
|
||||
}
|
||||
|
||||
void AstNode::set_in_lvalue_flag(bool flag, bool no_descend)
|
||||
{
|
||||
if (flag != in_lvalue_from_above) {
|
||||
|
@ -2934,9 +2922,7 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
|
|||
//
|
||||
// long long is at least 64 bits in C++11
|
||||
long long shift_mod = 1ll << (max_width - case_sign_hint);
|
||||
// std::gcd requires C++17
|
||||
// bitno_div = std::gcd(stride, shift_mod);
|
||||
bitno_div = gcd((long long)stride, shift_mod);
|
||||
bitno_div = std::gcd((long long)stride, shift_mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue