Browse Source

cleancode

pull/648/head
songmingyang 3 years ago
parent
commit
ba7e6dfcdf
2 changed files with 7 additions and 7 deletions
  1. +2
    -2
      parser/common/parser_fp16_t.cc
  2. +5
    -5
      parser/common/parser_fp16_t.h

+ 2
- 2
parser/common/parser_fp16_t.cc View File

@@ -978,7 +978,7 @@ static void SetValByUint16Val(const uint16_t &input_val, const uint16_t &sign, u
}
} else {
e_ret = static_cast<int16_t>(kFp16ExpBias);
m_tmp = m_tmp << (kManBitLength - len);
m_tmp = m_tmp << static_cast<uint16_t>(kManBitLength - len);
e_ret = e_ret + (len - 1);
}
auto m_ret = static_cast<uint16_t>(m_tmp);
@@ -1116,7 +1116,7 @@ fp16_t &fp16_t::operator=(const uint32_t &ui_val) {
uint32_t m_min = kFp16ManHideBit;
uint32_t m_max = m_min << 1;
uint16_t len = static_cast<uint16_t>(GetManBitLength(m_tmp));
if (len > kDim11) {
if (len > static_cast<>kDim11) {
e_ret = kFp16ExpBias + kFp16ManLen;
uint32_t m_trunc = 0;
uint32_t trunc_mask = 1;


+ 5
- 5
parser/common/parser_fp16_t.h View File

@@ -93,8 +93,8 @@ using BitShift = enum {
/// @brief fp16 exponent bias
constexpr uint16_t kFp16ExpBias = 15U;
/// @ingroup fp16 basic parameter
/// @brief the exponent bit length of fp16 is 5
constexpr uint16_t kFp16ExpLen = 5U;
/// @brief the exponent bit length of fp16 is 10
constexpr uint16_t kFp16ExpLen = 10U;
/// @ingroup fp16 basic parameter
/// @brief the mantissa bit length of fp16 is 10
constexpr uint16_t kFp16ManLen = 10U;
@@ -134,17 +134,17 @@ constexpr uint16_t kFp16MaxMan = 0x03FF;
/// @ingroup fp16 basic operator
/// @brief get sign of fp16
inline uint16_t Fp16ExtracSign(const uint16_t x) {
return (((x) >> 15) & 1);
return (((x) >> kFp16SignIndex) & 1);
}
/// @ingroup fp16 basic operator
/// @brief get exponent of fp16
inline uint16_t Fp16ExtracExp(const uint16_t x) {
return (((x) >> 10) & kFp16MaxExp);
return (((x) >> kFp16ExpLen) & kFp16MaxExp);
}
/// @ingroup fp16 basic operator
/// @brief get mantissa of fp16
inline uint16_t Fp16ExtracMan(const uint16_t x) {
return ((((x) >> 0) & 0x3FF) | (((((x) >> 10) & 0x1F) > 0 ? 1 : 0) * 0x400));
return ((((x) >> 0) & 0x3FF) | (((((x) >> kFp16ManLen) & 0x1F) > 0 ? 1 : 0) * 0x400));
}
/// @ingroup fp16 basic operator
/// @brief constructor of fp16 from sign exponent and mantissa


Loading…
Cancel
Save