|
|
|
@@ -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 |
|
|
|
|