Fix 'operands of different size in bitwise operation' klockwork issue. (#5914)
* Fix 'operands of different size in bitwise operation' klockwork issue. * Changed 'byte_idx' type to size_t.
This commit is contained in:
parent
9970f5b248
commit
143fc069a6
@ -19,8 +19,8 @@ namespace ngraph
|
||||
{
|
||||
inline void set_u1(uint8_t* buf, size_t idx, uint8_t val)
|
||||
{
|
||||
const int byte_idx = idx / 8;
|
||||
const int bit_idx = 7 - (idx % 8);
|
||||
const size_t byte_idx = idx / 8;
|
||||
const uint8_t bit_idx = 7 - (idx % 8);
|
||||
if (val)
|
||||
{
|
||||
buf[byte_idx] |= (1 << bit_idx);
|
||||
@ -33,38 +33,38 @@ namespace ngraph
|
||||
|
||||
inline uint8_t get_u1(const uint8_t* buf, size_t idx)
|
||||
{
|
||||
const int byte_idx = idx / 8;
|
||||
const int bit_idx = 7 - (idx % 8);
|
||||
const size_t byte_idx = idx / 8;
|
||||
const uint8_t bit_idx = 7 - (idx % 8);
|
||||
return (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0;
|
||||
}
|
||||
|
||||
inline void set_u4(uint8_t* buf, size_t idx, uint8_t val)
|
||||
{
|
||||
const int byte_idx = idx / 2;
|
||||
const int bit_shift = 4 * (++idx % 2);
|
||||
const size_t byte_idx = idx / 2;
|
||||
const uint8_t bit_shift = 4 * (++idx % 2);
|
||||
buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed
|
||||
buf[byte_idx] |= (val << bit_shift); // set 1's
|
||||
}
|
||||
|
||||
inline uint8_t get_u4(const uint8_t* buf, size_t idx)
|
||||
{
|
||||
const int byte_idx = idx / 2;
|
||||
const int bit_shift = 4 * (++idx % 2);
|
||||
const size_t byte_idx = idx / 2;
|
||||
const uint8_t bit_shift = 4 * (++idx % 2);
|
||||
return (buf[byte_idx] >> bit_shift) & 0xF;
|
||||
}
|
||||
|
||||
inline void set_i4(uint8_t* buf, size_t idx, int8_t val)
|
||||
{
|
||||
const int byte_idx = idx / 2;
|
||||
const int bit_shift = 4 * (++idx % 2);
|
||||
const size_t byte_idx = idx / 2;
|
||||
const uint8_t bit_shift = 4 * (++idx % 2);
|
||||
buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed
|
||||
buf[byte_idx] |= (val << bit_shift); // set 1's
|
||||
}
|
||||
|
||||
inline int8_t get_i4(const uint8_t* buf, size_t idx)
|
||||
{
|
||||
const int byte_idx = idx / 2;
|
||||
const int bit_shift = 4 * (++idx % 2);
|
||||
const size_t byte_idx = idx / 2;
|
||||
const uint8_t bit_shift = 4 * (++idx % 2);
|
||||
uint8_t val = (buf[byte_idx] >> bit_shift) & 0xF;
|
||||
if (val & 0x08)
|
||||
{ // negative number
|
||||
|
Loading…
Reference in New Issue
Block a user