1 //===--- Float16bits.h - supports 2-byte floats ---------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements f16 and bf16 to support the compilation and execution 10 // of programs using these types. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_EXECUTIONENGINE_FLOAT16BITS_H_ 15 #define MLIR_EXECUTIONENGINE_FLOAT16BITS_H_ 16 17 #include <cstdint> 18 #include <iostream> 19 20 // Implements half precision and bfloat with f16 and bf16, using the MLIR type 21 // names. These data types are also used for c-interface runtime routines. 22 extern "C" { 23 struct f16 { 24 f16(float f = 0); 25 uint16_t bits; 26 }; 27 28 struct bf16 { 29 bf16(float f = 0); 30 uint16_t bits; 31 }; 32 } 33 34 // Outputs a half precision value. 35 std::ostream &operator<<(std::ostream &os, const f16 &f); 36 // Outputs a bfloat value. 37 std::ostream &operator<<(std::ostream &os, const bf16 &d); 38 39 #endif // MLIR_EXECUTIONENGINE_FLOAT16BITS_H_ 40