aboutsummaryrefslogtreecommitdiffstats
path: root/backends/cxxrtl/cxxrtl.h
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2020-12-21 02:15:55 +0000
committerwhitequark <whitequark@whitequark.org>2020-12-21 02:20:34 +0000
commitb9721bedf01ca1f536bbf13ba761333c6867bd29 (patch)
tree5a262c642e0f07230fc81cc7a1a39344603a77a3 /backends/cxxrtl/cxxrtl.h
parent40ca9d038b1e657b9b9ac17e7e5a2969c9922e00 (diff)
downloadyosys-b9721bedf01ca1f536bbf13ba761333c6867bd29.tar.gz
yosys-b9721bedf01ca1f536bbf13ba761333c6867bd29.tar.bz2
yosys-b9721bedf01ca1f536bbf13ba761333c6867bd29.zip
cxxrtl: speed up bit repeats (sign extends, etc).
On Minerva SoC SRAM, depending on the compiler, this change improves overall time by 4-7%.
Diffstat (limited to 'backends/cxxrtl/cxxrtl.h')
-rw-r--r--backends/cxxrtl/cxxrtl.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h
index 3c315c7df..0a6bcb849 100644
--- a/backends/cxxrtl/cxxrtl.h
+++ b/backends/cxxrtl/cxxrtl.h
@@ -317,6 +317,14 @@ struct value : public expr_base<value<Bits>> {
return sext_cast<NewBits>()(*this);
}
+ // Bit replication is far more efficient than the equivalent concatenation.
+ template<size_t Count>
+ CXXRTL_ALWAYS_INLINE
+ value<Bits * Count> repeat() const {
+ static_assert(Bits == 1, "repeat() is implemented only for 1-bit values");
+ return *this ? value<Bits * Count>().bit_not() : value<Bits * Count>();
+ }
+
// Operations with run-time parameters (offsets, amounts, etc).
//
// These operations are used for computations.