CPUID.hpp revision 19bac1e08be200c31efd26f0f5fd144c9b3eefd3
1// SwiftShader Software Renderer 2// 3// Copyright(c) 2005-2011 TransGaming Inc. 4// 5// All rights reserved. No part of this software may be copied, distributed, transmitted, 6// transcribed, stored in a retrieval system, translated into any human or computer 7// language by any means, or disclosed to third parties without the explicit written 8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express 9// or implied, including but not limited to any patent rights, are granted to you. 10// 11 12#ifndef sw_CPUID_hpp 13#define sw_CPUID_hpp 14 15namespace sw 16{ 17 #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) 18 #define __x86_64__ 1 19 #endif 20 21 class CPUID 22 { 23 public: 24 static bool supportsMMX(); 25 static bool supportsCMOV(); 26 static bool supportsMMX2(); // MMX instructions added by SSE: pshufw, pmulhuw, pmovmskb, pavgw/b, pextrw, pinsrw, pmaxsw/ub, etc. 27 static bool supportsSSE(); 28 static bool supportsSSE2(); 29 static bool supportsSSE3(); 30 static bool supportsSSSE3(); 31 static bool supportsSSE4_1(); 32 static int coreCount(); 33 static int processAffinity(); 34 35 static void setEnableMMX(bool enable); 36 static void setEnableCMOV(bool enable); 37 static void setEnableSSE(bool enable); 38 static void setEnableSSE2(bool enable); 39 static void setEnableSSE3(bool enable); 40 static void setEnableSSSE3(bool enable); 41 static void setEnableSSE4_1(bool enable); 42 43 private: 44 static bool MMX; 45 static bool CMOV; 46 static bool SSE; 47 static bool SSE2; 48 static bool SSE3; 49 static bool SSSE3; 50 static bool SSE4_1; 51 static int cores; 52 static int affinity; 53 54 static bool enableMMX; 55 static bool enableCMOV; 56 static bool enableSSE; 57 static bool enableSSE2; 58 static bool enableSSE3; 59 static bool enableSSSE3; 60 static bool enableSSE4_1; 61 62 static bool detectMMX(); 63 static bool detectCMOV(); 64 static bool detectSSE(); 65 static bool detectSSE2(); 66 static bool detectSSE3(); 67 static bool detectSSSE3(); 68 static bool detectSSE4_1(); 69 static int detectCoreCount(); 70 static int detectAffinity(); 71 }; 72} 73 74namespace sw 75{ 76 inline bool CPUID::supportsMMX() 77 { 78 return MMX && enableMMX; 79 } 80 81 inline bool CPUID::supportsCMOV() 82 { 83 return CMOV && enableCMOV; 84 } 85 86 inline bool CPUID::supportsMMX2() 87 { 88 return supportsSSE(); // Coincides with 64-bit integer vector instructions supported by SSE 89 } 90 91 inline bool CPUID::supportsSSE() 92 { 93 return SSE && enableSSE; 94 } 95 96 inline bool CPUID::supportsSSE2() 97 { 98 return SSE2 && enableSSE2; 99 } 100 101 inline bool CPUID::supportsSSE3() 102 { 103 return SSE3 && enableSSE3; 104 } 105 106 inline bool CPUID::supportsSSSE3() 107 { 108 return SSSE3 && enableSSSE3; 109 } 110 111 inline bool CPUID::supportsSSE4_1() 112 { 113 return SSE4_1 && enableSSE4_1; 114 } 115 116 inline int CPUID::coreCount() 117 { 118 return cores; 119 } 120 121 inline int CPUID::processAffinity() 122 { 123 return affinity; 124 } 125} 126 127#endif // sw_CPUID_hpp 128