Support multiarch for i686.
[glibc.git] / sysdeps / x86_64 / multiarch / init-arch.c
blobc152ab29eba45cf45102fca6b5aa5ecb8079d182
1 /* Initialize CPU feature data.
2 This file is part of the GNU C Library.
3 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@redhat.com>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <cpuid.h>
22 #include "init-arch.h"
25 struct cpu_features __cpu_features attribute_hidden;
28 static void
29 get_common_indeces (void)
31 __cpuid (1, __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax,
32 __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ebx,
33 __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx,
34 __cpu_features.cpuid[COMMON_CPUID_INDEX_1].edx);
36 unsigned int eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
37 __cpu_features.family = (eax >> 8) & 0x0f;
38 __cpu_features.model = (eax >> 4) & 0x0f;
42 void
43 __init_cpu_features (void)
45 unsigned int ebx;
46 unsigned int ecx;
47 unsigned int edx;
49 __cpuid (0, __cpu_features.max_cpuid, ebx, ecx, edx);
51 /* This spells out "GenuineIntel". */
52 if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
54 __cpu_features.kind = arch_kind_intel;
56 get_common_indeces ();
58 unsigned int eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
59 unsigned int extended_family = (eax >> 20) & 0xff;
60 unsigned int extended_model = (eax >> 12) & 0xf0;
61 if (__cpu_features.family == 0x0f)
63 __cpu_features.family += extended_family;
64 __cpu_features.model += extended_model;
66 else if (__cpu_features.family == 0x06)
68 __cpu_features.model += extended_model;
70 #ifndef ENABLE_SSSE3_ON_ATOM
71 if (__cpu_features.model == 0x1c)
72 /* Avoid SSSE3 on Atom since it is slow. */
73 __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx &= ~(1 << 9);
74 #endif
77 /* This spells out "AuthenticAMD". */
78 else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
80 __cpu_features.kind = arch_kind_amd;
82 get_common_indeces ();
84 else
85 __cpu_features.kind = arch_kind_other;
89 const struct cpu_features *
90 __get_cpu_features (void)
92 if (__cpu_features.kind == arch_kind_unknown)
93 __init_cpu_features ();
95 return &__cpu_features;