[PATCH 00/21] accel/tcg: share raise_excp across TCG targets

Yonggang Luo posted 21 patches 1 week, 1 day ago
accel/tcg/cpu-exec-common.c                   |  6 ++
accel/tcg/tcg-runtime.c                       |  6 ++
accel/tcg/tcg-runtime.h                       | 11 +++
include/accel/tcg/cpu-loop.h                  | 13 +++
include/exec/helper-gen.h.inc                 | 24 ++++--
target/alpha/helper.c                         | 11 ---
target/alpha/helper.h                         |  1 -
target/alpha/translate.c                      |  9 +-
target/arm/internals.h                        | 27 ++++--
target/arm/tcg-stubs.c                        |  4 +-
target/arm/tcg/helper-defs.h                  |  1 -
target/arm/tcg/m_helper.c                     |  3 +-
target/arm/tcg/op_helper.c                    | 43 +++-------
target/arm/tcg/translate.c                    |  2 +-
target/avr/helper.c                           | 24 ------
target/avr/helper.h                           |  3 -
target/avr/translate.c                        |  6 +-
target/hexagon/cpu.c                          | 13 +--
target/hexagon/cpu.h                          |  2 +-
target/hexagon/gen_tcg_sys.h                  |  2 +-
target/hexagon/helper.h                       |  5 +-
target/hexagon/internal.h                     |  5 --
target/hexagon/macros.h                       |  2 +-
target/hexagon/op_helper.c                    | 37 ++++-----
target/hexagon/translate.c                    | 11 +--
target/hppa/helper.h                          |  2 -
target/hppa/op_helper.c                       | 15 +---
target/hppa/sys_helper.c                      |  4 +-
target/hppa/translate.c                       |  3 +-
target/i386/helper.h                          |  2 +-
target/i386/tcg/excp_helper.c                 | 18 ++--
target/i386/tcg/helper-tcg.h                  | 42 ++++++++--
target/i386/tcg/translate.c                   |  2 +-
target/loongarch/tcg/helper.h                 |  2 -
target/loongarch/tcg/op_helper.c              |  6 --
target/loongarch/tcg/tcg_cpu.c                |  4 +-
target/loongarch/tcg/translate.c              |  3 +-
target/m68k/helper.c                          | 12 +--
target/m68k/helper.h                          |  1 -
target/m68k/op_helper.c                       | 19 -----
target/m68k/translate.c                       |  2 +-
target/microblaze/helper.c                    |  3 +-
target/microblaze/helper.h                    |  2 -
target/microblaze/op_helper.c                 | 22 +----
target/microblaze/translate.c                 |  3 +-
target/mips/helper.h                          |  6 +-
target/mips/tcg/exception.c                   | 22 +----
target/mips/tcg/fpu_helper.c                  |  6 +-
target/mips/tcg/translate.c                   | 13 ++-
target/or1k/exception.c                       | 31 -------
target/or1k/exception.h                       |  7 +-
target/or1k/exception_helper.c                | 13 +--
target/or1k/helper.h                          |  1 -
target/or1k/meson.build                       |  1 -
target/or1k/translate.c                       |  2 +-
target/ppc/cpu.h                              |  3 -
target/ppc/helper.h                           |  2 -
target/ppc/internal.h                         |  9 ++
target/ppc/misc_helper.c                      |  1 +
target/ppc/tcg-excp_helper.c                  | 21 -----
target/ppc/timebase_helper.c                  |  1 +
target/ppc/translate.c                        | 23 +++---
target/riscv/helper.h                         |  2 +-
target/riscv/tcg/insn_trans/trans_rvi.c.inc   |  6 +-
.../tcg/insn_trans/trans_rvzicfiss.c.inc      |  3 +-
target/riscv/tcg/op_helper.c                  |  5 +-
target/riscv/tcg/translate.c                  | 10 ++-
target/rx/cpu.h                               | 13 +++
target/rx/helper.c                            | 16 ++--
target/rx/helper.h                            |  7 +-
target/rx/op_helper.c                         | 46 +----------
target/rx/translate.c                         | 19 +++--
target/s390x/helper.h                         |  1 -
target/s390x/tcg/mem_helper.c                 |  2 +-
target/s390x/tcg/misc_helper.c                | 10 ---
target/s390x/tcg/translate.c                  |  2 +-
target/sh4/cpu.h                              | 24 ++++++
target/sh4/helper.c                           | 82 ++++++++++---------
target/sh4/helper.h                           |  4 -
target/sh4/op_helper.c                        | 43 ++--------
target/sh4/translate.c                        | 17 +++-
target/sparc/helper.c                         | 21 +----
target/sparc/helper.h                         |  2 -
target/sparc/translate.c                      |  7 +-
target/xtensa/cpu.h                           |  1 +
target/xtensa/exc_helper.c                    | 13 ++-
target/xtensa/helper.h                        |  1 -
target/xtensa/translate.c                     |  7 +-
target/xtensa/win_helper.c                    | 12 +--
89 files changed, 399 insertions(+), 577 deletions(-)
delete mode 100644 target/or1k/exception.c
[PATCH 00/21] accel/tcg: share raise_excp across TCG targets
Posted by Yonggang Luo 1 week, 1 day ago
Many TCG targets copy the same two-line raise: set
cs->exception_index and call cpu_loop_exit_restore. They also copy
DEF_HELPER_2(raise_exception, ...). helper_raise_exception is a
global C symbol, so a unified binary cannot keep that name on more
than one target.

