All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chinmay Rath <rathc@linux.ibm.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	harshpb@linux.ibm.com, milesg@linux.ibm.com, npiggin@gmail.com,
	richard.henderson@linaro.org, vishalc@linux.ibm.com,
	Amit Machhiwal <amachhiw@linux.ibm.com>
Subject: Re: [PATCH v2 28/37] target/ppc: Move byte-reverse instructions to decodetree
Date: Thu, 27 Aug 2026 16:22:31 +0530	[thread overview]
Message-ID: <77f33b73-90f5-4fa4-b894-c5ae55ccf99b@linux.ibm.com> (raw)
In-Reply-To: <20260826212240.e4941caf-e6-amachhiw@linux.ibm.com>


On 8/26/26 21:24, Amit Machhiwal wrote:
> On 2026/08/26 10:38 AM, Chinmay Rath wrote:
>> From: Vishal Chourasia <vishalc@linux.ibm.com>
>>
>> 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>
>> ---
>>   target/ppc/insn32.decode                   |  5 +++
>>   target/ppc/translate.c                     | 35 -------------------
>>   target/ppc/translate/fixedpoint-impl.c.inc | 40 ++++++++++++++++++++++
>>   3 files changed, 45 insertions(+), 35 deletions(-)
>>
>> diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
>> index f7ab08704f..7614655f72 100644
>> --- a/target/ppc/insn32.decode
>> +++ b/target/ppc/insn32.decode
>> @@ -320,6 +320,11 @@ MFMSR           011111 ..... ----- ----- 0001010011 -   @X_t
>>   MTMSR           011111 ..... ---- . ----- 0010010010 -  @X_rs_l
>>   MTMSRD          011111 ..... ---- . ----- 0010110010 -  @X_rs_l
>>   
>> +### Fixed-Point Byte-Reverse Instructions
>> +BRW             011111 ..... ..... ----- 0010011011 -   @X_sa
>> +BRD             011111 ..... ..... ----- 0010111011 -   @X_sa
>> +BRH             011111 ..... ..... ----- 0011011011 -   @X_sa
>> +
>>   ### Fixed-Point Load Instructions
>>   
>>   LBZ             100010 ..... ..... ................     @D
>> diff --git a/target/ppc/translate.c b/target/ppc/translate.c
>> index 9d29134fa1..8950476be7 100644
>> --- a/target/ppc/translate.c
>> +++ b/target/ppc/translate.c
>> @@ -4532,42 +4532,7 @@ static void gen_dform3D(DisasContext *ctx)
>>       return gen_invalid(ctx);
>>   }
>>   
>> -#if defined(TARGET_PPC64)
>> -/* brd */
>> -static void gen_brd(DisasContext *ctx)
>> -{
>> -    tcg_gen_bswap64_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
>> -}
>> -
>> -/* brw */
>> -static void gen_brw(DisasContext *ctx)
>> -{
>> -    tcg_gen_bswap64_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
>> -    tcg_gen_rotli_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 32);
>> -
>> -}
>> -
>> -/* brh */
>> -static void gen_brh(DisasContext *ctx)
>> -{
>> -    TCGv_i64 mask = tcg_constant_i64(0x00ff00ff00ff00ffull);
>> -    TCGv_i64 t1 = tcg_temp_new_i64();
>> -    TCGv_i64 t2 = tcg_temp_new_i64();
>> -
>> -    tcg_gen_shri_i64(t1, cpu_gpr[rS(ctx->opcode)], 8);
>> -    tcg_gen_and_i64(t2, t1, mask);
>> -    tcg_gen_and_i64(t1, cpu_gpr[rS(ctx->opcode)], mask);
>> -    tcg_gen_shli_i64(t1, t1, 8);
>> -    tcg_gen_or_i64(cpu_gpr[rA(ctx->opcode)], t1, t2);
>> -}
>> -#endif
>> -
>>   static opcode_t opcodes[] = {
>> -#if defined(TARGET_PPC64)
>> -GEN_HANDLER_E(brd, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA310),
>> -GEN_HANDLER_E(brw, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA310),
>> -GEN_HANDLER_E(brh, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE, PPC2_ISA310),
>> -#endif
>>   GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
>>   GEN_HANDLER_E(copy, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE, PPC2_ISA300),
>>   GEN_HANDLER_E(cp_abort, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
>> diff --git a/target/ppc/translate/fixedpoint-impl.c.inc b/target/ppc/translate/fixedpoint-impl.c.inc
>> index a75279022c..cef67d6431 100644
>> --- a/target/ppc/translate/fixedpoint-impl.c.inc
>> +++ b/target/ppc/translate/fixedpoint-impl.c.inc
>> @@ -17,6 +17,46 @@
>>    * License along with this library; if not, see <http://www.gnu.org/licenses/>.
>>    */
>>   
>> +/*
>> + * Byte-Reverse Instructions
>> + */
>> +static bool do_byte_reverse_X_sa(DisasContext *ctx, arg_X_sa *a, int kind)
>> +{
>> +#if defined(TARGET_PPC64)
>> +    switch (kind) {
>> +    case 0: /* brd */
>> +        tcg_gen_bswap64_i64(cpu_gpr[a->ra], cpu_gpr[a->rs]);
>> +        break;
>> +    case 1: /* brw */
>> +        tcg_gen_bswap64_i64(cpu_gpr[a->ra], cpu_gpr[a->rs]);
>> +        tcg_gen_rotli_i64(cpu_gpr[a->ra], cpu_gpr[a->ra], 32);
>> +        break;
>> +    case 2: /* brh */
>> +    {
>> +        TCGv_i64 mask = tcg_constant_i64(0x00ff00ff00ff00ffull);
>> +        TCGv_i64 t1 = tcg_temp_new_i64();
>> +        TCGv_i64 t2 = tcg_temp_new_i64();
>> +
>> +        tcg_gen_shri_i64(t1, cpu_gpr[a->rs], 8);
>> +        tcg_gen_and_i64(t2, t1, mask);
>> +        tcg_gen_and_i64(t1, cpu_gpr[a->rs], mask);
>> +        tcg_gen_shli_i64(t1, t1, 8);
>> +        tcg_gen_or_i64(cpu_gpr[a->ra], t1, t2);
>> +        break;
>> +    }
>> +    default:
>> +        g_assert_not_reached();
>> +    }
>> +#else
>> +    qemu_build_not_reached();
>> +#endif
>> +    return true;
>> +}
>> +
>> +TRANS64_FLAGS2(ISA310, BRD, do_byte_reverse_X_sa, 0)
>> +TRANS64_FLAGS2(ISA310, BRW, do_byte_reverse_X_sa, 1)
>> +TRANS64_FLAGS2(ISA310, BRH, do_byte_reverse_X_sa, 2)
> The kind values 0, 1, 2 are opaque at the call site — a reader has to
> cross-reference the switch inside do_byte_reverse_X_sa to know which is
> which. The more common pattern in this series is three small separate
> translators, which avoids the switch entirely and is self-documenting:
>
> static bool trans_BRD(DisasContext *ctx, arg_BRD *a)
> {
>      REQUIRE_64BIT(ctx);
>      REQUIRE_INSNS_FLAGS2(ctx, ISA310);
>      tcg_gen_bswap64_i64(cpu_gpr[a->ra], cpu_gpr[a->rs]);
>      return true;
> }
>
> ...and similarly for BRW and BRH. This also eliminates the
> do_byte_reverse_X_sa wrapper and the #else qemu_build_not_reached()
> block entirely, since REQUIRE_64BIT already handles 32-bit builds.
Separating the trans_XXX handlers as suggested but preserving #if 
defined (TARGET_PPC64) and #else qemu_build_not_reached() blocks in 
them, since REQUIRE_64B is a run time check. #if defined (TARGET_PPC64) 
is required during compilation.
>
> ~Amit
>


  reply	other threads:[~2026-08-27 10:52 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26  5:08 [PATCH v2 00/37] target/ppc: PPC TCG Improvements (decodetree migrations + ISA 2.07 flag updates) Chinmay Rath
2026-08-26  5:08 ` [PATCH v2 01/37] target/ppc: Migrate extswsli to decodetree Chinmay Rath
2026-08-26  7:33   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 02/37] target/ppc: Migrate atomic loads " Chinmay Rath
2026-08-26  9:20   ` Amit Machhiwal
2026-08-26 12:28     ` Chinmay Rath
2026-08-26 12:30       ` Chinmay Rath
2026-08-26  5:08 ` [PATCH v2 03/37] target/ppc: Convert cache instructions " Chinmay Rath
2026-08-26 10:20   ` Amit Machhiwal
2026-08-26 13:09     ` Chinmay Rath
2026-08-26 13:17       ` Amit Machhiwal
2026-08-27  9:13       ` Chinmay Rath
2026-08-27  8:37     ` Chinmay Rath
2026-08-26  5:08 ` [PATCH v2 04/37] target/ppc: Move vector merge " Chinmay Rath
2026-08-26 10:57   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 05/37] target/ppc: Move vector pack " Chinmay Rath
2026-08-26 11:04   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 06/37] target/ppc: Move st{b, h, w, d, q}cx " Chinmay Rath
2026-08-26 11:18   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 07/37] target/ppc: convert slw, srw instruction via decode spec Chinmay Rath
2026-08-26 11:28   ` Amit Machhiwal
2026-08-26 11:30     ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 08/37] target/ppc: convert sraw[i] " Chinmay Rath
2026-08-26 11:41   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 09/37] target/ppc: Convert mcrf to decode tree Chinmay Rath
2026-08-26 11:52   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 10/37] target/ppc: Move fixed-point Shift insns to decodetree Chinmay Rath
2026-08-26  5:08 ` [PATCH v2 11/37] target/ppc: Move fixed-point byte-reversal store " Chinmay Rath
2026-08-26  5:08 ` [PATCH v2 12/37] target/ppc: Move GPR atomic load/store instructions " Chinmay Rath
2026-08-26 12:05   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 13/37] target/ppc: Move isync instruction " Chinmay Rath
2026-08-26 12:20   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 14/37] target/ppc: Convert b{a, l, la} to decode tree Chinmay Rath
2026-08-26 12:24   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 15/37] target/ppc: move various conditional branch insns to decodetree Chinmay Rath
2026-08-26 12:38   ` Amit Machhiwal
2026-08-26 12:45   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 16/37] target/ppc: Fix TRANS* macro variadic arguments handling Chinmay Rath
2026-08-26 12:50   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 17/37] target/ppc: Move wait instruction to decodetree Chinmay Rath
2026-08-26 13:12   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 18/37] target/ppc: Move sleep & friends " Chinmay Rath
2026-08-26 13:26   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 19/37] target/ppc: Refactor sleep and its variants to use a common helper Chinmay Rath
2026-08-26 13:38   ` Amit Machhiwal
2026-08-26 14:30   ` Miles Glenn
2026-08-26  5:08 ` [PATCH v2 20/37] target/ppc: Move Condition Register access instructions to decodetree Chinmay Rath
2026-08-26 14:24   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 21/37] target/ppc: Move Condition Register logical " Chinmay Rath
2026-08-26 14:43   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 22/37] target/ppc: make do_ea_calc_ra available for 32 bit builds Chinmay Rath
2026-08-26 14:48   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 23/37] target/ppc: Move Fixed-Point Load/Store String instructions to decodetree Chinmay Rath
2026-08-26 15:19   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 24/37] target/ppc: Move VMX integer arithmetic and BCD " Chinmay Rath
2026-08-26 15:30   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 25/37] target/ppc: Move rlwimi, rlwinm " Chinmay Rath
2026-08-26 15:41   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 26/37] target/ppc: Move lmw, stmw " Chinmay Rath
2026-08-26 15:44   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 27/37] target/ppc: Move mfmsr, mtmsr[d] " Chinmay Rath
2026-08-26 15:49   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 28/37] target/ppc: Move byte-reverse " Chinmay Rath
2026-08-26 15:54   ` Amit Machhiwal
2026-08-27 10:52     ` Chinmay Rath [this message]
2026-08-26  5:08 ` [PATCH v2 29/37] target/ppc: Move system call and rfi " Chinmay Rath
2026-08-26 16:54   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 30/37] target/ppc: Replace PPC2_VSX207 flag with PPC2_ISA207 Chinmay Rath
2026-08-26 16:56   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 31/37] target/ppc: Use PPC2_ISA207 instead of PPC2_BCTAR_ISA207 Chinmay Rath
2026-08-26 16:58   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 32/37] target/ppc: Use PPC2_ISA207 instead of PPC2_LSQ_ISA207 Chinmay Rath
2026-08-26 17:01   ` Amit Machhiwal
2026-08-26  5:08 ` [PATCH v2 33/37] target/ppc: Use PPC2_ISA207 instead of PPC2_ALTIVEC_207 Chinmay Rath
2026-08-26 17:23   ` Amit Machhiwal
2026-08-26  5:09 ` [PATCH v2 34/37] target/ppc: Use PPC2_ISA207 instead of PPC2_ISA207S Chinmay Rath
2026-08-26  5:09 ` [PATCH v2 35/37] target/ppc: Reorder PPC2 flags Chinmay Rath
2026-08-26  5:09 ` [PATCH v2 36/37] target/ppc: Add ICBT support for ISA version 2.07 Chinmay Rath
2026-08-26  5:09 ` [PATCH v2 37/37] target/ppc: Add self as maintainer for PowerPC TCG CPUs Chinmay Rath
2026-08-26  5:41   ` Amit Machhiwal
2026-08-26  6:25   ` Gautam Menghani
2026-08-26  9:37   ` Aditya Gupta
2026-08-27  9:50 ` [PATCH v2 00/37] target/ppc: PPC TCG Improvements (decodetree migrations + ISA 2.07 flag updates) Aniket Sahu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77f33b73-90f5-4fa4-b894-c5ae55ccf99b@linux.ibm.com \
    --to=rathc@linux.ibm.com \
    --cc=amachhiw@linux.ibm.com \
    --cc=harshpb@linux.ibm.com \
    --cc=milesg@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=vishalc@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.