| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2013 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | #include <fstream>
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2015-12-22 18:20:48 -06:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-13 07:29:19 -05:00
										 |  |  | #include <asm/hwcap.h>
 | 
					
						
							|  |  |  | #include <sys/auxv.h>
 | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:06:58 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "Common/CPUDetect.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-20 04:11:52 +01:00
										 |  |  | #include "Common/StringUtil.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | const char procfile[] = "/proc/cpuinfo"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-22 17:45:42 -04:00
										 |  |  | static std::string GetCPUString() | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | 	const std::string marker = "Hardware\t: "; | 
					
						
							|  |  |  | 	std::string cpu_string = "Unknown"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::string line; | 
					
						
							|  |  |  | 	std::ifstream file(procfile); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!file) | 
					
						
							|  |  |  | 		return cpu_string; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | 	while (std::getline(file, line)) | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | 		if (line.find(marker) != std::string::npos) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			cpu_string = line.substr(marker.length()); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return cpu_string; | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-16 01:22:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | CPUInfo cpu_info; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-02 19:27:50 -04:00
										 |  |  | CPUInfo::CPUInfo() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 	Detect(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:17:29 -05:00
										 |  |  | // Detects the various CPU features
 | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | void CPUInfo::Detect() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Set some defaults here
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:17:29 -05:00
										 |  |  | 	// When ARMv8 CPUs come out, these need to be updated.
 | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 	HTT = false; | 
					
						
							| 
									
										
										
										
											2014-06-01 23:49:23 -05:00
										 |  |  | 	OS64bit = true; | 
					
						
							|  |  |  | 	CPU64bit = true; | 
					
						
							|  |  |  | 	Mode64bit = true; | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 	vendor = VENDOR_ARM; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Get the information about the CPU
 | 
					
						
							| 
									
										
										
										
											2015-06-13 07:29:19 -05:00
										 |  |  | 	num_cores = sysconf(_SC_NPROCESSORS_CONF); | 
					
						
							| 
									
										
										
										
											2014-06-01 23:49:23 -05:00
										 |  |  | 	strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string)); | 
					
						
							| 
									
										
										
										
											2015-06-13 07:29:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	unsigned long hwcaps = getauxval(AT_HWCAP); | 
					
						
							|  |  |  | 	bFP = hwcaps & HWCAP_FP; | 
					
						
							|  |  |  | 	bASIMD = hwcaps & HWCAP_ASIMD; | 
					
						
							|  |  |  | 	bAES = hwcaps & HWCAP_AES; | 
					
						
							|  |  |  | 	bCRC32 = hwcaps & HWCAP_CRC32; | 
					
						
							|  |  |  | 	bSHA1 = hwcaps & HWCAP_SHA1; | 
					
						
							|  |  |  | 	bSHA2 = hwcaps & HWCAP_SHA2; | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:17:29 -05:00
										 |  |  | // Turn the CPU info into a string we can show
 | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | std::string CPUInfo::Summarize() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	std::string sum; | 
					
						
							|  |  |  | 	if (num_cores == 1) | 
					
						
							|  |  |  | 		sum = StringFromFormat("%s, %i core", cpu_string, num_cores); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		sum = StringFromFormat("%s, %i cores", cpu_string, num_cores); | 
					
						
							| 
									
										
										
										
											2015-06-13 07:29:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (bAES) sum += ", AES"; | 
					
						
							|  |  |  | 	if (bCRC32) sum += ", CRC32"; | 
					
						
							|  |  |  | 	if (bSHA1) sum += ", SHA1"; | 
					
						
							|  |  |  | 	if (bSHA2) sum += ", SHA2"; | 
					
						
							| 
									
										
										
										
											2014-06-01 23:49:23 -05:00
										 |  |  | 	if (CPU64bit) sum += ", 64-bit"; | 
					
						
							| 
									
										
										
										
											2013-02-26 13:49:00 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return sum; | 
					
						
							|  |  |  | } |