+#ifdef __F16C__
+
+// Use the f16c instructions from Haswell if available (and we know that they
+// are at compile time).
+static inline double fp16_to_fp64(fp16_int_t x)
+{
+ return _cvtsh_ss(x);
+}
+
+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);
+}
+
+#else
+