Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2810DC61DBD for ; Wed, 26 Aug 2026 12:29:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzCkM-0006CX-3y; Wed, 26 Aug 2026 08:28:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wzCkK-0006C5-NE; Wed, 26 Aug 2026 08:28:48 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wzCkI-00025a-Hp; Wed, 26 Aug 2026 08:28:48 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67QAWBaS2615471; Wed, 26 Aug 2026 12:28:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=sjuKTI BCZVbEV93CcZJf4bhGtw472WXq/7GutbwA/wA=; b=rGvtq4BUYcSFCxlGwWH7XT EbtlGI4A9StEGQ8zpt2U4DzgeUtg6anrF8DMwFROmPmJCV68pSMu3LavVoWCPord TSPJCF3wIGBxwv00MNJxjKd4xrWB38C+E67KIpo4JfLdcwNTrcRhJt5iZzlLb0Vp rWMgnoyI/v1aBgRXf2P++gtO/mxN4sDSLqLAmVx8qbpR9tBXqgDUHQZbz0G1k8c3 Rcp8nDclzTOheROC4JE2wVXxgVeoi2P5vAUh/2lPEC0yqvtJCbc079uTfKC0/irJ BSR/vvC/dCIslO+87NiJ/koecZ9QHCsvwH93JpBvU40S4RW4N9UZlrnX+YUYv2/Q == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g726epfu8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Aug 2026 12:28:42 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67QCQGlT016727; Wed, 26 Aug 2026 12:28:41 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g7p3qa2r9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Aug 2026 12:28:41 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67QCSeKC2556550 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Aug 2026 12:28:40 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C916E58058; Wed, 26 Aug 2026 12:28:40 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8053258057; Wed, 26 Aug 2026 12:28:37 +0000 (GMT) Received: from [9.111.28.250] (unknown [9.111.28.250]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 26 Aug 2026 12:28:36 +0000 (GMT) Message-ID: <2bdd4d82-49ec-4de6-8868-31a6e0c377da@linux.ibm.com> Date: Wed, 26 Aug 2026 17:58:34 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 02/37] target/ppc: Migrate atomic loads to decodetree To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, harshpb@linux.ibm.com, milesg@linux.ibm.com, npiggin@gmail.com, richard.henderson@linaro.org References: <20260826050923.74756-1-rathc@linux.ibm.com> <20260826050923.74756-3-rathc@linux.ibm.com> <20260826140945.286298f2-fa-amachhiw@linux.ibm.com> Content-Language: en-US From: Chinmay Rath In-Reply-To: <20260826140945.286298f2-fa-amachhiw@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=TfimcxQh c=1 sm=1 tr=0 ts=6a8edbfa cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=AzRaCOm2d27KreSwJzIA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI2MDEwMCBTYWx0ZWRfX+MTijZxFJFN3 V8sUXgktS+KQ8KJMfNtP26QJzEsm7YJBu5E5TgXIJN0c0hvbESV6yV5EBj5iqLfGDpwKNW18Rw4 8pxjV95muodVH/aJzLSWY4mqjNBwL/Q= X-Proofpoint-GUID: 9UJpxMeZQDOqg3MFyzUCGLcbOqqONuGS X-Proofpoint-ORIG-GUID: fQz7TRaTZT7T8rEuaFe2mFzumwBwc_P2 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI2MDEwMCBTYWx0ZWRfX4qDmxb28XArf oS4DFfaTFk0TpB1bZ3p4rkxOpu27SOuvFEPxaqvMmhMngwiRuKJSeh9w8g3eqhLOdoXwgS6aAs+ eOVh0ksXgQc8EU1p7kItHA6Nj6DCvw61V8YBs6f/C7086QeQXxdtzfPT1fAS5EzrrUe+pCCEC2H kvTIBwHEoHGF7b2foZbytTFm0QaM5qWizXpx0U/4GEYMLS0J6szCZYzpTenUWjhctRAukZrJ4r+ TGOeVv7DtC7UNwCv4HMvd9ElC6SJq73ad1VHnNyWXE4r/Ge0Cp8igNgue9yecztlXZW8SVddJdg 4M1jk+yLT0h2gX+3Sh40QkS6lKU5nSSSGql30Mv9mtMAp4LrB5Kta3l1lBPDHwfdh2foDslquqO idhSpCXdtPX30Qp6S5xYYpMVveefb76/ivYLBzkT2vL0LMNgUU7x2TgH0HCXNw8XhOufkFcGI/q vqmXyRZIYVuDPHCH/PQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-26_03,2026-08-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608260100 Received-SPF: pass client-ip=148.163.158.5; envelope-from=rathc@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 8/26/26 14:50, Amit Machhiwal wrote: > On 2026/08/26 10:38 AM, Chinmay Rath wrote: >> From: Nikhil Kumar Singh >> >> Migrate load-and-reserve instructions (lbarx, lharx, lwarx, ldarx, >> lqarx) to decodetree using the X-form layout. >> >> A shared helper (do_load_locked) is introduced for standard-width >> variants, while LQARX is handled separately due to its 128-bit >> semantics and register pairing constraints. >> >> The implementation preserves legacy behavior, including: >> - Reservation granularity and overwrite semantics >> - Alignment requirements >> - Invalid instruction cases for LQARX >> >> Testing: >> - Verified TCG equivalence with legacy implementation >> >> Signed-off-by: Nikhil Kumar Singh >> Reviewed-by: Glenn Miles >> Signed-off-by: Chinmay Rath >> --- >> target/ppc/insn32.decode | 7 +++ >> target/ppc/translate.c | 124 +++++++++++++++++++-------------------- >> 2 files changed, 69 insertions(+), 62 deletions(-) >> >> diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode >> index 342e65dadf..26948e08a7 100644 >> --- a/target/ppc/insn32.decode >> +++ b/target/ppc/insn32.decode >> @@ -1309,6 +1309,13 @@ XVF64GERNN 111011 ... -- .... 0 ..... 11111010 ..- @XX3_at xa=%xx_xa_pair >> ##Extend Sign Word and Shift Left Immediate XS-form >> EXTSWSLI 011111 ..... ..... ..... 110111101 . . @XS >> >> +## Load and Reserve Instructions >> +LBARX 011111 ..... ..... ..... 0000110100 . @X_rc >> +LHARX 011111 ..... ..... ..... 0001110100 . @X_rc >> +LWARX 011111 ..... ..... ..... 0000010100 . @X_rc >> +LDARX 011111 ..... ..... ..... 0001010100 . @X_rc >> +LQARX 011111 ..... ..... ..... 0100010100 . @X_rc >> + >> ## Vector Division Instructions >> >> VDIVSW 000100 ..... ..... ..... 00110001011 @VX >> diff --git a/target/ppc/translate.c b/target/ppc/translate.c >> index e627f48f9e..cc9287dcc5 100644 >> --- a/target/ppc/translate.c >> +++ b/target/ppc/translate.c >> @@ -2947,30 +2947,6 @@ static void gen_isync(DisasContext *ctx) >> ctx->base.is_jmp = DISAS_EXIT_UPDATE; >> } >> >> -static void gen_load_locked(DisasContext *ctx, MemOp memop) >> -{ >> - TCGv gpr = cpu_gpr[rD(ctx->opcode)]; >> - TCGv t0 = tcg_temp_new(); >> - >> - gen_set_access_type(ctx, ACCESS_RES); >> - gen_addr_reg_index(ctx, t0); >> - tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, DEF_MEMOP(memop) | MO_ALIGN); >> - tcg_gen_mov_tl(cpu_reserve, t0); >> - tcg_gen_movi_tl(cpu_reserve_length, memop_size(memop)); >> - tcg_gen_mov_tl(cpu_reserve_val, gpr); >> -} >> - >> -#define LARX(name, memop) \ >> -static void gen_##name(DisasContext *ctx) \ >> -{ \ >> - gen_load_locked(ctx, memop); \ >> -} >> - >> -/* lwarx */ >> -LARX(lbarx, MO_UB) >> -LARX(lharx, MO_UW) >> -LARX(lwarx, MO_UL) >> - >> static void gen_fetch_inc_conditional(DisasContext *ctx, MemOp memop, >> TCGv EA, TCGCond cond, int addend) >> { >> @@ -3219,42 +3195,9 @@ STCX(sthcx_, MO_UW) >> STCX(stwcx_, MO_UL) >> >> #if defined(TARGET_PPC64) >> -/* ldarx */ >> -LARX(ldarx, MO_UQ) >> /* stdcx. */ >> STCX(stdcx_, MO_UQ) >> >> -/* lqarx */ >> -static void gen_lqarx(DisasContext *ctx) >> -{ >> - int rd = rD(ctx->opcode); >> - TCGv EA, hi, lo; >> - TCGv_i128 t16; >> - >> - if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) || >> - (rd == rB(ctx->opcode)))) { >> - gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); >> - return; >> - } >> - >> - gen_set_access_type(ctx, ACCESS_RES); >> - EA = tcg_temp_new(); >> - gen_addr_reg_index(ctx, EA); >> - >> - /* Note that the low part is always in RD+1, even in LE mode. */ >> - lo = cpu_gpr[rd + 1]; >> - hi = cpu_gpr[rd]; >> - >> - t16 = tcg_temp_new_i128(); >> - tcg_gen_qemu_ld_i128(t16, EA, ctx->mem_idx, DEF_MEMOP(MO_128 | MO_ALIGN)); >> - tcg_gen_extr_i128_i64(lo, hi, t16); >> - >> - tcg_gen_mov_tl(cpu_reserve, EA); >> - tcg_gen_movi_tl(cpu_reserve_length, 16); >> - tcg_gen_st_tl(hi, tcg_env, offsetof(CPUPPCState, reserve_val)); >> - tcg_gen_st_tl(lo, tcg_env, offsetof(CPUPPCState, reserve_val2)); >> -} >> - >> /* stqcx. */ >> static void gen_stqcx_(DisasContext *ctx) >> { >> @@ -5741,6 +5684,68 @@ static bool trans_EXTSWSLI(DisasContext *ctx, arg_XS *a) >> return true; >> } >> >> +/* >> + * Load-and-reserve core >> + */ >> +static bool do_load_locked(DisasContext *ctx, arg_X_rc *a, MemOp memop) >> +{ >> + TCGv EA = do_ea_calc(ctx, a->ra, cpu_gpr[a->rb]); >> + TCGv gpr = cpu_gpr[a->rt]; >> + >> + gen_set_access_type(ctx, ACCESS_RES); >> + >> + tcg_gen_qemu_ld_tl(gpr, EA, ctx->mem_idx, memop | MO_ALIGN); >> + >> + tcg_gen_mov_tl(cpu_reserve, EA); >> + tcg_gen_movi_tl(cpu_reserve_length, memop_size(memop)); >> + >> + tcg_gen_mov_tl(cpu_reserve_val, gpr); >> + >> + return true; >> +} >> + >> +TRANS_FLAGS2(ATOMIC_ISA206, LBARX, do_load_locked, DEF_MEMOP(MO_UB)) >> +TRANS_FLAGS2(ATOMIC_ISA206, LHARX, do_load_locked, DEF_MEMOP(MO_UW)) >> +TRANS(LWARX, do_load_locked, DEF_MEMOP(MO_UL)) >> +TRANS64(LDARX, do_load_locked, DEF_MEMOP(MO_UQ)) >> + >> +static bool trans_LQARX(DisasContext *ctx, arg_LQARX *a) >> +{ >> + REQUIRE_64BIT(ctx); >> + REQUIRE_INSNS_FLAGS2(ctx, ISA207S); > The old GEN_HANDLER_E used PPC2_LSQ_ISA207, but the new code uses > PPC2_ISA207S . In the current QEMU CPU model set this makes no practical > difference — every CPU that sets PPC2_ISA207S also sets PPC2_LSQ_ISA207. > However, PPC2_LSQ_ISA207 is the precise flag for this feature and keeps > lqarx symmetric with its companion stqcx_ (line 5870) which correctly > continues to use PPC2_LSQ_ISA207. Please use REQUIRE_INSNS_FLAGS2(ctx, > LSQ_ISA207) for consistency and to guard against future CPU models that > may set these flags independently Hi Amit, Nice catch ! Thanks ! In the later patches 32 and 34 in this series, I have consolidated all ISA 2.07 flags into a single flag. Hence both PPC2_LSQ_ISA207 and PPC2_ISA207S are replaced by PPC2_ISA207, hence this is automatically taken care of. Regards, Chinmay > >> +#if defined(TARGET_PPC64) >> + TCGv EA; >> + TCGv_i128 t16; >> + /* Must use even register and avoid overlap */ >> + if (unlikely((a->rt & 1) || (a->rt == a->ra) || (a->rt == a->rb))) { >> + gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); >> + return true; >> + } >> + >> + gen_set_access_type(ctx, ACCESS_RES); >> + EA = do_ea_calc(ctx, a->ra, cpu_gpr[a->rb]); >> + t16 = tcg_temp_new_i128(); >> + >> + tcg_gen_qemu_ld_i128(t16, EA, ctx->mem_idx, >> + DEF_MEMOP(MO_128 | MO_ALIGN)); >> + >> + tcg_gen_extr_i128_i64(cpu_gpr[a->rt + 1], >> + cpu_gpr[a->rt], >> + t16); >> + >> + tcg_gen_mov_tl(cpu_reserve, EA); >> + tcg_gen_movi_tl(cpu_reserve_length, 16); >> + >> + tcg_gen_st_i64(cpu_gpr[a->rt], >> + tcg_env, offsetof(CPUPPCState, reserve_val)); > All these multi-line calls can be collapsed to single lines — they are > within 80 characters respectively and fit within the 80-column limit. > The only exception is tcg_gen_st_i64(..., reserve_val2) at 85 chars, > which legitimately needs wrapping. The unnecessary line splits add > visual noise without any readability benefit. > >> + tcg_gen_st_i64(cpu_gpr[a->rt + 1], >> + tcg_env, offsetof(CPUPPCState, reserve_val2)); >> +#else >> + qemu_build_not_reached(); >> +#endif >> + return true; >> +} >> + >> #include "translate/fixedpoint-impl.c.inc" >> >> #include "translate/fp-impl.c.inc" >> @@ -5853,9 +5858,6 @@ GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), >> GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), >> GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), >> GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), >> -GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206), >> -GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206), >> -GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), >> GEN_HANDLER_E(lwat, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE, PPC2_ISA300), >> GEN_HANDLER_E(stwat, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE, PPC2_ISA300), >> GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206), >> @@ -5864,8 +5866,6 @@ GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), >> #if defined(TARGET_PPC64) >> GEN_HANDLER_E(ldat, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE, PPC2_ISA300), >> GEN_HANDLER_E(stdat, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE, PPC2_ISA300), >> -GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), >> -GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207), >> GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), >> GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207), >> #endif >> -- >> 2.55.0 >>