cpuid/x86: avoid trailing nulls in output and storage
This commit is contained in:
parent
6473b36cf7
commit
5c14eb01e1
@ -45,7 +45,6 @@ x86::x86 ()
|
||||
memcpy (vendor_name.data () + 0, &vendor0, sizeof (vendor0));
|
||||
memcpy (vendor_name.data () + 4, &vendor1, sizeof (vendor1));
|
||||
memcpy (vendor_name.data () + 8, &vendor2, sizeof (vendor2));
|
||||
vendor_name.back () = '\0';
|
||||
|
||||
const bool is_amd = vendor0 == 0x68747541 && vendor1 == 0x69746e65 && vendor2 == 0x444d4163;
|
||||
|
||||
@ -72,7 +71,6 @@ x86::x86 ()
|
||||
memcpy (&product_name[0x00], &product0, sizeof (product0));
|
||||
memcpy (&product_name[0x10], &product1, sizeof (product1));
|
||||
memcpy (&product_name[0x20], &product2, sizeof (product2));
|
||||
product_name.back () = '\0';
|
||||
}
|
||||
|
||||
// Function 4 isn't implemented by AMD. Intel uses it for cache
|
||||
@ -93,13 +91,20 @@ x86::x86 ()
|
||||
std::ostream&
|
||||
cruft::cpu::operator<< (std::ostream &os, const x86 &val)
|
||||
{
|
||||
auto const to_string = [] (auto const &obj) {
|
||||
return cruft::view {
|
||||
obj.begin (),
|
||||
std::find (obj.begin (), obj.end (), '\0')
|
||||
};
|
||||
};
|
||||
|
||||
return os << cruft::format::printf (
|
||||
"{ name: { vendor: '%!', product: '%!' }"
|
||||
", cores: { logical: %!, physical: %!, hyper_threading: %! }"
|
||||
", simd: { sse: %!, sse2: %!, sse3: %!, ssse3: %!, sse41: %!, sse42: %! }"
|
||||
" }",
|
||||
cruft::view {val.vendor_name},
|
||||
cruft::view {val.product_name},
|
||||
to_string (val.vendor_name),
|
||||
to_string (val.product_name),
|
||||
val.cores.logical,
|
||||
val.cores.physical,
|
||||
(val.cores.hyper_threading ? "true" : "false"),
|
||||
|
@ -41,8 +41,8 @@ namespace cruft::cpu {
|
||||
bool avx;
|
||||
} simd;
|
||||
|
||||
std::array<char,12+1> vendor_name;
|
||||
std::array<char,48+1> product_name;
|
||||
std::array<char,12> vendor_name;
|
||||
std::array<char,48> product_name;
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
|
Loading…
Reference in New Issue
Block a user