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