This series adds a shared C exit and a shared TCG helper, then
converts one target per commit. Joiners call gen_helper_raise_excp
and drop the copied DEF. Leftover TCG helpers that still do extra
work take an arch prefix. C wrappers keep the short name as
static inline where that is enough. The shared helper only touches
CPUState. Translate may store arch state (error_code, PC) first.
Guest trap numbers stay below 0x10000. TCG loop codes such as
EXCP_INTERRUPT start at 0x10000.

- Add cpu_loop_exit_excp next to cpu_loop_exit_restore. Set
  cpu->exception_index then restore and exit. host_pc == 0 skips
  restore.
- Move helper_info_* extern into each gen_helper_* body so a
  comment on DEF_HELPER attaches to gen_helper_*, not helper_info_*.
- Add TCG raise_excp (env, exception, restore). restore 1 exits
  with GETPC(); restore 0 skips unwind.
- Convert RX and SH4: name guest traps RX_EXCP_* / SH4_EXCP_*.
  Join privilege, illegal, BRK, and INT on RX, and illegal /
  FPU-disable on SH4. Prefix leftover rx_wait. Keep SH4 sleep,
  trapa, and exclusive.
- Convert the remaining joiners one arch per commit: m68k, or1k,
  microblaze, sparc, loongarch, hppa, alpha, s390x, xtensa, avr,
  arm exception_internal, mips, and ppc. Store error_code or PC
  in translate where needed, then call the shared helper.
- Prefix leftover TCG helpers that still do extra work:
  i386_raise_exception, riscv_raise_exception, and
  hexagon_raise_exception. Prefix leftover wait as mips_wait and
  hexagon_wait. Tricore raise_exception_sync does not join.

