mbox series

[RFC,v1,0/1] Add helper_print functions for printing intermediate results of complex instructions in RISC-V target

Message ID cover.1732376265.git.chao.liu@yeah.net (mailing list archive)
Headers show
Series Add helper_print functions for printing intermediate results of complex instructions in RISC-V target | expand

Message

Chao Liu Nov. 23, 2024, 5:23 p.m. UTC
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(+)