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.
14 #include "CpuCapabilities.h"
16 CPUCapabilities::~CPUCapabilities()
20 CPUCapabilities::CPUCapabilities()
23 setIntelCapabilities();
30 CPUCapabilities::setIntelCapabilities()
34 int32 maxStandardFunction
, maxExtendedFunction
= 0;
36 if (get_cpuid(&baseInfo
, 0L, 0L) != B_OK
) {
37 // this CPU doesn't support cpuid
41 maxStandardFunction
= baseInfo
.eax_0
.max_eax
;
42 if (maxStandardFunction
>= 500) {
43 maxStandardFunction
= 0; /* old Pentium sample chips has cpu signature here */
48 get_cpuid(&cpuInfo
, 0x80000000, 0L);
50 // extended cpuid is only supported if max_eax is greater than the service id
51 if (cpuInfo
.eax_0
.max_eax
> 0x80000000) {
52 maxExtendedFunction
= cpuInfo
.eax_0
.max_eax
& 0xff;
55 if (maxStandardFunction
> 0) {
57 get_cpuid(&cpuInfo
, 1L, 0L);
58 if (cpuInfo
.eax_1
.features
& (1UL << 23)) {
59 capabilities
= CAPABILITY_MMX
;
62 if (cpuInfo
.eax_1
.features
& (1UL << 25)) {
63 capabilities
= CAPABILITY_SSE1
;
66 if (cpuInfo
.eax_1
.features
& (1UL << 26)) {
67 capabilities
= CAPABILITY_SSE2
;
70 if (maxStandardFunction
>= 1) {
71 /* Extended features */
72 if (cpuInfo
.eax_1
.extended_features
& (1UL << 0)) {
73 capabilities
= CAPABILITY_SSE3
;
75 if (cpuInfo
.eax_1
.extended_features
& (1UL << 9)) {
76 capabilities
= CAPABILITY_SSSE3
;
78 if (cpuInfo
.eax_1
.extended_features
& (1UL << 19)) {
79 capabilities
= CAPABILITY_SSE41
;
81 if (cpuInfo
.eax_1
.extended_features
& (1UL << 20)) {
82 capabilities
= CAPABILITY_SSE42
;
89 CPUCapabilities::HasMMX()
91 return capabilities
>= CAPABILITY_MMX
;
95 CPUCapabilities::HasSSE1()
97 return capabilities
>= CAPABILITY_SSE1
;
101 CPUCapabilities::HasSSE2()
103 return capabilities
>= CAPABILITY_SSE2
;
107 CPUCapabilities::HasSSE3()
109 return capabilities
>= CAPABILITY_SSE3
;
113 CPUCapabilities::HasSSSE3()
115 return capabilities
>= CAPABILITY_SSSE3
;
119 CPUCapabilities::HasSSE41()
121 return capabilities
>= CAPABILITY_SSE41
;
125 CPUCapabilities::HasSSE42()
127 return capabilities
>= CAPABILITY_SSE42
;
131 CPUCapabilities::PrintCapabilities()
133 static const char *CapArray
[8] = {
134 "", "MMX", "SSE1", "SSE2", "SSE3", "SSSE3", "SSE4.1", "SSE4.2"
137 printf("CPU is capable of running ");
139 for (uint32 i
=1;i
<=capabilities
;i
++) {
140 printf("%s ",CapArray
[i
]);
143 printf("no extensions");