From 5e987c2798d06adcbb139a0a923cbeb5a02e28d2 Mon Sep 17 00:00:00 2001 From: qnqinan Date: Wed, 16 Jan 2019 18:24:56 +0800 Subject: [PATCH] fix a bug in fp16 to fp32 --- src/fpga/common/fpga_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fpga/common/fpga_common.cpp b/src/fpga/common/fpga_common.cpp index 0a1787aa3f..bf90a3a119 100644 --- a/src/fpga/common/fpga_common.cpp +++ b/src/fpga/common/fpga_common.cpp @@ -76,7 +76,7 @@ int32_t convertmantissa(int32_t i) { } float fp16_2_fp32(int16_t fp16_num) { - int16_t se_fp16 = fp16_num >> 10; + int16_t se_fp16 = (fp16_num >> 10) & 0x3f; int16_t m_fp16 = fp16_num & 0x3ff; int32_t e_fp32 = 0; int16_t offset = 0; @@ -94,7 +94,7 @@ float fp16_2_fp32(int16_t fp16_num) { e_fp32 = 0x80000000; offset = 0; } else if (se_fp16 < 63) { - e_fp32 = 0x80000000 + (se_fp16 - 32) << 23; + e_fp32 = 0x80000000 + ((se_fp16 - 32) << 23); offset = 1024; } else { // se_fp16 == 63 e_fp32 = 0xC7800000; -- GitLab