Skip to content

Use PRIu32 format specifier when printing time_in_secs#76

Merged
joseph-yiu merged 2 commits into
eembc:dev_2026q3from
joseph-yiu:fix/issue35_printf_u32
May 22, 2026
Merged

Use PRIu32 format specifier when printing time_in_secs#76
joseph-yiu merged 2 commits into
eembc:dev_2026q3from
joseph-yiu:fix/issue35_printf_u32

Conversation

@joseph-yiu
Copy link
Copy Markdown
Contributor

@joseph-yiu joseph-yiu commented May 21, 2026

This patch addresses #35, where a printf statement for time_in_secs() (ee_u32) used the %d format specifier for int. The issue arise when using a 16-bit architecture where %d (int) does not match the size of ee_u32.

2 files are modified:

  • core_main.c
  • coremark.h (adding inttypes.h)

The change does not affect CoreMark result as it only impact the code for execution time reporting (after the workload is completed).

@petertorelli
Copy link
Copy Markdown
Member

PRIu32, while being C99 compliant, implies 32-bits. Since I don't have any 16-bit systems to test against, I think the worst-case is a warning as the compiler converts. Other than pedantry, there's no impact to the core benchmark timing so this is fine.

@mysterymath
Copy link
Copy Markdown

I took the time to rebuild llvm-mos's copy of coremark without this patch, and we got two warnings. Accordingly, I think there's another place to fix this at line 367.

core_main.c:367:42: warning: format specifies type 'int' but the argument has type 'secs_ret' (aka 'unsigned long') [-Wformat]
  367 |     ee_printf("Total time (secs): %d\n", time_in_secs(total_time));
      |                                   ~~     ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                   %lu
core_main.c:370:19: warning: format specifies type 'int' but the argument has type 'ee_u32' (aka 'unsigned long') [-Wformat]
  369 |         ee_printf("Iterations/Sec   : %d\n",
      |                                       ~~
      |                                       %lu
  370 |                   default_num_contexts * results[0].iterations
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371 |                       / time_in_secs(total_time));
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

@mysterymath
Copy link
Copy Markdown

I also manually applied this patch along with a similar PRIu32 fix to line 367, and the benchmark passes with no warnings or runtime errors.

@joseph-yiu
Copy link
Copy Markdown
Contributor Author

Thanks. I will update that this weekend :)

@joseph-yiu joseph-yiu merged commit 58e6027 into eembc:dev_2026q3 May 22, 2026
@joseph-yiu
Copy link
Copy Markdown
Contributor Author

Changes merged into development branch (dev_2026q3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants