mirror of
https://github.com/YosysHQ/yosys
synced 2025-08-11 21:50:54 +00:00
simplify: std::gcd
This commit is contained in:
parent
950339b1b0
commit
581b9684a2
1 changed files with 2 additions and 16 deletions
|
@ -36,25 +36,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
// For std::gcd in C++17
|
#include <numeric>
|
||||||
// #include <numeric>
|
|
||||||
|
|
||||||
YOSYS_NAMESPACE_BEGIN
|
YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
using namespace AST;
|
using namespace AST;
|
||||||
using namespace AST_INTERNAL;
|
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)
|
void AstNode::set_in_lvalue_flag(bool flag, bool no_descend)
|
||||||
{
|
{
|
||||||
if (flag != in_lvalue_from_above) {
|
if (flag != in_lvalue_from_above) {
|
||||||
|
@ -3001,9 +2989,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 is at least 64 bits in C++11
|
||||||
long long shift_mod = 1ll << (max_width - case_sign_hint);
|
long long shift_mod = 1ll << (max_width - case_sign_hint);
|
||||||
// std::gcd requires C++17
|
bitno_div = std::gcd((long long)stride, shift_mod);
|
||||||
// bitno_div = std::gcd(stride, shift_mod);
|
|
||||||
bitno_div = gcd((long long)stride, shift_mod);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue