From b9721bedf01ca1f536bbf13ba761333c6867bd29 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 21 Dec 2020 02:15:55 +0000 Subject: cxxrtl: speed up bit repeats (sign extends, etc). On Minerva SoC SRAM, depending on the compiler, this change improves overall time by 4-7%. --- backends/cxxrtl/cxxrtl.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'backends/cxxrtl/cxxrtl.h') 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> { return sext_cast()(*this); } + // Bit replication is far more efficient than the equivalent concatenation. + template + CXXRTL_ALWAYS_INLINE + value repeat() const { + static_assert(Bits == 1, "repeat() is implemented only for 1-bit values"); + return *this ? value().bit_not() : value(); + } + // Operations with run-time parameters (offsets, amounts, etc). // // These operations are used for computations. -- cgit v1.2.3