56b8fcc
commit a1eb3915e781c5b9aed89931cbd536a186c15ed5
56b8fcc
Author: Florian Weimer <fweimer@redhat.com>
56b8fcc
Date:   Tue Mar 2 14:58:05 2021 +0100
56b8fcc
56b8fcc
    x86: Automate generation of PREFERRED_FEATURE_INDEX_1 bitfield
56b8fcc
    
56b8fcc
    Use a .def file to define the bitfield layout, so that it is possible
56b8fcc
    to iterate over field members using the preprocessor.
56b8fcc
    
56b8fcc
    (cherry picked from commit e4933c8a92ea08eecdf3ab45e7f76c95dc3d20ac)
56b8fcc
56b8fcc
diff --git a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
56b8fcc
new file mode 100644
56b8fcc
index 0000000000000000..06af1a8dd5c6c2b4
56b8fcc
--- /dev/null
56b8fcc
+++ b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def
56b8fcc
@@ -0,0 +1,34 @@
56b8fcc
+/* Bits in the PREFERRED_FEATURE_INDEX_1 bitfield of <cpu-features.h>.
56b8fcc
+   Copyright (C) 2020-2021 Free Software Foundation, Inc.
56b8fcc
+   This file is part of the GNU C Library.
56b8fcc
+
56b8fcc
+   The GNU C Library is free software; you can redistribute it and/or
56b8fcc
+   modify it under the terms of the GNU Lesser General Public
56b8fcc
+   License as published by the Free Software Foundation; either
56b8fcc
+   version 2.1 of the License, or (at your option) any later version.
56b8fcc
+
56b8fcc
+   The GNU C Library is distributed in the hope that it will be useful,
56b8fcc
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
56b8fcc
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
56b8fcc
+   Lesser General Public License for more details.
56b8fcc
+
56b8fcc
+   You should have received a copy of the GNU Lesser General Public
56b8fcc
+   License along with the GNU C Library; if not, see
56b8fcc
+   <https://www.gnu.org/licenses/>.  */
56b8fcc
+
56b8fcc
+BIT (Fast_Rep_String)
56b8fcc
+BIT (Fast_Copy_Backward)
56b8fcc
+BIT (Slow_BSF)
56b8fcc
+BIT (Fast_Unaligned_Load)
56b8fcc
+BIT (Prefer_PMINUB_for_stringop)
56b8fcc
+BIT (Fast_Unaligned_Copy)
56b8fcc
+BIT (I586)
56b8fcc
+BIT (I686)
56b8fcc
+BIT (Slow_SSE4_2)
56b8fcc
+BIT (AVX_Fast_Unaligned_Load)
56b8fcc
+BIT (Prefer_MAP_32BIT_EXEC)
56b8fcc
+BIT (Prefer_No_VZEROUPPER)
56b8fcc
+BIT (Prefer_ERMS)
56b8fcc
+BIT (Prefer_No_AVX512)
56b8fcc
+BIT (MathVec_Prefer_No_AVX512)
56b8fcc
+BIT (Prefer_FSRM)
56b8fcc
diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h
56b8fcc
index 624736b40ebb2cd6..e7f314657c8162da 100644
56b8fcc
--- a/sysdeps/x86/include/cpu-features.h
56b8fcc
+++ b/sysdeps/x86/include/cpu-features.h
56b8fcc
@@ -757,40 +757,23 @@ enum
56b8fcc
 #define reg_AESKLE		ebx
56b8fcc
 #define reg_WIDE_KL		ebx
56b8fcc
 
56b8fcc
-/* PREFERRED_FEATURE_INDEX_1.  */
56b8fcc
-#define bit_arch_I586				(1u << 0)
56b8fcc
-#define bit_arch_I686				(1u << 1)
56b8fcc
-#define bit_arch_Fast_Rep_String		(1u << 2)
56b8fcc
-#define bit_arch_Fast_Copy_Backward		(1u << 3)
56b8fcc
-#define bit_arch_Fast_Unaligned_Load		(1u << 4)
56b8fcc
-#define bit_arch_Fast_Unaligned_Copy		(1u << 5)
56b8fcc
-#define bit_arch_Slow_BSF			(1u << 6)
56b8fcc
-#define bit_arch_Slow_SSE4_2			(1u << 7)
56b8fcc
-#define bit_arch_AVX_Fast_Unaligned_Load	(1u << 8)
56b8fcc
-#define bit_arch_Prefer_MAP_32BIT_EXEC		(1u << 9)
56b8fcc
-#define bit_arch_Prefer_PMINUB_for_stringop	(1u << 10)
56b8fcc
-#define bit_arch_Prefer_No_VZEROUPPER		(1u << 11)
56b8fcc
-#define bit_arch_Prefer_ERMS			(1u << 12)
56b8fcc
-#define bit_arch_Prefer_FSRM			(1u << 13)
56b8fcc
-#define bit_arch_Prefer_No_AVX512		(1u << 14)
56b8fcc
-#define bit_arch_MathVec_Prefer_No_AVX512	(1u << 15)
56b8fcc
-
56b8fcc
-#define index_arch_Fast_Rep_String		PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Fast_Copy_Backward		PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Slow_BSF			PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Fast_Unaligned_Load		PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Prefer_PMINUB_for_stringop 	PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Fast_Unaligned_Copy		PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_I586				PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_I686				PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Slow_SSE4_2			PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_AVX_Fast_Unaligned_Load	PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Prefer_MAP_32BIT_EXEC	PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Prefer_No_VZEROUPPER		PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Prefer_ERMS			PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Prefer_No_AVX512		PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_MathVec_Prefer_No_AVX512	PREFERRED_FEATURE_INDEX_1
56b8fcc
-#define index_arch_Prefer_FSRM			PREFERRED_FEATURE_INDEX_1
56b8fcc
+/* PREFERRED_FEATURE_INDEX_1.  First define the bitindex values
56b8fcc
+   sequentially, then define the bit_arch* and index_arch_* lookup
56b8fcc
+   constants.  */
56b8fcc
+enum
56b8fcc
+  {
56b8fcc
+#define BIT(x) _bitindex_arch_##x ,
56b8fcc
+#include "cpu-features-preferred_feature_index_1.def"
56b8fcc
+#undef BIT
56b8fcc
+  };
56b8fcc
+enum
56b8fcc
+  {
56b8fcc
+#define BIT(x)					\
56b8fcc
+    bit_arch_##x = 1u << _bitindex_arch_##x ,	\
56b8fcc
+    index_arch_##x = PREFERRED_FEATURE_INDEX_1,
56b8fcc
+#include "cpu-features-preferred_feature_index_1.def"
56b8fcc
+#undef BIT
56b8fcc
+  };
56b8fcc
 
56b8fcc
 /* XCR0 Feature flags.  */
56b8fcc
 #define bit_XMM_state		(1u << 1)