RFC Add helper_print functions for printing intermediate results of complex instructions in RISC-V target
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest1 patch 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/1 | riscv: Add helper_print() for printing intermediate results of IRtarget/ target/ | +59 | 2 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH v1 0/1] Add helper_print functions for printing intermediate results of complex instructions in RISC-V target
Hi all,
Recently, I have been working on functional simulation and verification of an extended complex instruction set for an AI chip based on the RISC-V architecture using QEMU.
Given the complexity of some instructions, I attempted to introduce a set of helper functions that can print certain intermediate results of IR corresponding to a single instruction, such as those from sparse matrix operations.
My implementation approach is as follows:
1. Encapsulate printf within helper functions (to avoid issues where the printf address might exceed the ±2GB address space when called directly). Since helpers do not support variadic arguments, I defined multiple helper_print functions with a maximum of 7 parameters.
2. Designed a syntactic sugar using C macros and the concatenation operator ## to encapsulate the aforementioned helper_print functions, which can support up to 7 parameters.
However, I encountered some issues, such as having to set < #pragma GCC diagnostic ignored "-Wformat-security"> for this piece of code, but I think there might be some security risks involved.
Currently, these macros are temporarily added under target/risc-v, but I believe they could be designed more generally to support more architectures.
During testing, I found that these interfaces work particularly well for debugging simulations of complex instructions.
Therefore, I am sharing this patch with the mailing list in hopes that we can discuss and come up with a friendlier and more universal solution. :)
Regards,
Chao
Chao Liu (1):
riscv: Add gen_helper_print() to debug IR
target/riscv/helper.h | 13 ++++++++++++ target/riscv/op_helper.c | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
Signature · 1 line
2.40.1