2 * Copyright (C) 2009 David McPaul
4 * includes code from sysinfo.c which is
5 * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
6 * Copyright (c) 2002, Carlos Hasan, for Haiku.
8 * All rights reserved. Distributed under the terms of the MIT License.
12 #include "CpuCapabilities.h"
18 CPUCapabilities::~CPUCapabilities()
23 CPUCapabilities::CPUCapabilities()
26 #if defined(__INTEL__) || defined(__x86_64__)
27 _SetIntelCapabilities();
32 #if defined(__INTEL__) || defined(__x86_64__)
34 CPUCapabilities::_SetIntelCapabilities()
38 int32 maxStandardFunction
, maxExtendedFunction
= 0;
40 if (get_cpuid(&baseInfo
, 0L, 0L) != B_OK
) {
41 // this CPU doesn't support cpuid
45 maxStandardFunction
= baseInfo
.eax_0
.max_eax
;
46 if (maxStandardFunction
>= 500) {
47 maxStandardFunction
= 0; /* old Pentium sample chips has cpu signature here */
52 get_cpuid(&cpuInfo
, 0x80000000, 0L);
54 // extended cpuid is only supported if max_eax is greater than the service id
55 if (cpuInfo
.eax_0
.max_eax
> 0x80000000) {
56 maxExtendedFunction
= cpuInfo
.eax_0
.max_eax
& 0xff;
59 if (maxStandardFunction
> 0) {
61 get_cpuid(&cpuInfo
, 1L, 0L);
62 if (cpuInfo
.eax_1
.features
& (1UL << 23)) {
63 fCapabilities
= CAPABILITY_MMX
;
66 if (cpuInfo
.eax_1
.features
& (1UL << 25)) {
67 fCapabilities
= CAPABILITY_SSE1
;
70 if (cpuInfo
.eax_1
.features
& (1UL << 26)) {
71 fCapabilities
= CAPABILITY_SSE2
;
74 if (maxStandardFunction
>= 1) {
75 /* Extended features */
76 if (cpuInfo
.eax_1
.extended_features
& (1UL << 0)) {
77 fCapabilities
= CAPABILITY_SSE3
;
79 if (cpuInfo
.eax_1
.extended_features
& (1UL << 9)) {
80 fCapabilities
= CAPABILITY_SSSE3
;
82 if (cpuInfo
.eax_1
.extended_features
& (1UL << 19)) {
83 fCapabilities
= CAPABILITY_SSE41
;
85 if (cpuInfo
.eax_1
.extended_features
& (1UL << 20)) {
86 fCapabilities
= CAPABILITY_SSE42
;
91 #endif // __INTEL__ || __x86_64__
95 CPUCapabilities::HasMMX()
97 return fCapabilities
>= CAPABILITY_MMX
;
102 CPUCapabilities::HasSSE1()
104 return fCapabilities
>= CAPABILITY_SSE1
;
109 CPUCapabilities::HasSSE2()
111 return fCapabilities
>= CAPABILITY_SSE2
;
116 CPUCapabilities::HasSSE3()
118 return fCapabilities
>= CAPABILITY_SSE3
;
123 CPUCapabilities::HasSSSE3()
125 return fCapabilities
>= CAPABILITY_SSSE3
;
130 CPUCapabilities::HasSSE41()
132 return fCapabilities
>= CAPABILITY_SSE41
;
137 CPUCapabilities::HasSSE42()
139 return fCapabilities
>= CAPABILITY_SSE42
;
144 CPUCapabilities::PrintCapabilities()
146 static const char *CapArray
[8] = {
147 "", "MMX", "SSE1", "SSE2", "SSE3", "SSSE3", "SSE4.1", "SSE4.2"
150 printf("CPU is capable of running ");
151 if (fCapabilities
> 0) {
152 for (uint32 i
= 1; i
<= fCapabilities
; i
++)
153 printf("%s ",CapArray
[i
]);
155 printf("no extensions");