+// 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__
+
+// Use the f16c instructions from Haswell if available (and we know that they
+// are at compile time).
+static inline float fp16_to_fp32(fp16_int_t x)
+{
+ return _cvtsh_ss(x.val);
+}
+
+static inline fp16_int_t fp32_to_fp16(float x)
+{
+ fp16_int_t ret;
+ ret.val = _cvtss_sh(x, 0);
+ return ret;
+}
+
+#else