diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index 166112c..191ef2a 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -211,25 +211,39 @@ constexpr uint32_t kFp32MaxExp = 0xFFU; 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)) +inline bool FP32_IS_NAN(cons uint16_t x) { + return ((((x) & kFp32ExpMask) == kFp32ExpMask) && ((x) & kFp32ManMask)); +} /// @ingroup fp32 special value judgment /// @brief whether a fp32 is infinite -#define FP32_IS_INF(x) ((((x) & kFp32ExpMask) == kFp32ExpMask) && (!((x) & kFp32ManMask))) +inline bool FP32_IS_INF(const uint16_t x) { + return ((((x) & kFp32ExpMask) == kFp32ExpMask) && (!((x) & kFp32ManMask))); +} /// @ingroup fp32 special value judgment /// @brief whether a fp32 is a denormalized value -#define FP32_IS_DENORM(x) ((((x)&kFp32ExpMask) == 0)) +inline bool FP32_IS_DENORM(const uint16_t x) { + return ((((x)&kFp32ExpMask) == 0)); +} /// @ingroup fp32 basic operator /// @brief get sign of fp32 -#define FP32_EXTRAC_SIGN(x) (((x) >> kFp32SignIndex) & 1) +inline bool FP32_EXTRAC_SIGN(const uint16_t x) { + return (((x) >> kFp32SignIndex) & 1); +} /// @ingroup fp32 basic operator /// @brief get exponent of fp16 -#define FP32_EXTRAC_EXP(x) (((x)&kFp32ExpMask) >> kFp32ManLen) +inline bool FP32_EXTRAC_EXP(const uint16_t x) { + return (((x)&kFp32ExpMask) >> kFp32ManLen); +} /// @ingroup fp32 basic operator /// @brief get mantissa of fp16 -#define FP32_EXTRAC_MAN(x) (((x)&kFp32ManMask) | (((((x) >> kFp32ManLen) & kFp32MaxExp) > 0 ? 1 : 0) * kFp32ManHideBit)) +inline uint16_t FP32_EXTRAC_MAN(const uint16_t x) { + return (((x)&kFp32ManMask) | (((((x) >> kFp32ManLen) & kFp32MaxExp) > 0 ? 1 : 0) * kFp32ManHideBit)); +} /// @ingroup fp32 basic operator /// @brief constructor of fp32 from sign exponent and mantissa -#define FP32_CONSTRUCTOR(s, e, m) (((s) << kFp32SignIndex) | ((e) << kFp32ManLen) | ((m) & kFp32MaxMan)) +inline uint16_t FP32_CONSTRUCTOR(const uint16_t s, const uint16_t e, const uint16_t m) { + return (((s) << kFp32SignIndex) | ((e) << kFp32ManLen) | ((m) & kFp32MaxMan)); +} /// @ingroup fp64 basic parameter /// @brief fp64 exponent bias constexpr uint16_t kFp64ExpBias = 1023U; @@ -265,10 +279,14 @@ constexpr uint64_t kFp64MaxExp = 0x07FF; constexpr uint64_t kFp64MaxMan = 0xFFFFFFFFFFFLLu; /// @ingroup fp64 special value judgment /// @brief whether a fp64 is NaN -#define FP64_IS_NAN(x) ((((x) & kFp64ExpMask) == kFp64ExpMask) && ((x) & kFp64ManMask)) +inline bool FP64_IS_NAN(const uint16_t x) { + return ((((x) & kFp64ExpMask) == kFp64ExpMask) && ((x) & kFp64ManMask)); +} /// @ingroup fp64 special value judgment /// @brief whether a fp64 is infinite -#define FP64_IS_INF(x) ((((x) & kFp64ExpMask) == kFp64ExpMask) && (!((x) & kFp64ManMask))) +inline bool FP64_IS_INF(const uint16_t x) { + return ((((x) & kFp64ExpMask) == kFp64ExpMask) && (!((x) & kFp64ManMask))); +} /// @ingroup integer special value judgment /// @brief maximum positive value of int8_t (0111 1111) constexpr int8_t kInt8Max = 0x7F; @@ -619,7 +637,7 @@ T GetManSum(int16_t e_a, const T &m_a, int16_t e_b, const T &m_b) { T sum = 0; if (e_a != e_b) { T m_tmp = 0; - int16_t e_tmp = std::abs(e_a - e_b); + int16_t e_tmp = static_caststd::abs(e_a - e_b); if (e_a > e_b) { m_tmp = m_b; m_tmp = RightShift(m_tmp, e_tmp);