From c6d88d8b5b73b3bdf5725a9630ce775763481f5a Mon Sep 17 00:00:00 2001 From: zhao-lupeng Date: Wed, 25 May 2022 14:16:47 +0800 Subject: [PATCH] test1 --- parser/common/parser_fp16_t.cc | 32 ++++++++++++++++---------------- parser/common/parser_fp16_t.h | 32 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/parser/common/parser_fp16_t.cc b/parser/common/parser_fp16_t.cc index 92d9964..8eaf2d6 100644 --- a/parser/common/parser_fp16_t.cc +++ b/parser/common/parser_fp16_t.cc @@ -20,7 +20,7 @@ #include "graph/def_types.h" namespace { -constexpr uint16_t kManBitLength = 11; +constexpr uint16_t kManBitLength = 11U; } namespace ge { namespace parser { @@ -100,7 +100,7 @@ static float Fp16ToFloat(const uint16_t &fp_val) { e_ret = 0; m_ret = 0; } else { - e_ret = hf_exp - kFp16ExpBias + kFp32ExpBias; + e_ret = static_cast(hf_exp) - static_cast(kFp16ExpBias) + static_cast(kFp32ExpBias); m_ret = hf_man & kFp16ManMask; m_ret = m_ret << (kFp32ManLen - kFp16ManLen); } @@ -132,7 +132,7 @@ static double Fp16ToDouble(const uint16_t &fp_val) { e_ret = 0; m_ret = 0; } else { - e_ret = hf_exp - kFp16ExpBias + kFp64ExpBias; + e_ret = static_cast(hf_exp) - static_cast(kFp16ExpBias) + static_cast(kFp64ExpBias); m_ret = hf_man & kFp16ManMask; m_ret = m_ret << (kFp64ManLen - kFp16ManLen); } @@ -156,7 +156,7 @@ static uint8_t GetUint8ValByMan(uint8_t s_ret, const uint64_t &long_int_m, const m_ret++; } if (static_cast(s_ret)) { - m_ret = (~m_ret) + 1; + m_ret = (~m_ret) + 1U; } if (m_ret == 0) { s_ret = 0; @@ -285,7 +285,7 @@ static uint16_t GetUint16ValByMan(uint16_t s_ret, const uint64_t &long_int_m, co m_ret++; } if (static_cast(s_ret)) { - m_ret = (~m_ret) + 1; + m_ret = (~m_ret) + 1U; } if (m_ret == 0) { s_ret = 0; @@ -676,14 +676,14 @@ static uint16_t Fp16Div(uint16_t v_1, uint16_t v_2) { uint64_t m_tmp; if (e_a > e_b) { m_tmp = m_a; - uint16_t tmp = e_a - e_b; + uint16_t tmp = static_cast(e_a - e_b); for (int i = 0; i < tmp; i++) { m_tmp = m_tmp << 1; } m_a = m_tmp; } else if (e_a < e_b) { m_tmp = m_b; - uint16_t tmp = e_b - e_a; + uint16_t tmp = static_cast(e_b - e_a); for (int i = 0; i < tmp; i++) { m_tmp = m_tmp << 1; } @@ -918,7 +918,7 @@ fp16_t &fp16_t::operator=(const int8_t &i_val) { e_ret = kFp16ManLen; while ((m_ret & kFp16ManHideBit) == 0) { m_ret = m_ret << 1; - e_ret = e_ret - 1; + e_ret = e_ret - 1U; } e_ret = e_ret + kFp16ExpBias; } @@ -936,7 +936,7 @@ fp16_t &fp16_t::operator=(const uint8_t &ui_val) { e_ret = kFp16ManLen; while ((m_ret & kFp16ManHideBit) == 0) { m_ret = m_ret << 1; - e_ret = e_ret - 1; + e_ret = e_ret - 1U; } e_ret = e_ret + kFp16ExpBias; } @@ -954,7 +954,7 @@ static void SetValByUint16Val(const uint16_t &input_val, const uint16_t &sign, u int16_t e_ret; if (len > kDim11) { e_ret = kFp16ExpBias + kFp16ManLen; - uint16_t e_tmp = len - kDim11; + uint16_t e_tmp = len - static_cast(kDim11); uint32_t trunc_mask = 1; for (int i = 1; i < e_tmp; i++) { trunc_mask = (trunc_mask << 1) + 1; @@ -977,7 +977,7 @@ static void SetValByUint16Val(const uint16_t &input_val, const uint16_t &sign, u e_ret = e_ret + 1; } } else { - e_ret = kFp16ExpBias; + e_ret = static_cast(kFp16ExpBias); m_tmp = m_tmp << (kManBitLength - len); e_ret = e_ret + (len - 1); } @@ -1039,7 +1039,7 @@ fp16_t &fp16_t::operator=(const uint16_t &ui_val) { val = kFp16Max; } } else { - e_ret = kFp16ExpBias; + e_ret = static_cast(kFp16ExpBias); m_ret = m_ret << (kDim11 - len); e_ret = e_ret + (len - 1); } @@ -1058,7 +1058,7 @@ static void SetValByUint32Val(const uint32_t &input_val, const uint16_t &sign, u e_ret = kFp16ExpBias + kFp16ManLen; uint32_t m_trunc = 0; uint32_t trunc_mask = 1; - uint16_t e_tmp = len - kDim11; + uint16_t e_tmp = len - static_cast(kDim11); for (int i = 1; i < e_tmp; i++) { trunc_mask = (trunc_mask << 1) + 1; } @@ -1084,7 +1084,7 @@ static void SetValByUint32Val(const uint32_t &input_val, const uint16_t &sign, u m_tmp = kFp16MaxMan; } } else { - e_ret = kFp16ExpBias; + e_ret = static_cast(kFp16ExpBias); m_tmp = m_tmp << (kDim11 - len); e_ret = e_ret + (len - 1); } @@ -1120,7 +1120,7 @@ fp16_t &fp16_t::operator=(const uint32_t &ui_val) { e_ret = kFp16ExpBias + kFp16ManLen; uint32_t m_trunc = 0; uint32_t trunc_mask = 1; - uint16_t e_tmp = len - kDim11; + uint16_t e_tmp = len - static_cast(kDim11); for (int i = 1; i < e_tmp; i++) { trunc_mask = (trunc_mask << 1) + 1; } @@ -1146,7 +1146,7 @@ fp16_t &fp16_t::operator=(const uint32_t &ui_val) { m_tmp = kFp16MaxMan; } } else { - e_ret = kFp16ExpBias; + e_ret = static_cast(kFp16ExpBias); m_tmp = m_tmp << (kDim11 - len); e_ret = e_ret + (len - 1); } diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index a8bf36f..2a50d2f 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -91,16 +91,16 @@ using BitShift = enum { }; /// @ingroup fp16 basic parameter /// @brief fp16 exponent bias -constexpr uint16_t kFp16ExpBias = 15; +constexpr uint16_t kFp16ExpBias = 15U; /// @ingroup fp16 basic parameter /// @brief the exponent bit length of fp16 is 5 -constexpr uint16_t kFp16ExpLen = 5; +constexpr uint16_t kFp16ExpLen = 5U; /// @ingroup fp16 basic parameter /// @brief the mantissa bit length of fp16 is 10 -constexpr uint16_t kFp16ManLen = 10; +constexpr uint16_t kFp16ManLen = 10U; /// @ingroup fp16 basic parameter /// @brief bit index of sign in fp16 -constexpr uint16_t kFp16SignIndex = 15; +constexpr uint16_t kFp16SignIndex = 15U; /// @ingroup fp16 basic parameter /// @brief sign mask of fp16 (1 00000 00000 00000) constexpr uint16_t kFp16SignMask = 0x8000; @@ -164,16 +164,16 @@ constexpr uint16_t kFp16MinNormal = 1.0f / (2 << 14); #define FP16_IS_INVALID(x) (((x) & kFp16ExpMask) == kFp16ExpMask) /// @ingroup fp32 basic parameter /// @brief fp32 exponent bias -constexpr uint16_t kFp32ExpBias = 127; +constexpr uint16_t kFp32ExpBias = 127U; /// @ingroup fp32 basic parameter /// @brief the exponent bit length of float/fp32 is 8 -constexpr uint16_t kFp32ExpLen = 8; +constexpr uint16_t kFp32ExpLen = 8U; /// @ingroup fp32 basic parameter /// @brief the mantissa bit length of float/fp32 is 23 -constexpr uint16_t kFp32ManLen = 23; +constexpr uint16_t kFp32ManLen = 23U; /// @ingroup fp32 basic parameter /// @brief bit index of sign in float/fp32 -constexpr uint16_t kFp32SignIndex = 31; +constexpr uint16_t kFp32SignIndex = 31U; /// @ingroup fp32 basic parameter /// @brief sign mask of fp32 (1 0000 0000 0000 0000 0000 0000 000) constexpr uint32_t kFp32SignMask = 0x80000000u; @@ -191,10 +191,10 @@ constexpr uint32_t kFp32ManHideBit = 0x00800000u; constexpr uint32_t kFp32AbsMax = 0x7FFFFFFFu; /// @ingroup fp32 basic parameter /// @brief maximum exponent value of fp32 is 255(1111 1111) -constexpr uint32_t kFp32MaxExp = 0xFF; +constexpr uint32_t kFp32MaxExp = 0xFFU; /// @ingroup fp32 basic parameter /// @brief maximum mantissa value of fp32 (1111 1111 1111 1111 1111 111) -constexpr uint32_t kFp32MaxMan = 0x7FFFFF; +constexpr uint32_t kFp32MaxMan = 0x7FFFFFU; /// @ingroup fp32 special value judgment /// @brief whether a fp32 is NaN #define FP32_IS_NAN(x) ((((x) & kFp32ExpMask) == kFp32ExpMask) && ((x) & kFp32ManMask)) @@ -218,16 +218,16 @@ constexpr uint32_t kFp32MaxMan = 0x7FFFFF; #define FP32_CONSTRUCTOR(s, e, m) (((s) << kFp32SignIndex) | ((e) << kFp32ManLen) | ((m) & kFp32MaxMan)) /// @ingroup fp64 basic parameter /// @brief fp64 exponent bias -constexpr uint16_t kFp64ExpBias = 1023; +constexpr uint16_t kFp64ExpBias = 1023U; /// @ingroup fp64 basic parameter /// @brief the exponent bit length of double/fp64 is 11 -constexpr uint16_t kFp64ExpLen = 11; +constexpr uint16_t kFp64ExpLen = 11U; /// @ingroup fp64 basic parameter /// @brief the mantissa bit length of double/fp64 is 52 -constexpr uint16_t kFp64ManLen = 52; +constexpr uint16_t kFp64ManLen = 52U; /// @ingroup fp64 basic parameter /// @brief bit index of sign in double/fp64 is 63 -constexpr uint16_t kFp64SignIndex = 63; +constexpr uint16_t kFp64SignIndex = 63U; /// @ingroup fp64 basic parameter /// @brief sign mask of fp64 (1 000 (total 63bits 0)) constexpr uint64_t kFp64SignMask = 0x8000000000000000LLu; @@ -269,14 +269,14 @@ constexpr int16_t kInt16Max = 0x7FFF; constexpr uint16_t kBitLen16Max = 0xFFFF; /// @ingroup integer special value judgment /// @brief maximum positive value of int32_t (0111 1111 1111 1111 1111 1111 1111 1111) -constexpr int32_t kInt32Max = 0x7FFFFFFFu; +constexpr int32_t kInt32Max = 0x7FFFFFFF; /// @ingroup integer special value judgment /// @brief maximum value of a data with 32 bits length (1111 1111 1111 1111 1111 1111 1111 1111) constexpr uint32_t kBitLen32Max = 0xFFFFFFFFu; /// @ingroup integer special value judgment /// @brief maximum positive value of int64_t /// (0111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111) -constexpr int64_t kInt64Max = 0x7FFFFFFFFFFFFFFFu; +constexpr int64_t kInt64Max = 0x7FFFFFFFFFFFFFFF; /// @ingroup integer special value judgment /// @brief maximum value of a data with 64 bits length /// (1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111)