From ba7e6dfcdf50d46a4833f34a2885d15378f92b06 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 17:48:30 +0800 Subject: [PATCH] cleancode --- parser/common/parser_fp16_t.cc | 4 ++-- parser/common/parser_fp16_t.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/parser/common/parser_fp16_t.cc b/parser/common/parser_fp16_t.cc index 3ce5c6b..fd94a9e 100644 --- a/parser/common/parser_fp16_t.cc +++ b/parser/common/parser_fp16_t.cc @@ -978,7 +978,7 @@ static void SetValByUint16Val(const uint16_t &input_val, const uint16_t &sign, u } } else { e_ret = static_cast(kFp16ExpBias); - m_tmp = m_tmp << (kManBitLength - len); + m_tmp = m_tmp << static_cast(kManBitLength - len); e_ret = e_ret + (len - 1); } auto m_ret = static_cast(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(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; diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index e8722f9..2f970b9 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -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