Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12401: UB when sizeof(std::size_t) in floor_log2
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-08-19 18:50:26
#12401: UB when sizeof(std::size_t) in floor_log2
-------------------------------+------------------------
Reporter: viboes | Owner: igaztanaga
Type: Bugs | Status: closed
Milestone: To Be Determined | Component: intrusive
Version: Boost 1.61.0 | Severity: Problem
Resolution: invalid | Keywords:
-------------------------------+------------------------
Changes (by igaztanaga):
* status: new => closed
* resolution: => invalid
Comment:
That function is only called if sizeof(std::size_t)*CHAR_BIT is 64:
{{{
inline std::size_t floor_log2 (std::size_t x)
{
const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT;
return floor_log2(x, integral_constant<std::size_t, Bits>());
}
}}}
The 32 bit version uses only 16 bit shift:
{{{
inline std::size_t floor_log2 (std::size_t v,
integral_constant<std::size_t, 32>)
{
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
};
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
return MultiplyDeBruijnBitPosition[(std::size_t)(v * 0x07C4ACDDU) >>
27];
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12401#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC