1 /*
2 * libjingle
3 * Copyright 2011 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "talk/media/base/cpuid.h"
29
30 #include "libyuv/cpu_id.h"
31
32 namespace cricket {
33
TestCpuFlag(int flag)34 bool CpuInfo::TestCpuFlag(int flag) {
35 return libyuv::TestCpuFlag(flag) ? true : false;
36 }
37
MaskCpuFlagsForTest(int enable_flags)38 void CpuInfo::MaskCpuFlagsForTest(int enable_flags) {
39 libyuv::MaskCpuFlags(enable_flags);
40 }
41
42 // Detect an Intel Core I5 or better such as 4th generation Macbook Air.
IsCoreIOrBetter()43 bool IsCoreIOrBetter() {
44 #if defined(__i386__) || defined(__x86_64__) || \
45 defined(_M_IX86) || defined(_M_X64)
46 uint32_t cpu_info[4];
47 libyuv::CpuId(0, 0, &cpu_info[0]); // Function 0: Vendor ID
48 if (cpu_info[1] == 0x756e6547 && cpu_info[3] == 0x49656e69 &&
49 cpu_info[2] == 0x6c65746e) { // GenuineIntel
50 // Detect CPU Family and Model
51 // 3:0 - Stepping
52 // 7:4 - Model
53 // 11:8 - Family
54 // 13:12 - Processor Type
55 // 19:16 - Extended Model
56 // 27:20 - Extended Family
57 libyuv::CpuId(1, 0, &cpu_info[0]); // Function 1: Family and Model
58 int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
59 int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
60 // CpuFamily | CpuModel | Name
61 // 6 | 14 | Yonah -- Core
62 // 6 | 15 | Merom -- Core 2
63 // 6 | 23 | Penryn -- Core 2 (most common)
64 // 6 | 26 | Nehalem -- Core i*
65 // 6 | 28 | Atom
66 // 6 | 30 | Lynnfield -- Core i*
67 // 6 | 37 | Westmere -- Core i*
68 const int kAtom = 28;
69 const int kCore2 = 23;
70 if (family < 6 || family == 15 ||
71 (family == 6 && (model == kAtom || model <= kCore2))) {
72 return false;
73 }
74 return true;
75 }
76 #endif
77 return false;
78 }
79
80 } // namespace cricket
81