diff options
| author | Athish Pranav D <[email protected]> | 2025-03-12 18:47:33 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-03-12 13:17:33 +0000 |
| commit | e36aff2ea93d9a9ff89320f77d4e2917c6d18697 (patch) | |
| tree | 6d1d769fc7acd4658250f6834a37e5249b376c81 /src/cuda-sim/cuda_device_printf.cc | |
| parent | 6ab2ca48f7f3f97052ae31f56fa93fa7eed84f2c (diff) | |
Corrected offset for args in printf (#84)
Signed-off-by: Athishpranav2003 <[email protected]>
Co-authored-by: Anu <[email protected]>
Co-authored-by: WilliamMTK <[email protected]>
Diffstat (limited to 'src/cuda-sim/cuda_device_printf.cc')
| -rw-r--r-- | src/cuda-sim/cuda_device_printf.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/cuda-sim/cuda_device_printf.cc b/src/cuda-sim/cuda_device_printf.cc index 1da6b85..69ebc63 100644 --- a/src/cuda-sim/cuda_device_printf.cc +++ b/src/cuda-sim/cuda_device_printf.cc @@ -38,6 +38,7 @@ void my_cuda_printf(const char *fmtstr, const char *arg_list) { unsigned arg_offset = 0; char buf[64]; bool in_fmt = false; + uint8_t acc = 0; while (fmtstr[i]) { char c = fmtstr[i++]; if (!in_fmt) { @@ -60,12 +61,19 @@ void my_cuda_printf(const char *fmtstr, const char *arg_list) { void *ptr = (void *)&arg_list[arg_offset]; // unsigned long long value = ((unsigned long long*)arg_list)[arg_offset]; if (c == 'u' || c == 'd') { - fprintf(fp, buf, *((unsigned long long *)ptr)); + acc++; + fprintf(fp, buf, *((unsigned *)ptr)); + arg_offset += 4; } else if (c == 'f') { - double tmp = *((double *)ptr); + if (acc%2) { + arg_offset += 4; + ptr = (void *)&arg_list[arg_offset]; + } + float tmp = *((float *)ptr); fprintf(fp, buf, tmp); + arg_offset += 8; + acc = 0; } - arg_offset++; in_fmt = false; } } |
