Skip to content

Commit

Permalink
Merge pull request #49 from definelicht/fix-const-log
Browse files Browse the repository at this point in the history
Fix ConstLog2
  • Loading branch information
definelicht authored Sep 21, 2021
2 parents f9d3555 + ee58342 commit 988dc99
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions include/hlslib/xilinx/Flatten.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ namespace {
template <signed long begin, signed long end>
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<kBits>,
ap_uint<kBits>>::type;
};
Expand Down
2 changes: 1 addition & 1 deletion include/hlslib/xilinx/ShiftRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct _MaxImpl<I, Is...> {

template <typename T, size_t Size>
class _ShiftRegisterStageImpl {
using Index_t = ap_uint<hlslib::ConstLog2(Size)>;
using Index_t = ap_uint<hlslib::ConstLog2(Size) + 1>;

public:
T Shift(T const &next) {
Expand Down
2 changes: 1 addition & 1 deletion include/hlslib/xilinx/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 988dc99

Please sign in to comment.