@samitouri / QOSamiQemu / commits / 42b6a48003

target/ppc: Convert b{a, l, la} to decode tree

Convert b, ba, bl and bla to decode tree specification. The functionality was tested by comparing the qemu -D log -d op,in_asm output as well as single stepping gdb to confirm LR was correctly populated only when LK is set. Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Reviewed-by: Nikhil Kumar Singh <nikhilks@linux.ibm.com> Reviewed-by: Glenn Miles <milesg@linux.ibm.com> Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com> Signed-off-by: Chinmay Rath <rathc@linux.ibm.com> Tested-by: Aniket Sahu <asahu1x@linux.ibm.com> Link: https://lore.kernel.org/qemu-devel/20260827133010.278889-15-rathc@linux.ibm.com Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

Ojaswin Mujoo committed Aug 27, 2026 at 18:59 UTC 42b6a48003b377d6139b8663a5056c07d8f9d40b
4 files changed +31 -31
target/ppc/insn32.decode
+7
@@ -1486,6 +1486,13 @@ MCRF 010011 ... -- ... -- ----- 00000 00000 - @XL_bfa
1486 MFBHRBE 011111 ..... ..... ..... 0100101110 - @XFX_bhrbe
1487 CLRBHRB 011111 ----- ----- ----- 0110101110 -
1488
1489 +# Branch Instructions
1490 +%li 2:24 !function=times_4
1491 +&I_b li aa:bool lk:bool
1492 +@I_b ...... ........................ aa:1 lk:1 &I_b li=%li
1493 +
1494 +B 010010 ........................ . . @I_b
1495 +
1496 ## Misc POWER instructions
1497
1498 ATTN 000000 00000 00000 00000 0100000000 0
target/ppc/internal.h
-7
@@ -197,13 +197,6 @@ EXTRACT_HELPER(L, 16, 2);
197 EXTRACT_HELPER(WC, 21, 2);
198 EXTRACT_HELPER(PL, 16, 2);
199
200 -/*** Jump target decoding ***/
201 -/* Immediate address */
202 -static inline target_ulong LI(uint32_t opcode)
203 -{
204 - return (opcode >> 0) & 0x03FFFFFC;
205 -}
206 -
200 static inline uint32_t BD(uint32_t opcode)
201 {
202 return (opcode >> 0) & 0xFFFC;
target/ppc/translate.c
-24
@@ -3089,29 +3089,6 @@ static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
3089 tcg_gen_movi_tl(cpu_lr, nip);
3090 }
3091
3092 -/* b ba bl bla */
3093 -static void gen_b(DisasContext *ctx)
3094 -{
3095 - target_ulong li, target;
3096 -
3097 - /* sign extend LI */
3098 - li = LI(ctx->opcode);
3099 - li = (li ^ 0x02000000) - 0x02000000;
3100 - if (likely(AA(ctx->opcode) == 0)) {
3101 - target = ctx->cia + li;
3102 - } else {
3103 - target = li;
3104 - }
3105 - if (LK(ctx->opcode)) {
3106 - gen_setlr(ctx, ctx->base.pc_next);
3107 - gen_update_branch_history(ctx, ctx->cia, NULL, BHRB_TYPE_CALL);
3108 - } else {
3109 - gen_update_branch_history(ctx, ctx->cia, NULL, BHRB_TYPE_OTHER);
3110 - }
3111 - gen_goto_tb(ctx, 0, target);
3112 - ctx->base.is_jmp = DISAS_NORETURN;
3113 -}
3114 -
3092 #define BCOND_IM 0
3093 #define BCOND_LR 1
3094 #define BCOND_CTR 2
@@ -5353,7 +5330,6 @@ GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
5330 /* ISA v3.0 changed the extended opcode from 62 to 30 */
5331 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x039FF801, PPC_WAIT),
5332 GEN_HANDLER_E(wait, 0x1F, 0x1E, 0x00, 0x039CF801, PPC_NONE, PPC2_ISA300),
5356 -GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
5333 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
5334 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
5335 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
target/ppc/translate/branch-impl.c.inc
+24
@@ -31,3 +31,27 @@ static bool trans_RFEBB(DisasContext *ctx, arg_XL_s *arg)
31 return true;
32 }
33 #endif
34 +
35 +static bool trans_B(DisasContext *ctx, arg_I_b *a)
36 +{
37 + target_ulong target, li;
38 +
39 + /* sign extend LI */
40 + li = (a->li ^ 0x02000000) - 0x02000000;
41 +
42 + if (likely(a->aa == 0)) {
43 + target = ctx->cia + li;
44 + } else {
45 + target = li;
46 + }
47 + if (a->lk) {
48 + gen_setlr(ctx, ctx->base.pc_next);
49 + gen_update_branch_history(ctx, ctx->cia, NULL, BHRB_TYPE_CALL);
50 + } else {
51 + gen_update_branch_history(ctx, ctx->cia, NULL, BHRB_TYPE_OTHER);
52 + }
53 + gen_goto_tb(ctx, 0, target);
54 + ctx->base.is_jmp = DISAS_NORETURN;
55 +
56 + return true;
57 +}