From: Steinar H. Gunderson Date: Sat, 21 Feb 2015 14:26:57 +0000 (+0100) Subject: Add some fp16 conversion overloads, for making code that can be templatized across... X-Git-Tag: 1.1.3~14 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=cea222cc88f1e210cd73331d74d0b33a67de3d81 Add some fp16 conversion overloads, for making code that can be templatized across fp16 and fp32. --- diff --git a/fp16.h b/fp16.h index 9f7eff9..4e6652f 100644 --- a/fp16.h +++ b/fp16.h @@ -22,6 +22,22 @@ fp16_int_t fp64_to_fp16(double x); double fp32_to_fp64(fp32_int_t x); fp32_int_t fp64_to_fp32(double x); +// Overloads for use in templates. +static inline double to_fp64(double x) { return x; } +static inline double to_fp64(float x) { return x; } +static inline double to_fp64(fp16_int_t x) { return fp16_to_fp64(x); } + +template inline T from_fp64(double x); +template<> inline double from_fp64(double x) { return x; } +template<> inline float from_fp64(double x) { return x; } +template<> inline fp16_int_t from_fp64(double x) { return fp64_to_fp16(x); } + +template +inline To convert_float(From x) { return from_fp64(to_fp64(x)); } + +template +inline Same convert_float(Same x) { return x; } + } // namespace movit #endif // _MOVIT_FP16_H