@samitouri / QOSamiQemu / commits / 614a52cf54

target/sh4: fixup tcg for sh4 fipr/ftrv instructions

Fixes TCG generation for sh4 `fipr` and `ftrv` instructions. Updates the current logic for these instructions to check the FPSCR register appropriately (according to the sh4 cpu manual, `fipr` and `ftrv` are only defined when the FPSCR register PR flag is 0). Also fixes the mth/nth-vector operands by multiplying by 4 to convert to the correct floating point register offset. Signed-off-by: Randy Schifflin <randy.schifflin@gmail.com> Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com> Message-ID: <20260629-fixup-sh4-tcg-fpu-instructions-b4-v1-2-4356b305f971@gmail.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

Randy Schifflin committed Jun 29, 2026 at 14:49 UTC 614a52cf549e6aefa656634b4d3fa0d4686125c6
2 files changed +6 -11
target/sh4/op_helper.c
+1 -1
@@ -488,7 +488,7 @@ void helper_ftrv(CPUSH4State *env, uint32_t n)
488 float32 p;
489
490 bank_matrix = (env->sr & FPSCR_FR) ? 0 : 16;
491 - bank_vector = (env->sr & FPSCR_FR) ? 16 : 0;
491 + bank_vector = (env->sr & FPSCR_FR) ? 16 + n : n;
492 set_float_exception_flags(0, &env->fp_status);
493 for (i = 0 ; i < 4 ; i++) {
494 r[i] = float32_zero;
target/sh4/translate.c
+5 -10
@@ -377,11 +377,6 @@ static inline void gen_store_fpr64(DisasContext *ctx, TCGv_i64 t, int reg)
377 goto do_illegal; \
378 }
379
380 -#define CHECK_FPSCR_PR_1 \
381 - if (!(ctx->tbflags & FPSCR_PR)) { \
382 - goto do_illegal; \
383 - }
384 -
380 #define CHECK_SH4A \
381 if (!(ctx->features & SH_FEATURE_SH4A)) { \
382 goto do_illegal; \
@@ -1740,22 +1735,22 @@ static void _decode_opc(DisasContext * ctx)
1735 return;
1736 case 0xf0ed: /* fipr FVm,FVn */
1737 CHECK_FPU_ENABLED
1743 - CHECK_FPSCR_PR_1
1738 + CHECK_FPSCR_PR_0
1739 {
1745 - TCGv m = tcg_constant_i32((ctx->opcode >> 8) & 3);
1746 - TCGv n = tcg_constant_i32((ctx->opcode >> 10) & 3);
1740 + TCGv m = tcg_constant_i32(((ctx->opcode >> 8) & 3) << 2);
1741 + TCGv n = tcg_constant_i32(((ctx->opcode >> 10) & 3) << 2);
1742 gen_helper_fipr(tcg_env, m, n);
1743 return;
1744 }
1745 break;
1746 case 0xf0fd: /* ftrv XMTRX,FVn */
1747 CHECK_FPU_ENABLED
1753 - CHECK_FPSCR_PR_1
1748 + CHECK_FPSCR_PR_0
1749 {
1750 if ((ctx->opcode & 0x0300) != 0x0100) {
1751 goto do_illegal;
1752 }
1758 - TCGv n = tcg_constant_i32((ctx->opcode >> 10) & 3);
1753 + TCGv n = tcg_constant_i32(((ctx->opcode >> 10) & 3) << 2);
1754 gen_helper_ftrv(tcg_env, n);
1755 return;
1756 }