| 1 |
/* This test checks if the __builtin_cpu_is and __builtin_cpu_supports calls |
| 2 |
are recognized. It also independently uses CPUID to get cpu type and |
| 3 |
features supported and checks if the builtins correctly identify the |
| 4 |
platform. The code to do the identification is adapted from |
| 5 |
libgcc/config/i386/cpuinfo.c. */ |
| 6 |
|
| 7 |
/* { dg-do run } */ |
| 8 |
|
| 9 |
#include <assert.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include "cpuid.h" |
| 12 |
#define CHECK___builtin_cpu_is(cpu) assert (__builtin_cpu_is (cpu)) |
| 13 |
#define CHECK___builtin_cpu_supports(isa) \ |
| 14 |
assert (__builtin_cpu_supports (isa)) |
| 15 |
#define gcc_assert(a) assert (a) |
| 16 |
#define gcc_unreachable() abort () |
| 17 |
#define inline |
| 18 |
#include "../../../common/config/i386/i386-cpuinfo.h" |
| 19 |
#include "../../../common/config/i386/cpuinfo.h" |
| 20 |
|
| 21 |
/* Check if the ISA features are identified. */ |
| 22 |
static void |
| 23 |
check_features (struct __processor_model *cpu_model, |
| 24 |
unsigned int *cpu_features2) |
| 25 |
{ |
| 26 |
#define has_feature(f) \ |
| 27 |
has_cpu_feature (cpu_model, cpu_features2, f) |
| 28 |
#define ISA_NAMES_TABLE_START |
| 29 |
#define ISA_NAMES_TABLE_END |
| 30 |
#define ISA_NAMES_TABLE_ENTRY(name, feature, priority, option) \ |
| 31 |
assert (!!has_feature (feature) == !!__builtin_cpu_supports (name)); |
| 32 |
#include "../../../common/config/i386/i386-isas.h" |
| 33 |
} |
| 34 |
|
| 35 |
static int |
| 36 |
check_detailed () |
| 37 |
{ |
| 38 |
struct __processor_model cpu_model = { 0 }; |
| 39 |
struct __processor_model2 cpu_model2 = { 0 }; |
| 40 |
unsigned int cpu_features2[SIZE_OF_CPU_FEATURES] = { 0 }; |
| 41 |
|
| 42 |
if (cpu_indicator_init (&cpu_model, &cpu_model2, cpu_features2) != 0) |
| 43 |
return 0; |
| 44 |
|
| 45 |
check_features (&cpu_model, cpu_features2); |
| 46 |
|
| 47 |
switch (cpu_model.__cpu_vendor) |
| 48 |
{ |
| 49 |
case VENDOR_INTEL: |
| 50 |
assert (__builtin_cpu_is ("intel")); |
| 51 |
get_intel_cpu (&cpu_model, &cpu_model2, cpu_features2); |
| 52 |
break; |
| 53 |
case VENDOR_AMD: |
| 54 |
assert (__builtin_cpu_is ("amd")); |
| 55 |
get_amd_cpu (&cpu_model, &cpu_model2, cpu_features2); |
| 56 |
break; |
| 57 |
case VENDOR_HYGON: |
| 58 |
assert (__builtin_cpu_is ("hygon")); |
| 59 |
get_hygon_cpu (&cpu_model, &cpu_model2, cpu_features2); |
| 60 |
break; |
| 61 |
default: |
| 62 |
break; |
| 63 |
} |
| 64 |
|
| 65 |
return 0; |
| 66 |
} |
| 67 |
|
| 68 |
static int |
| 69 |
quick_check () |
| 70 |
{ |
| 71 |
/* Check CPU Features. */ |
| 72 |
assert (__builtin_cpu_supports ("cmov") >= 0); |
| 73 |
|
| 74 |
assert (__builtin_cpu_supports ("mmx") >= 0); |
| 75 |
|
| 76 |
assert (__builtin_cpu_supports ("popcnt") >= 0); |
| 77 |
|
| 78 |
assert (__builtin_cpu_supports ("sse") >= 0); |
| 79 |
|
| 80 |
assert (__builtin_cpu_supports ("sse2") >= 0); |
| 81 |
|
| 82 |
assert (__builtin_cpu_supports ("sse3") >= 0); |
| 83 |
|
| 84 |
assert (__builtin_cpu_supports ("ssse3") >= 0); |
| 85 |
|
| 86 |
assert (__builtin_cpu_supports ("sse4.1") >= 0); |
| 87 |
|
| 88 |
assert (__builtin_cpu_supports ("sse4.2") >= 0); |
| 89 |
|
| 90 |
assert (__builtin_cpu_supports ("avx") >= 0); |
| 91 |
|
| 92 |
assert (__builtin_cpu_supports ("avx2") >= 0); |
| 93 |
|
| 94 |
assert (__builtin_cpu_supports ("avx512f") >= 0); |
| 95 |
|
| 96 |
assert (__builtin_cpu_supports ("avx512vpopcntdq") >= 0); |
| 97 |
|
| 98 |
assert (__builtin_cpu_supports ("x86-64") >= 0); |
| 99 |
assert (__builtin_cpu_supports ("x86-64-v2") >= 0); |
| 100 |
assert (__builtin_cpu_supports ("x86-64-v3") >= 0); |
| 101 |
assert (__builtin_cpu_supports ("x86-64-v4") >= 0); |
| 102 |
|
| 103 |
/* Check CPU type. */ |
| 104 |
assert (__builtin_cpu_is ("amd") >= 0); |
| 105 |
|
| 106 |
assert (__builtin_cpu_is ("intel") >= 0); |
| 107 |
|
| 108 |
assert (__builtin_cpu_is ("atom") >= 0); |
| 109 |
|
| 110 |
assert (__builtin_cpu_is ("core2") >= 0); |
| 111 |
|
| 112 |
assert (__builtin_cpu_is ("corei7") >= 0); |
| 113 |
|
| 114 |
assert (__builtin_cpu_is ("nehalem") >= 0); |
| 115 |
|
| 116 |
assert (__builtin_cpu_is ("westmere") >= 0); |
| 117 |
|
| 118 |
assert (__builtin_cpu_is ("sandybridge") >= 0); |
| 119 |
|
| 120 |
assert (__builtin_cpu_is ("amdfam10h") >= 0); |
| 121 |
|
| 122 |
assert (__builtin_cpu_is ("barcelona") >= 0); |
| 123 |
|
| 124 |
assert (__builtin_cpu_is ("shanghai") >= 0); |
| 125 |
|
| 126 |
assert (__builtin_cpu_is ("istanbul") >= 0); |
| 127 |
|
| 128 |
assert (__builtin_cpu_is ("amdfam15h") >= 0); |
| 129 |
|
| 130 |
assert (__builtin_cpu_is ("bdver1") >= 0); |
| 131 |
|
| 132 |
assert (__builtin_cpu_is ("bdver2") >= 0); |
| 133 |
|
| 134 |
assert (__builtin_cpu_is ("c86-4g-m4") >= 0); |
| 135 |
|
| 136 |
return 0; |
| 137 |
} |
| 138 |
|
| 139 |
int main () |
| 140 |
{ |
| 141 |
__builtin_cpu_init (); |
| 142 |
quick_check (); |
| 143 |
check_detailed (); |
| 144 |
return 0; |
| 145 |
} |