Optimize 32bit memset/memcpy with SSE2/SSSE3.
[glibc.git] / sysdeps / x86_64 / multiarch / init-arch.h
blob69492cb3bf25eb0847a97a0762b9d5c90608d2aa
1 /* This file is part of the GNU C Library.
2 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #define bit_Fast_Rep_String (1 << 0)
21 #ifdef __ASSEMBLER__
23 #include <ifunc-defines.h>
25 #define bit_SSE2 (1 << 26)
26 #define bit_SSSE3 (1 << 9)
27 #define bit_SSE4_2 (1 << 20)
29 #define index_SSE2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_EDX_OFFSET
30 #define index_SSSE3 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
31 #define index_SSE4_2 COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
33 #define index_Fast_Rep_String FEATURE_INDEX_1*FEATURE_SIZE
35 #else /* __ASSEMBLER__ */
37 #include <sys/param.h>
39 enum
41 COMMON_CPUID_INDEX_1 = 0,
42 /* Keep the following line at the end. */
43 COMMON_CPUID_INDEX_MAX
46 enum
48 FEATURE_INDEX_1 = 0,
49 /* Keep the following line at the end. */
50 FEATURE_INDEX_MAX
53 extern struct cpu_features
55 enum
57 arch_kind_unknown = 0,
58 arch_kind_intel,
59 arch_kind_amd,
60 arch_kind_other
61 } kind;
62 int max_cpuid;
63 struct cpuid_registers
65 unsigned int eax;
66 unsigned int ebx;
67 unsigned int ecx;
68 unsigned int edx;
69 } cpuid[COMMON_CPUID_INDEX_MAX];
70 unsigned int family;
71 unsigned int model;
72 unsigned int feature[FEATURE_INDEX_MAX];
73 } __cpu_features attribute_hidden;
76 extern void __init_cpu_features (void) attribute_hidden;
77 #define INIT_ARCH()\
78 do \
79 if (__cpu_features.kind == arch_kind_unknown) \
80 __init_cpu_features (); \
81 while (0)
83 /* Used from outside libc.so to get access to the CPU features structure. */
84 extern const struct cpu_features *__get_cpu_features (void)
85 __attribute__ ((const));
87 #ifndef NOT_IN_libc
88 # define __get_cpu_features() (&__cpu_features)
89 #endif
91 #define HAS_CPU_FEATURE(idx, reg, bit) \
92 ((__get_cpu_features ()->cpuid[idx].reg & (1 << (bit))) != 0)
94 /* Following are the feature tests used throughout libc. */
96 #define HAS_SSE2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, edx, 26)
97 #define HAS_POPCOUNT HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 23)
98 #define HAS_SSE4_2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 20)
99 #define HAS_FMA HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, 12)
101 #define index_Fast_Rep_String FEATURE_INDEX_1
103 #endif /* __ASSEMBLER__ */