vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / plugins / ffmpeg / CpuCapabilities.cpp
blobde2baf4e65e012d8c7724095ce83241d32905560
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 */
12 #include "CpuCapabilities.h"
14 #include <string.h>
15 #include <cpu_type.h>
18 CPUCapabilities::~CPUCapabilities()
23 CPUCapabilities::CPUCapabilities()
24 : fCapabilities(0)
26 #if defined(__INTEL__) || defined(__x86_64__)
27 _SetIntelCapabilities();
28 #endif
32 #if defined(__INTEL__) || defined(__x86_64__)
33 void
34 CPUCapabilities::_SetIntelCapabilities()
36 cpuid_info baseInfo;
37 cpuid_info cpuInfo;
38 int32 maxStandardFunction, maxExtendedFunction = 0;
40 if (get_cpuid(&baseInfo, 0L, 0L) != B_OK) {
41 // this CPU doesn't support cpuid
42 return;
45 maxStandardFunction = baseInfo.eax_0.max_eax;
46 if (maxStandardFunction >= 500) {
47 maxStandardFunction = 0; /* old Pentium sample chips has cpu signature here */
50 /* Extended cpuid */
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__
94 bool
95 CPUCapabilities::HasMMX()
97 return fCapabilities >= CAPABILITY_MMX;
101 bool
102 CPUCapabilities::HasSSE1()
104 return fCapabilities >= CAPABILITY_SSE1;
108 bool
109 CPUCapabilities::HasSSE2()
111 return fCapabilities >= CAPABILITY_SSE2;
115 bool
116 CPUCapabilities::HasSSE3()
118 return fCapabilities >= CAPABILITY_SSE3;
122 bool
123 CPUCapabilities::HasSSSE3()
125 return fCapabilities >= CAPABILITY_SSSE3;
129 bool
130 CPUCapabilities::HasSSE41()
132 return fCapabilities >= CAPABILITY_SSE41;
136 bool
137 CPUCapabilities::HasSSE42()
139 return fCapabilities >= CAPABILITY_SSE42;
143 void
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]);
154 } else {
155 printf("no extensions");
157 printf("\n");