X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=fp16.h;h=c21153b3466fe71424283063cb7cf9b775a89153;hp=5417e020b82cdfc039e78a1124b3c98833604e77;hb=0c821b2eb013de712041d2b337612b9a6297695f;hpb=6be20704cdc7b64e37cc886b7872df58ef66eb1f diff --git a/fp16.h b/fp16.h index 5417e02..c21153b 100644 --- a/fp16.h +++ b/fp16.h @@ -14,8 +14,13 @@ namespace movit { -typedef unsigned int fp32_int_t; -typedef unsigned short fp16_int_t; +// structs instead of ints, so that they are not implicitly convertible. +struct fp32_int_t { + unsigned int val; +}; +struct fp16_int_t { + unsigned short val; +}; #ifdef __F16C__ @@ -23,14 +28,16 @@ typedef unsigned short fp16_int_t; // are at compile time). static inline double fp16_to_fp64(fp16_int_t x) { - return _cvtsh_ss(x); + return _cvtsh_ss(x.val); } static inline fp16_int_t fp64_to_fp16(double x) { // NOTE: Strictly speaking, there are some select values where this isn't correct, // since we first round to fp32 and then to fp16. - return _cvtss_sh(x, 0); + fp16_int_t ret; + ret.val = _cvtss_sh(x, 0); + return ret; } #else