1 /* Initialize CPU feature data.
2 This file is part of the GNU C Library.
3 Copyright (C) 2008, 2009, 2010 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
23 #include "init-arch.h"
26 struct cpu_features __cpu_features attribute_hidden
;
30 get_common_indeces (unsigned int *family
, unsigned int *model
)
32 __cpuid (1, __cpu_features
.cpuid
[COMMON_CPUID_INDEX_1
].eax
,
33 __cpu_features
.cpuid
[COMMON_CPUID_INDEX_1
].ebx
,
34 __cpu_features
.cpuid
[COMMON_CPUID_INDEX_1
].ecx
,
35 __cpu_features
.cpuid
[COMMON_CPUID_INDEX_1
].edx
);
37 unsigned int eax
= __cpu_features
.cpuid
[COMMON_CPUID_INDEX_1
].eax
;
38 *family
= (eax
>> 8) & 0x0f;
39 *model
= (eax
>> 4) & 0x0f;
44 __init_cpu_features (void)
49 unsigned int family
= 0;
50 unsigned int model
= 0;
51 enum cpu_features_kind kind
;
53 __cpuid (0, __cpu_features
.max_cpuid
, ebx
, ecx
, edx
);
55 /* This spells out "GenuineIntel". */
56 if (ebx
== 0x756e6547 && ecx
== 0x6c65746e && edx
== 0x49656e69)
58 kind
= arch_kind_intel
;
60 get_common_indeces (&family
, &model
);
62 unsigned int eax
= __cpu_features
.cpuid
[COMMON_CPUID_INDEX_1
].eax
;
63 unsigned int extended_family
= (eax
>> 20) & 0xff;
64 unsigned int extended_model
= (eax
>> 12) & 0xf0;
67 family
+= extended_family
;
68 model
+= extended_model
;
70 else if (family
== 0x06)
72 model
+= extended_model
;
81 /* Rep string instructions are fast on Intel Core i3, i5
83 __cpu_features
.feature
[index_Fast_Rep_String
]
84 |= bit_Fast_Rep_String
;
89 /* This spells out "AuthenticAMD". */
90 else if (ebx
== 0x68747541 && ecx
== 0x444d4163 && edx
== 0x69746e65)
94 get_common_indeces (&family
, &model
);
97 kind
= arch_kind_other
;
99 __cpu_features
.family
= family
;
100 __cpu_features
.model
= model
;
101 atomic_write_barrier ();
102 __cpu_features
.kind
= kind
;
105 #undef __get_cpu_features
107 const struct cpu_features
*
108 __get_cpu_features (void)
110 if (__cpu_features
.kind
== arch_kind_unknown
)
111 __init_cpu_features ();
113 return &__cpu_features
;