[Mlir-commits] [mlir] b312776 - [mlir][sparse] Preserve NaNs when converting float to bfloat
Benjamin Kramer
llvmlistbot at llvm.org
Tue Jun 21 06:30:39 PDT 2022
Author: Benjamin Kramer
Date: 2022-06-21T15:22:35+02:00
New Revision: b3127769b1ae39928a76b0a0469152c0f826e424
URL: https://github.com/llvm/llvm-project/commit/b3127769b1ae39928a76b0a0469152c0f826e424
DIFF: https://github.com/llvm/llvm-project/commit/b3127769b1ae39928a76b0a0469152c0f826e424.diff
LOG: [mlir][sparse] Preserve NaNs when converting float to bfloat
Added:
Modified:
mlir/lib/ExecutionEngine/Float16bits.cpp
Removed:
################################################################################
diff --git a/mlir/lib/ExecutionEngine/Float16bits.cpp b/mlir/lib/ExecutionEngine/Float16bits.cpp
index 289eaeab2ccc..96eed35fef26 100644
--- a/mlir/lib/ExecutionEngine/Float16bits.cpp
+++ b/mlir/lib/ExecutionEngine/Float16bits.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "mlir/ExecutionEngine/Float16bits.h"
+#include <cmath>
namespace {
@@ -106,6 +107,9 @@ const uint32_t kF32BfMantiBitDiff = 16;
// Constructs the 16 bit representation for a bfloat value from a float value.
// This implementation is adapted from Eigen.
uint16_t float2bfloat(float floatValue) {
+ if (std::isnan(floatValue))
+ return std::signbit(floatValue) ? 0xFFC0 : 0x7FC0;
+
Float32Bits floatBits;
floatBits.f = floatValue;
uint16_t bfloatBits;
More information about the Mlir-commits
mailing list