2014-07-04 16:17:05 -04:00
|
|
|
//
|
|
|
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "device/cpu/cpubuiltins.hpp"
|
|
|
|
|
#include "device/cpu/cpucommand.hpp"
|
|
|
|
|
|
|
|
|
|
#include <amdocl/cl_kernel.h>
|
2017-04-13 13:56:38 -04:00
|
|
|
#include <cstdio> // for printf
|
2014-07-04 16:17:05 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
#define BUF_SIZE_PRINTF 4095
|
2017-04-13 13:56:38 -04:00
|
|
|
// In the current implementation of printf in gcc 4.5.2 runtime libraries,inf/infinity and nan are
|
|
|
|
|
// not supported
|
|
|
|
|
// The [-]infinity value is printed as [-]1.#INF00
|
|
|
|
|
// The [-]nan value is printed as [-]1.#INF00
|
|
|
|
|
// bufOutUpdate converts the all printed instanced of [-]1.#INF00 to inf,and
|
2014-07-04 16:17:05 -04:00
|
|
|
// all printed instanced of [-]1.#IND00 to nan
|
2017-04-13 13:56:38 -04:00
|
|
|
void bufOutUpdate(std::string& sBufOut, const char* strToReplace, const char* strReplace) {
|
|
|
|
|
size_t foundIdx = 0;
|
|
|
|
|
while ((foundIdx = sBufOut.find(strToReplace, foundIdx)) != std::string::npos) {
|
|
|
|
|
sBufOut.replace(foundIdx, strlen(strToReplace), strReplace, strlen(strReplace));
|
|
|
|
|
foundIdx += 3;
|
|
|
|
|
}
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
2017-04-13 13:56:38 -04:00
|
|
|
int cpuprintf(const char* format, ...) {
|
|
|
|
|
char cBufOut[BUF_SIZE_PRINTF];
|
|
|
|
|
std::string sBufOut;
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
// write to the buffer
|
|
|
|
|
vsprintf(cBufOut, format, args);
|
|
|
|
|
sBufOut = cBufOut;
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
// convert to correct infinity/nan representation
|
|
|
|
|
bufOutUpdate(sBufOut, "1.#INF00", "inf");
|
|
|
|
|
bufOutUpdate(sBufOut, "1.#IND00", "nan");
|
|
|
|
|
bufOutUpdate(sBufOut, "1.#QNAN0", "nan");
|
|
|
|
|
int ret = amd::Os::printf("%s", sBufOut.c_str());
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
va_end(args);
|
|
|
|
|
return ret;
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
namespace cpu {
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
const clk_builtins_t Builtins::dispatchTable_ = {
|
2014-07-04 16:17:05 -04:00
|
|
|
/* Synchronization functions */
|
|
|
|
|
&WorkItem::barrier,
|
|
|
|
|
/* AMD Only builtins: FIXME_lmoriche: remove or add an extension */
|
2017-04-13 13:56:38 -04:00
|
|
|
NULL, cpuprintf};
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
} // namespace cpu
|