misc: Use the new bufval helpers in RegClass and Packet.

Those makes generally useful mechanisms are now available to any code
that wants to use it, and are covered by a unit test.

Change-Id: If918eba3b81443019c5789ab132de45c65f93072
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/57150
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2022-02-25 05:01:09 -08:00
parent 9df4159456
commit 001e17890c
2 changed files with 16 additions and 63 deletions

View File

@@ -43,6 +43,8 @@
#include <sstream>
#include "base/cprintf.hh"
#include "sim/bufval.hh"
#include "sim/byteswap.hh"
namespace gem5
{
@@ -58,42 +60,15 @@ RegClassOps::valString(const void *val, size_t size) const
{
// If this is just a RegVal, or could be interpreted as one, print it
// that way.
if (size == sizeof(uint64_t))
return csprintf("0x%016x", *(const uint64_t *)val);
else if (size == sizeof(uint32_t))
return csprintf("0x%08x", *(const uint32_t *)val);
else if (size == sizeof(uint16_t))
return csprintf("0x%04x", *(const uint16_t *)val);
else if (size == sizeof(uint8_t))
return csprintf("0x%02x", *(const uint8_t *)val);
auto [reg_val_str, reg_val_success] = printUintX(val, size, HostByteOrder);
if (reg_val_success)
return reg_val_str;
// Otherwise, print it as a sequence of bytes, 4 in a chunk, separated by
// spaces, and all surrounded by []s.
// Otherwise, print it as a sequence of bytes. Use big endian order so
// that the most significant bytes are printed first, like digits in a
// regular number.
std::stringstream out;
ccprintf(out, "[");
constexpr size_t chunk_size = 4;
const uint8_t *bytes = (const uint8_t *)val;
while (size >= chunk_size) {
size -= chunk_size;
if (size) {
ccprintf(out, "%02x%02x%02x%02x ", bytes[0], bytes[1], bytes[2],
bytes[3]);
} else {
ccprintf(out, "%02x%02x%02x%02x", bytes[0], bytes[1], bytes[2],
bytes[3]);
}
bytes += chunk_size;
}
while (size--)
ccprintf(out, "%02x", *bytes++);
ccprintf(out, "]");
return out.str();
return printByteBuf(val, size, ByteOrder::big);
}
const char *RegId::regClassStrings[] = {