Yonggang Luo (21):
  accel/tcg: add cpu_loop_exit_excp
  helper-gen: move helper_info extern into gen_helper
  accel/tcg: add helper raise_excp
  target/rx: convert raises to raise_excp
  target/sh4: convert raises to raise_excp
  target/m68k: convert raises to raise_excp
  target/or1k: convert exception to raise_excp
  target/microblaze: convert raise_exception to raise_excp
  target/sparc: convert raise_exception to raise_excp
  target/loongarch: convert raise_exception to raise_excp
  target/hexagon: convert raise_exception to hexagon_raise_exception
  target/hppa: convert excp to raise_excp
  target/alpha: convert excp to raise_excp
  target/s390x: convert exception to raise_excp
  target/xtensa: convert exception to raise_excp
  target/avr: convert debug/break/sleep to raise_excp
  target/arm: convert exception_internal to raise_excp
  target/riscv: convert raise_exception to riscv_raise_exception
  target/mips: convert raise_exception to raise_excp
  target/ppc: convert raise_exception to raise_excp
  target/i386: convert raise_exception to i386_raise_exception

 accel/tcg/cpu-exec-common.c                   |  6 ++
 accel/tcg/tcg-runtime.c                       |  6 ++
 accel/tcg/tcg-runtime.h                       | 11 +++
 include/accel/tcg/cpu-loop.h                  | 13 +++
 include/exec/helper-gen.h.inc                 | 24 ++++--
 target/alpha/helper.c                         | 11 ---
 target/alpha/helper.h                         |  1 -
 target/alpha/translate.c                      |  9 +-
 target/arm/internals.h                        | 27 ++++--
 target/arm/tcg-stubs.c                        |  4 +-
 target/arm/tcg/helper-defs.h                  |  1 -
 target/arm/tcg/m_helper.c                     |  3 +-
 target/arm/tcg/op_helper.c                    | 43 +++-------
 target/arm/tcg/translate.c                    |  2 +-
 target/avr/helper.c                           | 24 ------
 target/avr/helper.h                           |  3 -
 target/avr/translate.c                        |  6 +-
 target/hexagon/cpu.c                          | 13 +--
 target/hexagon/cpu.h                          |  2 +-
 target/hexagon/gen_tcg_sys.h                  |  2 +-
 target/hexagon/helper.h                       |  5 +-
 target/hexagon/internal.h                     |  5 --
 target/hexagon/macros.h                       |  2 +-
 target/hexagon/op_helper.c                    | 37 ++++-----
 target/hexagon/translate.c                    | 11 +--
 target/hppa/helper.h                          |  2 -
 target/hppa/op_helper.c                       | 15 +---
 target/hppa/sys_helper.c                      |  4 +-
 target/hppa/translate.c                       |  3 +-
 target/i386/helper.h                          |  2 +-
 target/i386/tcg/excp_helper.c                 | 18 ++--
 target/i386/tcg/helper-tcg.h                  | 42 ++++++++--
 target/i386/tcg/translate.c                   |  2 +-
 target/loongarch/tcg/helper.h                 |  2 -
 target/loongarch/tcg/op_helper.c              |  6 --
 target/loongarch/tcg/tcg_cpu.c                |  4 +-
 target/loongarch/tcg/translate.c              |  3 +-
 target/m68k/helper.c                          | 12 +--
 target/m68k/helper.h                          |  1 -
 target/m68k/op_helper.c                       | 19 -----
 target/m68k/translate.c                       |  2 +-
 target/microblaze/helper.c                    |  3 +-
 target/microblaze/helper.h                    |  2 -
 target/microblaze/op_helper.c                 | 22 +----
 target/microblaze/translate.c                 |  3 +-
 target/mips/helper.h                          |  6 +-
 target/mips/tcg/exception.c                   | 22 +----
 target/mips/tcg/fpu_helper.c                  |  6 +-
 target/mips/tcg/translate.c                   | 13 ++-
 target/or1k/exception.c                       | 31 -------
 target/or1k/exception.h                       |  7 +-
 target/or1k/exception_helper.c                | 13 +--
 target/or1k/helper.h                          |  1 -
 target/or1k/meson.build                       |  1 -
 target/or1k/translate.c                       |  2 +-
 target/ppc/cpu.h                              |  3 -
 target/ppc/helper.h                           |  2 -
 target/ppc/internal.h                         |  9 ++
 target/ppc/misc_helper.c                      |  1 +
 target/ppc/tcg-excp_helper.c                  | 21 -----
 target/ppc/timebase_helper.c                  |  1 +
 target/ppc/translate.c                        | 23 +++---
 target/riscv/helper.h                         |  2 +-
 target/riscv/tcg/insn_trans/trans_rvi.c.inc   |  6 +-
 .../tcg/insn_trans/trans_rvzicfiss.c.inc      |  3 +-
 target/riscv/tcg/op_helper.c                  |  5 +-
 target/riscv/tcg/translate.c                  | 10 ++-
 target/rx/cpu.h                               | 13 +++
 target/rx/helper.c                            | 16 ++--
 target/rx/helper.h                            |  7 +-
 target/rx/op_helper.c                         | 46 +----------
 target/rx/translate.c                         | 19 +++--
 target/s390x/helper.h                         |  1 -
 target/s390x/tcg/mem_helper.c                 |  2 +-
 target/s390x/tcg/misc_helper.c                | 10 ---
 target/s390x/tcg/translate.c                  |  2 +-
 target/sh4/cpu.h                              | 24 ++++++
 target/sh4/helper.c                           | 82 ++++++++++---------
 target/sh4/helper.h                           |  4 -
 target/sh4/op_helper.c                        | 43 ++--------
 target/sh4/translate.c                        | 17 +++-
 target/sparc/helper.c                         | 21 +----
 target/sparc/helper.h                         |  2 -
 target/sparc/translate.c                      |  7 +-
 target/xtensa/cpu.h                           |  1 +
 target/xtensa/exc_helper.c                    | 13 ++-
 target/xtensa/helper.h                        |  1 -
 target/xtensa/translate.c                     |  7 +-
 target/xtensa/win_helper.c                    | 12 +--
 89 files changed, 399 insertions(+), 577 deletions(-)
 delete mode 100644 target/or1k/exception.c

-- 
2.52.0.windows.1