SWDEV-424956 - Fix half vector printf issue
Refactor PrintfDbg::outputArgument() to remove potential risk.
Fix half vector printf issue on all devices.
Fix FEAT-56794 as well.
Change-Id: Iae39359d2128588def2e43d77fe58e868b8e71ff
[ROCm/clr commit: 35c80dd482]
This commit is contained in:
@@ -135,17 +135,16 @@ static constexpr size_t ConstStr = 0xffffffff;
|
||||
static constexpr char Separator[] = ",\0";
|
||||
|
||||
size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t size,
|
||||
const uint32_t* argument) const {
|
||||
const void* argument) const {
|
||||
// Serialize the output to the screen
|
||||
// amd::ScopedLock k(dev().lockAsyncOps());
|
||||
|
||||
size_t copiedBytes = size;
|
||||
// Print the string argument, using standard PrintfDbg()
|
||||
if (checkString(fmt.c_str())) {
|
||||
// copiedBytes should be as number of printed chars
|
||||
copiedBytes = 0;
|
||||
//(null) should be printed
|
||||
if (*argument == 0) {
|
||||
if (*(reinterpret_cast<const unsigned char*>(argument)) == 0) {
|
||||
amd::Os::printf(fmt.data(), 0);
|
||||
// copiedBytes = strlen("(null)")
|
||||
copiedBytes = 6;
|
||||
@@ -180,11 +179,9 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
|
||||
case 2:
|
||||
case 4:
|
||||
if (printFloat) {
|
||||
uint32_t arg = *argument;
|
||||
if (size == 2) {
|
||||
auto p = reinterpret_cast<const uint16_t*>(argument);
|
||||
amd::half2float(*p, &arg);
|
||||
}
|
||||
const float fArg = size == 2 ?
|
||||
amd::half2float(*(reinterpret_cast<const uint16_t *>(argument))) :
|
||||
*(reinterpret_cast<const float *>(argument));
|
||||
static const char* fSpecifiers = "eEfgGa";
|
||||
std::string fmtF = fmt;
|
||||
size_t posS = fmtF.find_first_of("%");
|
||||
@@ -192,7 +189,6 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
|
||||
if (posS != std::string::npos && posE != std::string::npos) {
|
||||
fmtF.replace(posS + 1, posE - posS, "s");
|
||||
}
|
||||
float fArg = *(reinterpret_cast<const float*>(&arg));
|
||||
float fSign = copysign(1.0, fArg);
|
||||
if (std::isinf(fArg) && !std::isnan(fArg)) {
|
||||
if (fSign < 0) {
|
||||
@@ -223,9 +219,13 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
|
||||
hhFmt.erase(hhFmt.find_first_of("h"), 2);
|
||||
amd::Os::printf(hhFmt.data(), *(reinterpret_cast<const unsigned char*>(argument)));
|
||||
} else if (hlModifier) {
|
||||
amd::Os::printf(hlFmt.data(), *argument);
|
||||
amd::Os::printf(hlFmt.data(), size == 2 ?
|
||||
*(reinterpret_cast<const uint16_t *>(argument)):
|
||||
*(reinterpret_cast<const uint32_t *>(argument)));
|
||||
} else {
|
||||
amd::Os::printf(fmt.data(), *argument);
|
||||
amd::Os::printf(fmt.data(), size == 2 ?
|
||||
*(reinterpret_cast<const uint16_t *>(argument)):
|
||||
*(reinterpret_cast<const uint32_t *>(argument)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -295,13 +295,13 @@ void PrintfDbg::outputDbgBuffer(const device::PrintfInfo& info, const uint32_t*
|
||||
fmt = str.substr(pos, posEnd - pos);
|
||||
fmt.erase(posStart - pos - 1, 1);
|
||||
pos = posStart = posEnd;
|
||||
outputArgument(sepStr, false, ConstStr, reinterpret_cast<const uint32_t*>(fmt.data()));
|
||||
outputArgument(sepStr, false, ConstStr, fmt.data());
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} else if (pos < str.length()) {
|
||||
outputArgument(sepStr, false, ConstStr,
|
||||
reinterpret_cast<const uint32_t*>((str.substr(pos)).data()));
|
||||
str.substr(pos).data());
|
||||
}
|
||||
} while (posStart != std::string::npos);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user