@samitouri / QOSamiQemu / commits / c5b846fb85

target/ppc: Move byte-reverse instructions to decodetree

Moving the following instructions to decodetree specification: brd, brw, brh : X-form The changes were verified by validating that the tcg ops generated by those instructions remain the same, which were captured with the `-d in_asm,op` flag. This also includes improvements from review feedback: - Add TARGET_PPC64 guards with qemu_build_not_reached() for 32-bit builds Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com> Reviewed-by: Glenn Miles <milesg@linux.ibm.com> Signed-off-by: Chinmay Rath <rathc@linux.ibm.com> Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com> Tested-by: Aniket Sahu <asahu1x@linux.ibm.com> Link: https://lore.kernel.org/qemu-devel/20260827133010.278889-29-rathc@linux.ibm.com Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

Vishal Chourasia committed Aug 27, 2026 at 18:59 UTC c5b846fb85f9e80a842c0539629fe3611747df85
3 files changed +53 -35
target/ppc/insn32.decode
+5
@@ -320,6 +320,11 @@ MFMSR 011111 ..... ----- ----- 0001010011 - @X_t
320 MTMSR 011111 ..... ---- . ----- 0010010010 - @X_rs_l
321 MTMSRD 011111 ..... ---- . ----- 0010110010 - @X_rs_l
322
323 +### Fixed-Point Byte-Reverse Instructions
324 +BRW 011111 ..... ..... ----- 0010011011 - @X_sa
325 +BRD 011111 ..... ..... ----- 0010111011 - @X_sa
326 +BRH 011111 ..... ..... ----- 0011011011 - @X_sa
327 +
328 ### Fixed-Point Load Instructions
329
330 LBZ 100010 ..... ..... ................ @D
target/ppc/translate.c
-35
@@ -4519,42 +4519,7 @@ static void gen_dform3D(DisasContext *ctx)
4519 return gen_invalid(ctx);
4520 }
4521
4522 -#if defined(TARGET_PPC64)
4523 -/* brd */
4524 -static void gen_brd(DisasContext *ctx)
4525 -{
4526 - tcg_gen_bswap64_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
4527 -}
4528 -
4529 -/* brw */
4530 -static void gen_brw(DisasContext *ctx)
4531 -{
4532 - tcg_gen_bswap64_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
4533 - tcg_gen_rotli_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 32);
4534 -
4535 -}
4536 -
4537 -/* brh */
4538 -static void gen_brh(DisasContext *ctx)
4539 -{
4540 - TCGv_i64 mask = tcg_constant_i64(0x00ff00ff00ff00ffull);
4541 - TCGv_i64 t1 = tcg_temp_new_i64();
4542 - TCGv_i64 t2 = tcg_temp_new_i64();
4543 -
4544 - tcg_gen_shri_i64(t1, cpu_gpr[rS(ctx->opcode)], 8);
4545 - tcg_gen_and_i64(t2, t1, mask);
4546 - tcg_gen_and_i64(t1, cpu_gpr[rS(ctx->opcode)], mask);
4547 - tcg_gen_shli_i64(t1, t1, 8);
4548 - tcg_gen_or_i64(cpu_gpr[rA(ctx->opcode)], t1, t2);
4549 -}
4550 -#endif
4551 -
4522 static opcode_t opcodes[] = {
4553 -#if defined(TARGET_PPC64)
4554 -GEN_HANDLER_E(brd, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA310),
4555 -GEN_HANDLER_E(brw, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA310),
4556 -GEN_HANDLER_E(brh, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE, PPC2_ISA310),
4557 -#endif
4523 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
4524 GEN_HANDLER_E(copy, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE, PPC2_ISA300),
4525 GEN_HANDLER_E(cp_abort, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
target/ppc/translate/fixedpoint-impl.c.inc
+48
@@ -17,6 +17,54 @@
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 +/*
21 + * Byte-Reverse Instructions
22 + */
23 +static bool trans_BRD(DisasContext *ctx, arg_BRD *a)
24 +{
25 + REQUIRE_64BIT(ctx);
26 + REQUIRE_INSNS_FLAGS2(ctx, ISA310);
27 +#if defined(TARGET_PPC64)
28 + tcg_gen_bswap64_i64(cpu_gpr[a->ra], cpu_gpr[a->rs]);
29 +#else
30 + qemu_build_not_reached();
31 +#endif
32 + return true;
33 +}
34 +
35 +static bool trans_BRW(DisasContext *ctx, arg_BRW *a)
36 +{
37 + REQUIRE_64BIT(ctx);
38 + REQUIRE_INSNS_FLAGS2(ctx, ISA310);
39 +#if defined(TARGET_PPC64)
40 + tcg_gen_bswap64_i64(cpu_gpr[a->ra], cpu_gpr[a->rs]);
41 + tcg_gen_rotli_i64(cpu_gpr[a->ra], cpu_gpr[a->ra], 32);
42 +#else
43 + qemu_build_not_reached();
44 +#endif
45 + return true;
46 +}
47 +
48 +static bool trans_BRH(DisasContext *ctx, arg_BRH *a)
49 +{
50 + REQUIRE_64BIT(ctx);
51 + REQUIRE_INSNS_FLAGS2(ctx, ISA310);
52 +#if defined(TARGET_PPC64)
53 + TCGv_i64 mask = tcg_constant_i64(0x00ff00ff00ff00ffull);
54 + TCGv_i64 t1 = tcg_temp_new_i64();
55 + TCGv_i64 t2 = tcg_temp_new_i64();
56 +
57 + tcg_gen_shri_i64(t1, cpu_gpr[a->rs], 8);
58 + tcg_gen_and_i64(t2, t1, mask);
59 + tcg_gen_and_i64(t1, cpu_gpr[a->rs], mask);
60 + tcg_gen_shli_i64(t1, t1, 8);
61 + tcg_gen_or_i64(cpu_gpr[a->ra], t1, t2);
62 +#else
63 + qemu_build_not_reached();
64 +#endif
65 + return true;
66 +}
67 +
68 /*
69 * Fixed-Point Load/Store Instructions
70 */