===================================================================
@@ -75,7 +75,8 @@ enum processor_features
FEATURE_SSSE3,
FEATURE_SSE4_1,
FEATURE_SSE4_2,
- FEATURE_AVX
+ FEATURE_AVX,
+ FEATURE_AVX2
};
struct __processor_model
@@ -191,8 +192,11 @@ get_intel_cpu (unsigned int family, unsigned int m
}
}
+/* ECX and EDX are output of CPUID at level one. MAX_CPUID_LEVEL is
+ the max possible level of CPUID insn. */
static void
-get_available_features (unsigned int ecx, unsigned int edx)
+get_available_features (unsigned int ecx, unsigned int edx,
+ int max_cpuid_level)
{
unsigned int features = 0;
@@ -217,6 +221,15 @@ static void
if (ecx & bit_AVX)
features |= (1 << FEATURE_AVX);
+ /* Get Advanced Features at level 7 (eax = 7, ecx = 0). */
+ if (max_cpuid_level >= 7)
+ {
+ unsigned int eax, ebx, ecx, edx;
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ if (ebx & bit_AVX2)
+ features |= (1 << FEATURE_AVX2);
+ }
+
__cpu_model.__cpu_features[0] = features;
}
@@ -296,7 +309,7 @@ __cpu_indicator_init (void)
/* Get CPU type. */
get_intel_cpu (family, model, brand_id);
/* Find available features. */
- get_available_features (ecx, edx);
+ get_available_features (ecx, edx, max_level);
__cpu_model.__cpu_vendor = VENDOR_INTEL;
}
else if (vendor == SIG_AMD)
@@ -311,7 +324,7 @@ __cpu_indicator_init (void)
/* Get CPU type. */
get_amd_cpu (family, model);
/* Find available features. */
- get_available_features (ecx, edx);
+ get_available_features (ecx, edx, max_level);
__cpu_model.__cpu_vendor = VENDOR_AMD;
}
else
===================================================================
@@ -9541,6 +9541,8 @@ SSE4.1 instructions.
SSE4.2 instructions.
@item avx
AVX instructions.
+@item avx2
+AVX2 instructions.
@end table
Here is an example:
===================================================================
@@ -29,6 +29,8 @@ fn1 ()
assert (__builtin_cpu_supports ("avx") >= 0);
+ assert (__builtin_cpu_supports ("avx2") >= 0);
+
/* Check CPU type. */
assert (__builtin_cpu_is ("amd") >= 0);
===================================================================
@@ -27763,6 +27763,7 @@ fold_builtin_cpu (tree fndecl, tree *args)
F_SSE4_1,
F_SSE4_2,
F_AVX,
+ F_AVX2,
F_MAX
};
@@ -27830,7 +27831,8 @@ fold_builtin_cpu (tree fndecl, tree *args)
{"ssse3", F_SSSE3},
{"sse4.1", F_SSE4_1},
{"sse4.2", F_SSE4_2},
- {"avx", F_AVX}
+ {"avx", F_AVX},
+ {"avx2", F_AVX2}
};
static tree __processor_model_type = NULL_TREE;