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