Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions rocclr/device/pal/palprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ int PrintfDbg::checkVectorSpecifier(const std::string& fmt, size_t startPos, siz
else if ((curPos >= 5) && (fmt[curPos - 5] == 'v')) {
size = 4;
}
// modifier is "hh" or "hl" with vec size 16
else if ((curPos >= 6) && (fmt[curPos - 6] == 'v')) {
size = 5;
}
if (size > 0) {
curPos = size;
pos -= curPos;
Expand Down Expand Up @@ -255,11 +259,9 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
if (checkString(fmt.c_str())) {
// copiedBytes should be as number of printed chars
copiedBytes = 0;
//(null) should be printed
if (*(reinterpret_cast<const unsigned char*>(argument)) == 0) {
amd::Os::printf(fmt.data(), 0);
// copiedBytes = strlen("(null)")
copiedBytes = 6;
// accounts for null character
copiedBytes = 1;
} else {
const unsigned char* argumentStr = reinterpret_cast<const unsigned char*>(argument);
amd::Os::printf(fmt.data(), argumentStr);
Expand Down Expand Up @@ -294,7 +296,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
const float fArg = size == 2 ?
amd::half2float(*(reinterpret_cast<const uint16_t *>(argument))) :
*(reinterpret_cast<const float *>(argument));
static const char* fSpecifiers = "eEfgGa";
static const char* fSpecifiers = "eEfFgGaA";
std::string fmtF = fmt;
size_t posS = fmtF.find_first_of("%");
size_t posE = fmtF.find_first_of(fSpecifiers);
Expand Down Expand Up @@ -322,13 +324,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
} else {
bool hhModifier = (strstr(fmt.c_str(), "hh") != nullptr);
if (hhModifier) {
// current implementation of printf in gcc 4.5.2 runtime libraries, doesn`t recognize
// "hh" modifier ==>
// argument should be explicitly converted to unsigned char (uchar) before printing and
// fmt should be updated not to contain "hh" modifier
std::string hhFmt = fmt;
hhFmt.erase(hhFmt.find_first_of("h"), 2);
amd::Os::printf(hhFmt.data(), *(reinterpret_cast<const unsigned char*>(argument)));
amd::Os::printf(fmt.data(), *(reinterpret_cast<const unsigned char*>(argument)));
} else if (hlModifier) {
amd::Os::printf(hlFmt.data(), size == 2 ?
*(reinterpret_cast<const uint16_t *>(argument)):
Expand Down Expand Up @@ -370,7 +366,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t

void PrintfDbg::outputDbgBuffer(const device::PrintfInfo& info, const uint32_t* workitemData,
size_t& i) const {
static const char* specifiers = "cdieEfgGaosuxXp";
static const char* specifiers = "cdieEfFgGaAosuxXp";
static const char* modifiers = "hl";
static const char* special = "%n";
static const std::string sepStr = "%s";
Expand Down Expand Up @@ -485,8 +481,14 @@ void PrintfDbg::outputDbgBuffer(const device::PrintfInfo& info, const uint32_t*
}
}

// handle '%%' escapes
if (pos != std::string::npos) {
fmt = str.substr(pos, str.size() - pos);
size_t P = fmt.find("%%");
while (P != std::string::npos) {
fmt.replace(P, 2, "%");
P = fmt.find("%%", P);
}
outputArgument(sepStr, false, ConstStr, fmt.data());
}
}
Expand Down
31 changes: 17 additions & 14 deletions rocclr/device/rocm/rocprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ bool PrintfDbg::checkFloat(const std::string& fmt) const {
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
case 'a':
case 'A':
return true;
break;
default:
Expand Down Expand Up @@ -101,6 +103,10 @@ int PrintfDbg::checkVectorSpecifier(const std::string& fmt, size_t startPos, siz
else if ((curPos >= 5) && (fmt[curPos - 5] == 'v')) {
size = 4;
}
// modifier is "hh" or "hl" with vec size 16
else if ((curPos >= 6) && (fmt[curPos - 6] == 'v')) {
size = 5;
}
if (size > 0) {
curPos = size;
pos -= curPos;
Expand Down Expand Up @@ -143,11 +149,9 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
if (checkString(fmt.c_str())) {
// copiedBytes should be as number of printed chars
copiedBytes = 0;
//(null) should be printed
if (*(reinterpret_cast<const unsigned char*>(argument)) == 0) {
amd::Os::printf(fmt.data(), 0);
// copiedBytes = strlen("(null)")
copiedBytes = 6;
// accounts for null character
copiedBytes = 1;
} else {
const unsigned char* argumentStr = reinterpret_cast<const unsigned char*>(argument);
amd::Os::printf(fmt.data(), argumentStr);
Expand Down Expand Up @@ -182,7 +186,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
const float fArg = size == 2 ?
amd::half2float(*(reinterpret_cast<const uint16_t *>(argument))) :
*(reinterpret_cast<const float *>(argument));
static const char* fSpecifiers = "eEfgGa";
static const char* fSpecifiers = "eEfFgGaA";
std::string fmtF = fmt;
size_t posS = fmtF.find_first_of("%");
size_t posE = fmtF.find_first_of(fSpecifiers);
Expand Down Expand Up @@ -210,14 +214,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
} else {
bool hhModifier = (strstr(fmt.c_str(), "hh") != nullptr);
if (hhModifier) {
// current implementation of printf in gcc 4.5.2 runtime libraries,
// doesn`t recognize "hh" modifier ==>
// argument should be explicitly converted to unsigned char (uchar)
// before printing and
// fmt should be updated not to contain "hh" modifier
std::string hhFmt = fmt;
hhFmt.erase(hhFmt.find_first_of("h"), 2);
amd::Os::printf(hhFmt.data(), *(reinterpret_cast<const unsigned char*>(argument)));
amd::Os::printf(fmt.data(), *(reinterpret_cast<const unsigned char*>(argument)));
} else if (hlModifier) {
amd::Os::printf(hlFmt.data(), size == 2 ?
*(reinterpret_cast<const uint16_t *>(argument)):
Expand Down Expand Up @@ -259,7 +256,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t

void PrintfDbg::outputDbgBuffer(const device::PrintfInfo& info, const uint32_t* workitemData,
size_t& i) const {
static const char* specifiers = "cdieEfgGaosuxXp";
static const char* specifiers = "cdieEfFgGaAosuxXp";
static const char* modifiers = "hl";
static const char* special = "%n";
static const std::string sepStr = "%s";
Expand Down Expand Up @@ -384,8 +381,14 @@ void PrintfDbg::outputDbgBuffer(const device::PrintfInfo& info, const uint32_t*
}
}

// handle '%%' escapes
if (pos != std::string::npos) {
fmt = str.substr(pos, str.size() - pos);
size_t P = fmt.find("%%", P);
while (P != std::string::npos) {
fmt.replace(P, 2, "%");
P = fmt.find("%%", P);
}
outputArgument(sepStr, false, ConstStr, reinterpret_cast<const uint32_t*>(fmt.data()));
}
}
Expand Down
Loading