All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 0/1] Add helper_print functions for printing intermediate results of complex instructions in RISC-V target
@ 2024-11-23 17:23 Chao Liu
  2024-11-23 17:23 ` [RFC PATCH v1 1/1] riscv: Add helper_print() for printing intermediate results of IR Chao Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Liu @ 2024-11-23 17:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: bmeng.cn, liwei1518, peter.maydell, palmer, alistair.francis,
	dbarboza, zhiwei_liu, Chao Liu

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-23 19:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-23 17:23 [RFC PATCH v1 0/1] Add helper_print functions for printing intermediate results of complex instructions in RISC-V target Chao Liu
2024-11-23 17:23 ` [RFC PATCH v1 1/1] riscv: Add helper_print() for printing intermediate results of IR Chao Liu
2024-11-23 18:35   ` [RFC PATCH v1 0/1] Add helper_print functions for printing intermediate results of complex instructions in RISC-V target Chao Liu
2024-11-23 19:08     ` Chao Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.