15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/* 25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle 35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2011 Google Inc. 45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without 65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met: 75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * this list of conditions and the following disclaimer. 105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * this list of conditions and the following disclaimer in the documentation 125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * and/or other materials provided with the distribution. 135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 3. The name of the author may not be used to endorse or promote products 145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * derived from this software without specific prior written permission. 155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */ 275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/cpuid.h" 295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#if !defined(DISABLE_YUV) 315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "libyuv/cpu_id.h" 325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace cricket { 355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool CpuInfo::TestCpuFlag(int flag) { 375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#if !defined(DISABLE_YUV) 385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return libyuv::TestCpuFlag(flag) ? true : false; 395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#else 405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid CpuInfo::MaskCpuFlagsForTest(int enable_flags) { 455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#if !defined(DISABLE_YUV) 465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org libyuv::MaskCpuFlags(enable_flags); 475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Detect an Intel Core I5 or better such as 4th generation Macbook Air. 515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool IsCoreIOrBetter() { 525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#if !defined(DISABLE_YUV) && (defined(__i386__) || defined(__x86_64__) || \ 535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org defined(_M_IX86) || defined(_M_X64)) 54582fe818e571fa2571267f5e369715188472f352wu@webrtc.org uint32 cpu_info[4]; 55582fe818e571fa2571267f5e369715188472f352wu@webrtc.org libyuv::CpuId(0, 0, &cpu_info[0]); // Function 0: Vendor ID 565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (cpu_info[1] == 0x756e6547 && cpu_info[3] == 0x49656e69 && 575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cpu_info[2] == 0x6c65746e) { // GenuineIntel 585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Detect CPU Family and Model 595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 3:0 - Stepping 605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 7:4 - Model 615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 11:8 - Family 625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 13:12 - Processor Type 635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 19:16 - Extended Model 645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 27:20 - Extended Family 65582fe818e571fa2571267f5e369715188472f352wu@webrtc.org libyuv::CpuId(1, 0, &cpu_info[0]); // Function 1: Family and Model 665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0); 675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0); 685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // CpuFamily | CpuModel | Name 695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 14 | Yonah -- Core 705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 15 | Merom -- Core 2 715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 23 | Penryn -- Core 2 (most common) 725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 26 | Nehalem -- Core i* 735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 28 | Atom 745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 30 | Lynnfield -- Core i* 755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // 6 | 37 | Westmere -- Core i* 765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const int kAtom = 28; 775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const int kCore2 = 23; 785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (family < 6 || family == 15 || 795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org (family == 6 && (model == kAtom || model <= kCore2))) { 805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} // namespace cricket 89