From 68a9aa7c29b72543552af9795310cc598a7975d6 Mon Sep 17 00:00:00 2001 From: Philippe Sauter Date: Fri, 26 Jan 2024 11:44:44 +0100 Subject: [PATCH 1/3] peepopt: handle offset too large in `shiftadd` If the offset is larger than the signal itself, meaning the signal is completely shifted out, it tried to extract a negative amount of bits from the old signal. This RTL pattern is suspicious since it is a complicated way of arriving at a constant value, so we warn the user. --- passes/pmgen/peepopt_shiftadd.pmg | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/passes/pmgen/peepopt_shiftadd.pmg b/passes/pmgen/peepopt_shiftadd.pmg index f9c930eae3d..6f2dd89af55 100644 --- a/passes/pmgen/peepopt_shiftadd.pmg +++ b/passes/pmgen/peepopt_shiftadd.pmg @@ -103,8 +103,18 @@ code new_a.append(old_a); } else { // data >> (...+c) transformed to data[MAX:c] >> (...) - new_a.append(old_a.extract_end(offset)); - + if(offset < GetSize(old_a)) // some signal bits left? + new_a.append(old_a.extract_end(offset)); + else { + if(shift->type.in($shiftx)) + log_warning("at %s: result of indexed part-selection is always constant (selecting from '%s' with index '%s + %d')\n", \ + shift->get_src_attribute().c_str(), log_signal(old_a), log_signal(var_signal), offset); + else + log_warning("at %s: result of shift operation is always constant (shifting '%s' by '%s + %d'-bits)\n", \ + shift->get_src_attribute().c_str(), log_signal(old_a), log_signal(var_signal), offset); + } + + // is it fine to leave new_a empty? (size 0) } SigSpec new_b = {var_signal, SigSpec(State::S0, log2scale)}; From 7f8b6dd9825e90adb6d858c57e7c9a70fbce57ba Mon Sep 17 00:00:00 2001 From: Philippe Sauter Date: Tue, 30 Jan 2024 09:51:21 +0100 Subject: [PATCH 2/3] peepopt: delete unnecessary comment in shiftadd --- passes/pmgen/peepopt_shiftadd.pmg | 2 -- 1 file changed, 2 deletions(-) diff --git a/passes/pmgen/peepopt_shiftadd.pmg b/passes/pmgen/peepopt_shiftadd.pmg index 6f2dd89af55..d17fcbb0d22 100644 --- a/passes/pmgen/peepopt_shiftadd.pmg +++ b/passes/pmgen/peepopt_shiftadd.pmg @@ -113,8 +113,6 @@ code log_warning("at %s: result of shift operation is always constant (shifting '%s' by '%s + %d'-bits)\n", \ shift->get_src_attribute().c_str(), log_signal(old_a), log_signal(var_signal), offset); } - - // is it fine to leave new_a empty? (size 0) } SigSpec new_b = {var_signal, SigSpec(State::S0, log2scale)}; From cbdf9b2f9c2953255bee05aa1a8ddc1cf80a4b13 Mon Sep 17 00:00:00 2001 From: Philippe Sauter Date: Wed, 31 Jan 2024 13:06:35 +0100 Subject: [PATCH 3/3] peepopt: handle empty src-attribute in shiftadd --- passes/pmgen/peepopt_shiftadd.pmg | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/passes/pmgen/peepopt_shiftadd.pmg b/passes/pmgen/peepopt_shiftadd.pmg index d17fcbb0d22..e690ff65113 100644 --- a/passes/pmgen/peepopt_shiftadd.pmg +++ b/passes/pmgen/peepopt_shiftadd.pmg @@ -103,15 +103,19 @@ code new_a.append(old_a); } else { // data >> (...+c) transformed to data[MAX:c] >> (...) - if(offset < GetSize(old_a)) // some signal bits left? + if(offset < GetSize(old_a)) { // some signal bits left? new_a.append(old_a.extract_end(offset)); - else { + } else { + // warn user in case data is empty (no bits left) + std::string location = shift->get_src_attribute(); + if (location.empty()) + location = shift->name.str(); if(shift->type.in($shiftx)) log_warning("at %s: result of indexed part-selection is always constant (selecting from '%s' with index '%s + %d')\n", \ - shift->get_src_attribute().c_str(), log_signal(old_a), log_signal(var_signal), offset); + location.c_str(), log_signal(old_a), log_signal(var_signal), offset); else log_warning("at %s: result of shift operation is always constant (shifting '%s' by '%s + %d'-bits)\n", \ - shift->get_src_attribute().c_str(), log_signal(old_a), log_signal(var_signal), offset); + location.c_str(), log_signal(old_a), log_signal(var_signal), offset); } }