blob: bd87d2e3cb0ce20eb83b8d11a09e570b58840c6f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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#if !defined(DISABLE_YUV)
31#include "libyuv/cpu_id.h"
32#endif
33
34namespace cricket {
35
36bool CpuInfo::TestCpuFlag(int flag) {
37#if !defined(DISABLE_YUV)
38 return libyuv::TestCpuFlag(flag) ? true : false;
39#else
40 return false;
41#endif
42}
43
44void CpuInfo::MaskCpuFlagsForTest(int enable_flags) {
45#if !defined(DISABLE_YUV)
46 libyuv::MaskCpuFlags(enable_flags);
47#endif
48}
49
50// Detect an Intel Core I5 or better such as 4th generation Macbook Air.
51bool IsCoreIOrBetter() {
52#if !defined(DISABLE_YUV) && (defined(__i386__) || defined(__x86_64__) || \
53 defined(_M_IX86) || defined(_M_X64))
wu@webrtc.org97077a32013-10-25 21:18:33 +000054 uint32 cpu_info[4];
55 libyuv::CpuId(0, 0, &cpu_info[0]); // Function 0: Vendor ID
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056 if (cpu_info[1] == 0x756e6547 && cpu_info[3] == 0x49656e69 &&
57 cpu_info[2] == 0x6c65746e) { // GenuineIntel
58 // Detect CPU Family and Model
59 // 3:0 - Stepping
60 // 7:4 - Model
61 // 11:8 - Family
62 // 13:12 - Processor Type
63 // 19:16 - Extended Model
64 // 27:20 - Extended Family
wu@webrtc.org97077a32013-10-25 21:18:33 +000065 libyuv::CpuId(1, 0, &cpu_info[0]); // Function 1: Family and Model
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
67 int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
68 // CpuFamily | CpuModel | Name
69 // 6 | 14 | Yonah -- Core
70 // 6 | 15 | Merom -- Core 2
71 // 6 | 23 | Penryn -- Core 2 (most common)
72 // 6 | 26 | Nehalem -- Core i*
73 // 6 | 28 | Atom
74 // 6 | 30 | Lynnfield -- Core i*
75 // 6 | 37 | Westmere -- Core i*
76 const int kAtom = 28;
77 const int kCore2 = 23;
78 if (family < 6 || family == 15 ||
79 (family == 6 && (model == kAtom || model <= kCore2))) {
80 return false;
81 }
82 return true;
83 }
84#endif
85 return false;
86}
87
88} // namespace cricket