History

Initial Commit

Ethan Hugg committed 12 years ago

Commit 70e5e621 parent bd509b2308 files · +97095 −-5Browse files

Showing the changes to codec/decoder/core/src/cpu.cpp (1 of 308 files). Show all

Unified · Split

codec/decoder/core/src/cpu.cpp+211−0
@@ -0,0 +1,211 @@
1+/*!
2+ * \copy
3+ * Copyright (c) 2009-2013, Cisco Systems
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * * Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ *
13+ * * Redistributions in binary form must reproduce the above copyright
14+ * notice, this list of conditions and the following disclaimer in
15+ * the documentation and/or other materials provided with the
16+ * distribution.
17+ *
18+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ *
32+ * \file cpu.cpp
33+ *
34+ * \brief CPU compatibility detection
35+ *
36+ * \date 04/29/2009 Created
37+ *
38+ *************************************************************************************
39+ */
40+#include <string.h>
41+
42+#include "cpu.h"
43+#include "cpu_core.h"
44+
45+namespace WelsDec {
46+
47+#define CPU_Vender_AMD "AuthenticAMD"
48+#define CPU_Vender_INTEL "GenuineIntel"
49+#define CPU_Vender_CYRIX "CyrixInstead"
50+
51+#if defined(X86_ASM)
52+
53+uint32_t WelsCPUFeatureDetect( int32_t *pNumberOfLogicProcessors )
54+{
55+ uint32_t uiCPU = 0;
56+ uint32_t uiFeatureA = 0, uiFeatureB = 0, uiFeatureC = 0, uiFeatureD = 0;
57+ int32_t CacheLineSize = 0;
58+ int8_t chVenderName[16] = { 0 };
59+
60+ if( !WelsCPUIdVerify() )
61+ {
62+ /* cpuid is not supported in cpu */
63+ return 0;
64+ }
65+
66+ WelsCPUId( 0, &uiFeatureA, (uint32_t*)&chVenderName[0],(uint32_t*)&chVenderName[8],(uint32_t*)&chVenderName[4] );
67+ if( uiFeatureA == 0 )
68+ {
69+ /* maximum input value for basic cpuid information */
70+ return 0;
71+ }
72+
73+ WelsCPUId( 1, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD );
74+ if( (uiFeatureD & 0x00800000) == 0 )
75+ {
76+ /* Basic MMX technology is not support in cpu, mean nothing for us so return here */
77+ return 0;
78+ }
79+
80+ uiCPU = WELS_CPU_MMX;
81+ if( uiFeatureD & 0x02000000 )
82+ {
83+ /* SSE technology is identical to AMD MMX extensions */
84+ uiCPU |= WELS_CPU_MMXEXT|WELS_CPU_SSE;
85+ }
86+ if( uiFeatureD & 0x04000000 )
87+ {
88+ /* SSE2 support here */
89+ uiCPU |= WELS_CPU_SSE2;
90+ }
91+ if ( uiFeatureD & 0x00000001 )
92+ {
93+ /* x87 FPU on-chip checking */
94+ uiCPU |= WELS_CPU_FPU;
95+ }
96+ if ( uiFeatureD & 0x00008000 )
97+ {
98+ /* CMOV instruction checking */
99+ uiCPU |= WELS_CPU_CMOV;
100+ }
101+ if ( !strcmp((const str_t*)chVenderName,CPU_Vender_INTEL) ) // confirmed_safe_unsafe_usage
102+ {
103+ if ( uiFeatureD & 0x10000000 )
104+ {
105+ /* Multi-Threading checking: contains of multiple logic processors */
106+ uiCPU |= WELS_CPU_HTT;
107+ }
108+ }
109+
110+ if( uiFeatureC & 0x00000001 ){
111+ /* SSE3 support here */
112+ uiCPU |= WELS_CPU_SSE3;
113+ }
114+ if( uiFeatureC & 0x00000200 ){
115+ /* SSSE3 support here */
116+ uiCPU |= WELS_CPU_SSSE3;
117+ }
118+ if( uiFeatureC & 0x00080000 ){
119+ /* SSE4.1 support here, 45nm Penryn processor */
120+ uiCPU |= WELS_CPU_SSE41;
121+ }
122+ if( uiFeatureC & 0x00100000 ){
123+ /* SSE4.2 support here, next generation Nehalem processor */
124+ uiCPU |= WELS_CPU_SSE42;
125+ }
126+ if ( WelsCPUSupportAVX( uiFeatureA, uiFeatureC ) )
127+ {
128+ /* AVX supported */
129+ uiCPU |= WELS_CPU_AVX;
130+ }
131+ if ( WelsCPUSupportFMA( uiFeatureA, uiFeatureC ) )
132+ {
133+ /* AVX FMA supported */
134+ uiCPU |= WELS_CPU_FMA;
135+ }
136+ if ( uiFeatureC & 0x02000000 )
137+ {
138+ /* AES checking */
139+ uiCPU |= WELS_CPU_AES;
140+ }
141+ if ( uiFeatureC & 0x00400000 )
142+ {
143+ /* MOVBE checking */
144+ uiCPU |= WELS_CPU_MOVBE;
145+ }
146+
147+ if ( pNumberOfLogicProcessors != NULL )
148+ {
149+ // HTT enabled on chip
150+ *pNumberOfLogicProcessors = (uiFeatureB & 0x00ff0000) >> 16; // feature bits: 23-16 on returned EBX
151+ }
152+
153+ WelsCPUId( 0x80000000, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD );
154+
155+ if( (!strcmp((const str_t*)chVenderName,CPU_Vender_AMD)) && (uiFeatureA>=0x80000001) ){ // confirmed_safe_unsafe_usage
156+ WelsCPUId(0x80000001, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD );
157+ if( uiFeatureD&0x00400000 ){
158+ uiCPU |= WELS_CPU_MMXEXT;
159+ }
160+ if( uiFeatureD&0x80000000 ){
161+ uiCPU |= WELS_CPU_3DNOW;
162+ }
163+ }
164+
165+ if( !strcmp((const str_t*)chVenderName,CPU_Vender_INTEL) ){ // confirmed_safe_unsafe_usage
166+ int32_t family, model;
167+
168+ WelsCPUId(1, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
169+ family = ((uiFeatureA>>8)&0xf) + ((uiFeatureA>>20)&0xff);
170+ model = ((uiFeatureA>>4)&0xf) + ((uiFeatureA>>12)&0xf0);
171+
172+ if( (family==6) && (model==9 || model==13 || model==14) ){
173+ uiCPU &= ~(WELS_CPU_SSE2|WELS_CPU_SSE3);
174+ }
175+ }
176+
177+ // get cache line size
178+ if( (!strcmp((const str_t*)chVenderName,CPU_Vender_INTEL)) || !(strcmp((const str_t*)chVenderName,CPU_Vender_CYRIX)) ){ // confirmed_safe_unsafe_usage
179+ WelsCPUId(1, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
180+
181+ CacheLineSize = (uiFeatureB&0xff00)>>5; // ((clflush_line_size >> 8) << 3), CLFLUSH_line_size * 8 = CacheLineSize_in_byte
182+
183+ if( CacheLineSize == 128 ){
184+ uiCPU |= WELS_CPU_CACHELINE_128;
185+ }
186+ else if( CacheLineSize == 64 ){
187+ uiCPU |= WELS_CPU_CACHELINE_64;
188+ }
189+ else if( CacheLineSize == 32 ){
190+ uiCPU |= WELS_CPU_CACHELINE_32;
191+ }
192+ else if( CacheLineSize == 16 ){
193+ uiCPU |= WELS_CPU_CACHELINE_16;
194+ }
195+ }
196+
197+ return uiCPU;
198+}
199+
200+
201+void WelsCPURestore( const uint32_t kuiCPU )
202+{
203+ if( kuiCPU & (WELS_CPU_MMX|WELS_CPU_MMXEXT|WELS_CPU_3DNOW|WELS_CPU_3DNOWEXT) )
204+ {
205+ WelsEmms();
206+ }
207+}
208+
209+#endif
210+
211+} // namespace WelsDec

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t