From ee58342a7a37b0d1c483dbcb2f7ffd30e8b1ea61 Mon Sep 17 00:00:00 2001 From: Johannes de Fine Licht Date: Tue, 21 Sep 2021 18:27:30 +0200 Subject: [PATCH] Fix ConstLog2 --- include/hlslib/xilinx/Flatten.h | 7 ++++--- include/hlslib/xilinx/ShiftRegister.h | 2 +- include/hlslib/xilinx/Utility.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/hlslib/xilinx/Flatten.h b/include/hlslib/xilinx/Flatten.h index c0a1e51..abfe8cb 100644 --- a/include/hlslib/xilinx/Flatten.h +++ b/include/hlslib/xilinx/Flatten.h @@ -117,9 +117,10 @@ namespace { template struct BitsToRepresent { static constexpr unsigned kBits = - (begin < 0 || end < 0) - ? (ConstLog2(hlslib::max(hlslib::abs(begin), hlslib::abs(end))) + 1) - : ConstLog2(hlslib::max(begin, end)); + 1 + + ((begin < 0 || end < 0) + ? (ConstLog2(hlslib::max(hlslib::abs(begin), hlslib::abs(end))) + 1) + : ConstLog2(hlslib::max(begin, end))); using type = typename std::conditional<(begin < 0 || end < 0), ap_int, ap_uint>::type; }; diff --git a/include/hlslib/xilinx/ShiftRegister.h b/include/hlslib/xilinx/ShiftRegister.h index a11e678..0409334 100644 --- a/include/hlslib/xilinx/ShiftRegister.h +++ b/include/hlslib/xilinx/ShiftRegister.h @@ -48,7 +48,7 @@ struct _MaxImpl { template class _ShiftRegisterStageImpl { - using Index_t = ap_uint; + using Index_t = ap_uint; public: T Shift(T const &next) { diff --git a/include/hlslib/xilinx/Utility.h b/include/hlslib/xilinx/Utility.h index f598050..62d91aa 100644 --- a/include/hlslib/xilinx/Utility.h +++ b/include/hlslib/xilinx/Utility.h @@ -12,7 +12,7 @@ namespace hlslib { // Constexpr methods for compile-time computations constexpr unsigned char ConstLog2(unsigned long val) { - return val == 0 ? 0 : 1 + ConstLog2(val >> 1); + return val <= 1 ? 0 : 1 + ConstLog2(val >> 1); } // Integer division with ceil instead of floor