mirror of
				https://github.com/google/cpu_features.git
				synced 2025-10-30 20:52:17 +01:00 
			
		
		
		
	[NFC] Change implementation of FillX86BrandString (#181)
This commit is contained in:
		 Guillaume Chatelet
					Guillaume Chatelet
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							32b49eb5e7
						
					
				
				
					commit
					cf589a2844
				
			| @@ -1690,21 +1690,20 @@ X86Microarchitecture GetX86Microarchitecture(const X86Info* info) { | |||||||
|   return X86_UNKNOWN; |   return X86_UNKNOWN; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void SetString(const uint32_t max_cpuid_ext_leaf, const uint32_t leaf_id, |  | ||||||
|                       char* buffer) { |  | ||||||
|   const Leaf leaf = SafeCpuId(max_cpuid_ext_leaf, leaf_id); |  | ||||||
|   // We allow calling memcpy from SetString which is only called when requesting |  | ||||||
|   // X86BrandString. |  | ||||||
|   memcpy(buffer, &leaf, sizeof(Leaf)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void FillX86BrandString(char brand_string[49]) { | void FillX86BrandString(char brand_string[49]) { | ||||||
|   const Leaf leaf_ext_0 = CpuId(0x80000000); |   const Leaf leaf_ext_0 = CpuId(0x80000000); | ||||||
|   const uint32_t max_cpuid_leaf_ext = leaf_ext_0.eax; |   const uint32_t max_cpuid_leaf_ext = leaf_ext_0.eax; | ||||||
|   SetString(max_cpuid_leaf_ext, 0x80000002, brand_string); |   const Leaf leaves[3] = { | ||||||
|   SetString(max_cpuid_leaf_ext, 0x80000003, brand_string + 16); |       SafeCpuId(max_cpuid_leaf_ext, 0x80000002), | ||||||
|   SetString(max_cpuid_leaf_ext, 0x80000004, brand_string + 32); |       SafeCpuId(max_cpuid_leaf_ext, 0x80000003), | ||||||
|   brand_string[48] = '\0'; |       SafeCpuId(max_cpuid_leaf_ext, 0x80000004), | ||||||
|  |   }; | ||||||
|  |   const size_t leaves_size = sizeof(leaves); | ||||||
|  | #if __STDC_VERSION__ >= 201112L | ||||||
|  |   _Static_assert(leaves_size == 48, "Leaves must be packed"); | ||||||
|  | #endif | ||||||
|  |   CpuFeatures_StringView_CopyString(view((const char*)leaves, leaves_size), | ||||||
|  |                                     brand_string, 49); | ||||||
| } | } | ||||||
|  |  | ||||||
| //////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user