From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9DD8606A322 for ; Thu, 3 Dec 2026 09:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtTLCCgA Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jg8lx5mx5z2xL4; Thu, 03 Dec 2026 20:41:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=172.234.252.31 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1796290909; cv=none; b=fgXPVH/CUMPeZdeFtVeiqmXNX751OV/xXfZdJZzC67z8m9ra9o4hG3h1V+0xbLlpsmK0IkWAxu0YTEdLeUb1Igq0BPxLV3savtIbn3lz64xJrlDrcG85Yl3XHRMEGx0DMSiSZqAjswQvwmsYvcm7YLdw0jk4yOt7OjPU7/VFW3uM/Xp/B8mOsONeX/xWf6vgl7GgYqXWGJeX/BHgGIHa0pIk3zgRVW4C7nvvb6WYx5Azek8URmlb2Rth/SrNe9xU9/ix4/aLAXTS5tMy0V/XQMi1Nu+0k30Q8nGWWUOCVBBOqnd9iJ9vLMvlk2tbi8pt4Nxv1vrAVcApzngcHv4Nmw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1796290909; c=relaxed/relaxed; bh=E8yItthxEGpNKxO4V1u22xeKpjOW/FL7zCSi5I6vDPI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aCFIQz6Z82KkDPsGX+IvevrxhVL2h2SnPURFxaP/c31XYI2wBfa4L1L/6X8L+M7xNfhQbyteKSQAwHVwPAVjezN1fcNEbWxZW7cUeWFKUK540a7H3iwBxF9Uwm/5mesY7RDPvq4dx2bt2cniaDa8sPEp81xQn3wRueLXm3KjrfdDpGw82PwkCyW4EBfJaylvIJW6XkGBfiKUZSFhoWiUQt2Ga2BgLqwMTD60L+KDw0q3lKy+AYGgeDLQEL1vKTjm17ukEjZns+IHOJY7RSAmPKKaaHe8kMTLDe3XEWNkk+Aj+dgOIMRLg0I5MTXTEm8J/MBLy01+fg5aTzcMrle+9w== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtTLCCgA; dkim-atps=neutral; spf=pass (client-ip=172.234.252.31; helo=sea.source.kernel.org; envelope-from=chleroy@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtTLCCgA; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=172.234.252.31; helo=sea.source.kernel.org; envelope-from=chleroy@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jg8lw1TJcz2xGw for ; Thu, 03 Dec 2026 20:41:48 +1100 (AEDT) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 149EE443E6; Thu, 3 Dec 2026 09:41:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 266E91F00893; Thu, 3 Dec 2026 09:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796290904; bh=E8yItthxEGpNKxO4V1u22xeKpjOW/FL7zCSi5I6vDPI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=GtTLCCgA5Bap2VqSoxAgNgnGD+u7MLqC5L0ycbU9NsxX/hqXRq4cKmXbxJ/DZqlYG I8/U2PNRr4k8yFdwfNAikW+TRQuiptWZRPc+IHz47LDyKhtohvEB1Pav5rrIl6saws XIb5K7hJqv7s4ZEo9KEFxSKDm96mKLHg0xfSgfch6yPEOnb0vMitSIXm6cIdC4MIes TOqw5Vx8VgrBLX3HEcrBG4McALLBeG5Xyg6bJapa+B31w6ryUX3Wt7bZqbNCe4WOg2 5rY/dgrOnoY8NiCa7EPJuyg9KKI2pX2Vrik0S5L481lgPZpSwc+KEgw6y7m5zLcMge +vfkbWWro3OVg== Message-ID: <30fbd121-8ada-4619-bb61-08ded9af6268@kernel.org> Date: Thu, 3 Dec 2026 10:41:27 +0100 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg To: David Laight Cc: "Nysal Jan K.A." , linuxppc-dev@lists.ozlabs.org, Jeevitha Palanisamy , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Ritesh Harjani (IBM)" , Shrikanth Hegde , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , "David Hildenbrand (Arm)" , Ryan Roberts , Andreas Larsson , Usama Arif , Kevin Brodsky , "Kiryl Shutsemau (Meta)" , linux-kernel@vger.kernel.org, llvm@lists.linux.dev References: <20261125174035.1412724-1-nysal@linux.ibm.com> <20261125174035.1412724-2-nysal@linux.ibm.com> <82516881-5ffa-40f6-9d6a-549fcbb0ab00@kernel.org> <20261202095747.0009eb79@pumpkin> <2b03573f-da09-479c-a87d-6ac41737caa8@kernel.org> <20261202175227.68aedaa6@pumpkin> Content-Language: fr-FR From: "Christophe Leroy (CS GROUP)" In-Reply-To: <20261202175227.68aedaa6@pumpkin> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Le 02/12/2026 à 18:52, David Laight a écrit : > On Wed, 2 Dec 2026 11:13:24 +0100 > "Christophe Leroy (CS GROUP)" wrote: > >> Le 02/12/2026 à 10:57, David Laight a écrit : >>> On Mon, 30 Nov 2026 18:58:11 +0100 >>> "Christophe Leroy (CS GROUP)" wrote: >>> >>>> Why a memory clobber ? Is it to get a barrier ? Otherwise I see no >>>> direct hidden memory modification in the sequence. >>> >>> I found something horrid during testing: >>> The compiler (gcc) will spill the value of a memory operand to stack. >>> So: >>> long f(long *p) >>> { >>> register long x asm("r3"); >>> >>> asm( "opcode %[x],%[p]" : [x] "=&r" (x) : [p] "m" (*p)); >>> return x; >>> } >>> compiles to: >>> f: >>> ld 9,0(3) >>> std 9,-16(1) >>> ori 2,2,0 >>> opcode 3,-16(1) >>> blr >> >> What 'opcode' is that ? Because powerpc is a RISC processor, there is no >> way ALU operation can operate on something else than registers. > > A memory read would do. > I was playing around trying to get the compiler to generate addressing > modes that lq doesn't support. > The point is that the asm block isn't given a reference to the address > it expects. > It also means that the size of the variable has to be right. > If it can do the same for an output then asm blocks that try to do > atomic operations will do them on a copy. > > Or consider (with -mno-altivec) this: > u128 f(int xx, u128 *p) > { > register u128 x asm("r4"); > > asm( "lq %[x],%[p]" : [x] "=&r" (x) : [p] "m" (*p)); > return x; > } > generates: > f: > ld 9,0(4) > ld 10,8(4) > std 9,-16(1) > std 10,-8(1) > ori 2,2,0 > lq 4,-16(1) > mr 3,4 > mr 4,5 > blr > > A little contrived and the byte order is wrong but it is failing to > do the expected atomic read of the 128bit value. Looks like the "m" generates the copy. When you use "+m" it doesn't. By the way you should use "+Q" instead of "+m" I think. With: u128 f(int xx, u128 *p) { register u128 x asm("r4"); asm volatile("lq %[x],%[mem]" : [x] "=&r" (x), [mem] "+Q" (*p)); return x; } I get 0000000000005490 : 5490: 78 23 89 7c mr r9,r4 5494: 00 00 89 e0 lq r4,0(r9) 5498: 78 23 83 7c mr r3,r4 549c: 78 2b a4 7c mr r4,r5 54a0: 20 00 80 4e blr Christophe