| #include <stdlib.h> |
| #include <cpuid.h> |
| |
| /* Check if the OS supports executing AVX512FP16 instructions. */ |
| |
| #define XCR_XFEATURE_ENABLED_MASK 0x0 |
| |
| #define XSTATE_FP 0x1 |
| #define XSTATE_SSE 0x2 |
| #define XSTATE_YMM 0x4 |
| #define XSTATE_OPMASK 0x20 |
| #define XSTATE_ZMM 0x40 |
| #define XSTATE_HI_ZMM 0x80 |
| |
| static int |
| check_osxsave (void) |
| { |
| unsigned int eax, ebx, ecx, edx; |
| |
| if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) |
| return 0; |
| |
| return (ecx & bit_OSXSAVE) != 0; |
| } |
| |
| static int |
| avx512fp16_os_support (void) |
| { |
| unsigned int eax, edx; |
| unsigned int ecx = XCR_XFEATURE_ENABLED_MASK; |
| unsigned int mask = XSTATE_MASK; |
| |
| if (!check_osxsave ()) |
| return 0; |
| |
| __asm__ ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (ecx)); |
| |
| return ((eax & mask) == mask); |
| } |
| |
| static void do_test (void); |
| |
| int |
| main () |
| { |
| unsigned int eax, ebx, ecx, edx; |
| |
| if (!avx512fp16_os_support ()) |
| return 0; |
| |
| if (__get_cpuid_max (0, NULL) < 7) |
| return 0; |
| |
| __cpuid_count (7, 0, eax, ebx, ecx, edx); |
| |
| /* Run AVX512FP16 test only if host has ISA support. */ |
| if (((ebx & (bit_AVX512F | bit_AVX512BW)) |
| == (bit_AVX512F | bit_AVX512BW)) |
| && (edx & bit_AVX512FP16) |
| && AVX512VL (ebx)) |
| { |
| do_test (); |
| #ifdef DEBUG |
| printf ("PASSED\n"); |
| #endif |
| return 0; |
| } |
| |
| #ifdef DEBUG |
| printf ("SKIPPED\n"); |
| #endif |
| |
| return 0; |
| } |