#pragma once #ifndef FP16_FP16_H #define FP16_FP16_H #if defined(__cplusplus) && (__cplusplus >= 201103L) #include <cstdint> #include <cmath> #elif !defined(__OPENCL_VERSION__) #include <stdint.h> #include <math.h> #endif #ifdef _MSC_VER #include <intrin.h> #endif #include <fp16/bitcasts.h> /* * Convert a 16-bit floating-point number in IEEE half-precision format, in bit representation, to * a 32-bit floating-point number in IEEE single-precision format, in bit representation. * * @note The implementation doesn't use any floating-point operations. */ static inline uint32_t fp16_ieee_to_fp32_bits(uint16_t h) { … } /* * Convert a 16-bit floating-point number in IEEE half-precision format, in bit representation, to * a 32-bit floating-point number in IEEE single-precision format. * * @note The implementation relies on IEEE-like (no assumption about rounding mode and no operations on denormals) * floating-point operations and bitcasts between integer and floating-point variables. */ static inline float fp16_ieee_to_fp32_value(uint16_t h) { … } /* * Convert a 32-bit floating-point number in IEEE single-precision format to a 16-bit floating-point number in * IEEE half-precision format, in bit representation. * * @note The implementation relies on IEEE-like (no assumption about rounding mode and no operations on denormals) * floating-point operations and bitcasts between integer and floating-point variables. */ static inline uint16_t fp16_ieee_from_fp32_value(float f) { … } /* * Convert a 16-bit floating-point number in ARM alternative half-precision format, in bit representation, to * a 32-bit floating-point number in IEEE single-precision format, in bit representation. * * @note The implementation doesn't use any floating-point operations. */ static inline uint32_t fp16_alt_to_fp32_bits(uint16_t h) { … } /* * Convert a 16-bit floating-point number in ARM alternative half-precision format, in bit representation, to * a 32-bit floating-point number in IEEE single-precision format. * * @note The implementation relies on IEEE-like (no assumption about rounding mode and no operations on denormals) * floating-point operations and bitcasts between integer and floating-point variables. */ static inline float fp16_alt_to_fp32_value(uint16_t h) { … } /* * Convert a 32-bit floating-point number in IEEE single-precision format to a 16-bit floating-point number in * ARM alternative half-precision format, in bit representation. * * @note The implementation relies on IEEE-like (no assumption about rounding mode and no operations on denormals) * floating-point operations and bitcasts between integer and floating-point variables. */ static inline uint16_t fp16_alt_from_fp32_value(float f) { … } #endif /* FP16_FP16_H */