Invalid `static_cast<_Float16>` on AVX512 with GCC 13+

Summary

Using Eigen on an AVX512 system such as Sapphire Rapids starts to fail to compile with GCC 13 with invalid 'static_cast' from type 'const Eigen::half' to type '_Float16'

Environment

  • Operating System : Windows
  • Architecture : x64
  • Eigen Version : 3.4.0
  • Compiler Version : GCC 13.1 -> GCC 14.1
  • Compile Flags : -march=sapphirerapids

Minimal Example

#include <Eigen/Core>

Or reduced to the minimal one: https://godbolt.org/z/rneW1G8qz

Steps to reproduce

  1. Compile with GCC 12.x --> Works
  2. Compile with GCC 13.x/14.x --> Fails g++ -march=sapphirerapids

What is the current bug behavior?

What is the expected correct behavior?

Relevant logs

/src/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h:123:25: error: invalid 'static_cast' from type 'const Eigen::half' to type '_Float16'
  123 |   return _mm512_set1_ph(static_cast<_Float16>(from));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h:216:39: error: invalid user-defined conversion from 'const Eigen::half' to '_Float16' [-fpermissive]
  216 |   return _mm512_add_ph(_mm512_set1_ph(a),
      |                                       ^
In file included from /src/eigen/Eigen/Core:175:
/src/eigen/Eigen/src/Core/arch/Default/Half.h:192:22: note: candidate is: 'Eigen::half::operator float() const' (near match)
  192 |    EIGEN_DEVICE_FUNC operator float() const {  // NOLINT: Allow implicit conversion to float, because it is lossless.
      |                      ^~~~~~~~
/src/eigen/Eigen/src/Core/arch/Default/Half.h:192:22: note:   no known conversion from 'float' to '_Float16'

# Many more warnings

/src/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h:217:38: warning: converting to '_Float16' from 'float' with greater conversion rank
  217 |                        _mm512_set_ph(31.0f, 30.0f, 29.0f, 28.0f, 27.0f, 26.0f, 25.0f, 24.0f, 23.0f, 22.0f, 21.0f, 20.0f,
      |                                      ^~~~~
/opt/gcc/13.2.0/lib/gcc/x86_64-pc-linux-gnu/13.2.0/include/avx512fp16intrin.h:83:25: note:   initializing argument 1 of '__m512h _mm512_set_ph(_Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16, _Float16)'
   83 | _mm512_set_ph (_Float16 __A31, _Float16 __A30, _Float16 __A29,
      |                ~~~~~~~~~^~~~~
/src/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h:217:45: warning: converting to '_Float16' from 'float' with greater conversion rank
  217 |                        _mm512_set_ph(31.0f, 30.0f, 29.0f, 28.0f, 27.0f, 26.0f, 25.0f, 24.0f, 23.0f, 22.0f, 21.0f, 20.0f,
      |                                             ^~~~~