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

Chao Liu posted 1 patch 11 months, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/cover.1732376265.git.chao.liu@yeah.net
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
target/riscv/helper.h    | 13 ++++++++++++
target/riscv/op_helper.c | 46 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+)
[RFC PATCH v1 0/1] Add helper_print functions for printing intermediate results of complex instructions in RISC-V target
Posted by Chao Liu 11 months, 4 weeks ago
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(+)

-- 
2.40.1