mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-01 16:30:15 +00:00
Merge branch 'f16c.msvc' into 'master'
Fix F16C build/runtime detection on Visual Studio See merge request GNOME/gtk!3429
This commit is contained in:
commit
442f485591
@ -80,6 +80,12 @@ half_to_float4_c (const guint16 h[4],
|
|||||||
|
|
||||||
#ifdef HAVE_F16C
|
#ifdef HAVE_F16C
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
#define CAST_M128I_P(a) (__m128i const *) a
|
||||||
|
#else
|
||||||
|
#define CAST_M128I_P(a) (__m128i_u const *) a
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
float_to_half4_f16c (const float f[4],
|
float_to_half4_f16c (const float f[4],
|
||||||
guint16 h[4])
|
guint16 h[4])
|
||||||
@ -93,11 +99,61 @@ static void
|
|||||||
half_to_float4_f16c (const guint16 h[4],
|
half_to_float4_f16c (const guint16 h[4],
|
||||||
float f[4])
|
float f[4])
|
||||||
{
|
{
|
||||||
__m128i i = _mm_loadl_epi64 ((__m128i_u const *)h);
|
__m128i i = _mm_loadl_epi64 (CAST_M128I_P (h));
|
||||||
__m128 s = _mm_cvtph_ps (i);
|
__m128 s = _mm_cvtph_ps (i);
|
||||||
|
|
||||||
_mm_store_ps (f, s);
|
_mm_store_ps (f, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef CAST_M128I_P
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
/* based on info from https://walbourn.github.io/directxmath-f16c-and-fma/ */
|
||||||
|
static gboolean
|
||||||
|
have_f16c_msvc (void)
|
||||||
|
{
|
||||||
|
static gboolean result = FALSE;
|
||||||
|
static gsize inited = 0;
|
||||||
|
|
||||||
|
if (g_once_init_enter (&inited))
|
||||||
|
{
|
||||||
|
int cpuinfo[4] = { -1 };
|
||||||
|
|
||||||
|
__cpuid (cpuinfo, 0);
|
||||||
|
|
||||||
|
if (cpuinfo[0] > 0)
|
||||||
|
{
|
||||||
|
__cpuid (cpuinfo, 1);
|
||||||
|
|
||||||
|
if ((cpuinfo[2] & 0x8000000) != 0)
|
||||||
|
result = (cpuinfo[2] & 0x20000000) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_once_init_leave (&inited, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
float_to_half4 (const float f[4], guint16 h[4])
|
||||||
|
{
|
||||||
|
if (have_f16c_msvc ())
|
||||||
|
float_to_half4_f16c (f, h);
|
||||||
|
else
|
||||||
|
float_to_half4_c (f, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
half_to_float4 (const guint16 h[4], float f[4])
|
||||||
|
{
|
||||||
|
if (have_f16c_msvc ())
|
||||||
|
half_to_float4_f16c (h, f);
|
||||||
|
else
|
||||||
|
half_to_float4_c (h, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
void float_to_half4 (const float f[4], guint16 h[4]) __attribute__((ifunc ("resolve_float_to_half4")));
|
void float_to_half4 (const float f[4], guint16 h[4]) __attribute__((ifunc ("resolve_float_to_half4")));
|
||||||
void half_to_float4 (const guint16 h[4], float f[4]) __attribute__((ifunc ("resolve_half_to_float4")));
|
void half_to_float4 (const guint16 h[4], float f[4]) __attribute__((ifunc ("resolve_half_to_float4")));
|
||||||
|
|
||||||
@ -120,11 +176,12 @@ resolve_half_to_float4 (void)
|
|||||||
else
|
else
|
||||||
return half_to_float4_c;
|
return half_to_float4_c;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#if defined(__APPLE__) || (defined(_MSC_VER) && !defined(__clang__))
|
||||||
// turns out aliases don't work on Darwin
|
// turns out aliases don't work on Darwin nor Visual Studio
|
||||||
|
|
||||||
void
|
void
|
||||||
float_to_half4 (const float f[4],
|
float_to_half4 (const float f[4],
|
||||||
|
@ -692,10 +692,8 @@ if get_option('f16c').enabled()
|
|||||||
# if !defined(__amd64__) && !defined(__x86_64__)
|
# if !defined(__amd64__) && !defined(__x86_64__)
|
||||||
# error "F16C intrinsics are only available on x86_64"
|
# error "F16C intrinsics are only available on x86_64"
|
||||||
# endif
|
# endif
|
||||||
#elif defined (_MSC_VER) && !defined (_M_X64) && !defined (_M_AMD64)
|
|
||||||
# error "F16C intrinsics not supported on x86 MSVC builds"
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__SSE__) || (_M_X64 > 0)
|
#if defined(__SSE__) || defined(_MSC_VER)
|
||||||
# include <immintrin.h>
|
# include <immintrin.h>
|
||||||
#else
|
#else
|
||||||
# error "No F16C intrinsics available"
|
# error "No F16C intrinsics available"
|
||||||
@ -707,8 +705,10 @@ int main () {
|
|||||||
__m128i i = _mm_cvtps_ph (s, 0);
|
__m128i i = _mm_cvtps_ph (s, 0);
|
||||||
_mm_storel_epi64 ((__m128i*)h, i);
|
_mm_storel_epi64 ((__m128i*)h, i);
|
||||||
|
|
||||||
|
#if defined (__GNUC__) || defined (__clang__)
|
||||||
__builtin_cpu_init ();
|
__builtin_cpu_init ();
|
||||||
__builtin_cpu_supports ("f16c");
|
__builtin_cpu_supports ("f16c");
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}'''
|
}'''
|
||||||
|
Loading…
Reference in New Issue
Block a user