vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / media-add-ons / video_mixer / CpuCapabilities.cpp
blob2a6d84dfddeb762f3067283712d6b36b038e09a9
1 /*
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.
9 */
11 #include <string.h>
12 #include <cpu_type.h>
14 #include "CpuCapabilities.h"
16 CPUCapabilities::~CPUCapabilities()
20 CPUCapabilities::CPUCapabilities()
22 #ifdef __INTEL__
23 setIntelCapabilities();
24 #endif
26 PrintCapabilities();
29 void
30 CPUCapabilities::setIntelCapabilities()
32 cpuid_info baseInfo;
33 cpuid_info cpuInfo;
34 int32 maxStandardFunction, maxExtendedFunction = 0;
36 if (get_cpuid(&baseInfo, 0L, 0L) != B_OK) {
37 // this CPU doesn't support cpuid
38 return;
41 maxStandardFunction = baseInfo.eax_0.max_eax;
42 if (maxStandardFunction >= 500) {
43 maxStandardFunction = 0; /* old Pentium sample chips has cpu signature here */
46 /* Extended cpuid */
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;
88 bool
89 CPUCapabilities::HasMMX()
91 return capabilities >= CAPABILITY_MMX;
94 bool
95 CPUCapabilities::HasSSE1()
97 return capabilities >= CAPABILITY_SSE1;
100 bool
101 CPUCapabilities::HasSSE2()
103 return capabilities >= CAPABILITY_SSE2;
106 bool
107 CPUCapabilities::HasSSE3()
109 return capabilities >= CAPABILITY_SSE3;
112 bool
113 CPUCapabilities::HasSSSE3()
115 return capabilities >= CAPABILITY_SSSE3;
118 bool
119 CPUCapabilities::HasSSE41()
121 return capabilities >= CAPABILITY_SSE41;
124 bool
125 CPUCapabilities::HasSSE42()
127 return capabilities >= CAPABILITY_SSE42;
130 void
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 ");
138 if (capabilities) {
139 for (uint32 i=1;i<=capabilities;i++) {
140 printf("%s ",CapArray[i]);
142 } else {
143 printf("no extensions");
145 printf("\n");