From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796163626; b=lsGOVzwyMpqb0g19gu7nZTflIqIpQyKggNjGuqb54cqbS0Tq4w2LmDPbBATdvAINXdtt 6z39VcCwEQw/kZgTPVBhIwyPzQIevepa/JJTiLxJpdt0FRfMq9DNgWsSx0IwdWCC7+m8y f/uK9Bbgb12SEWugR4i3HkVQKg7631MYem3HCgref5OJsws7mtUnf39amGTABJRYMya6L TZPMDMJJO05Adtb+c6AyCNzE079TvvD+20Z2juPiXJoRFaZrud2L1rXdzGsKYT1GXl4Ub mCxnOtu9T2rvYKIkywgNegPY+JgPfeeFg54GMXZ+brbnhW4YapnGv2RPfEgv138CbyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796163626; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=9f0FGRklgS+w051l5RwetNuRSzHyXgPGAaMPGVl5TOQ=; b=qnQfVynTavAra0RTFwpup2qNKXVbASMZj9ZKod0ZmlIi2yAZYa6ESNm9yrxQw2bjJhWh GJsfO7Ka/MDR395jleVQhUBpWq9bA+ehMB2deMEVfFZKV7xJPJ5bkmkABTEjJTdwSrBUE 14HPHdDaT3LgSIyKkPOfaDh4+IoQVRRJ4SssHA0HNpUBJnl5P8yFAm/+1wdRVbRANLrJO 2MK+5ECcHq2DYEiIUlH9QENv1RQjWLpL0WlFdalt63LXoyulfKyv5KODoSXs4ZbwfXvYi ScWtTUNU9xXEQPrst9uXAcrr6H0ccOzZ3JARIGbhRZwcHnM6hezBwjcUeAsQdVKgrBA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=DSuBVV71; arc=none smtp.remote-ip=209.85.128.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A524A606A320 for ; Tue, 1 Dec 2026 22:20:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A524A606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=DSuBVV71 Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4bb6886d30aso117971945e9.3 for ; Tue, 01 Dec 2026 14:20:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796163624; x=1796768424; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=9f0FGRklgS+w051l5RwetNuRSzHyXgPGAaMPGVl5TOQ=; b=DSuBVV71X1fMkQ2Oe8W/nu+SIE/uMVrJZjv9X7wkdb0UW9d0lQ8eH/YKHNGHikDEGe lg7YL7LoY56X2cypW0/AHvWe1CZh54iDYo7vNjGtX5EEi7TE3GDTGHHJCjzYKB5cqnoN /NYd+JiNL/iW0o/S7Vj/Y/yE9HYgvMWiHcBF3ICMDkS/ahp/mkZack8NyPDYROwCVHsR GoJQvqyk5ihOZN8wdncoJL5MfR+9CAAdVH3bmsurqEB4jgDezIt4U/ThyRIzTqrSt477 h4gVWQZXqQbcklHtR5z8kG5YEax8klEea+Sr3N/NX5mIwTPPbFeyrWEGexP0Zqvy04T/ 4hRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796163624; x=1796768424; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9f0FGRklgS+w051l5RwetNuRSzHyXgPGAaMPGVl5TOQ=; b=Zdu7zqOnUFe04M9k0TUkqIYS+Ptj1Gm7/LeIZ2RsYvHywXlPOCrp5FKoVHirLdgF1V JE16aErpDF4RBTFK63TsJIN8nQwmsf42SC76D4U3AxrLgfR5uMlTUtYz671TOmyz9HfY o2Evxom0a18Ukju0aA47MyfKelws8FqWBcmTdyUMlT75YL83cAYuU7TFZ3EloJ7UQI/y TyOreKcAzD6GErp/p+Z04/T+exEIkysyZAC13s60B+7mXToXfuC0Fdv8OYsq6a6xp+0S EqlscRWhyK8NZeZZxAWgzQ7slljV/admY6GQMW4ofoQgSDFdvJZuMUbqzFkmjVQzLrrP cNBw== X-Forwarded-Encrypted: i=1; AL+hErHXyuQooYWfxuXDeU9UHEMboycjc23rny+zy2LGWfToPvhIaeUirjvhp6b+OwXoaCIueZvib2caSCX4OdU=@vger.kernel.org X-Gm-Message-State: APuU4Z+2yjsx/b6ejIX7H1shQQVKQESBx/RohLG+TIGVc9msAcuCitmN dsRs1A84PwXwlzJc1ETB5GW37w+tL2UH7BPNmY3zWMhGaiAE3RozfrQg X-Gm-Gg: AZFdTZeSGY/z1xackhvqNLsFTqugv/9Ymw3Pr4hZPo5gLow4nnJUvffefBxClckyQiw XcI3Ov0a85CZePPQGNKcMgVB00hVRm1QoZwJCW6oYcR0U694IrpmNoeRelD9kNZtEgyHe/3B8kx gyh0GPaq7EndjWsr16qZXgqq0K2qlwCBoy/6mb1jRiC8mRDBR9rK2DixQ6bBssJdSIqsWkdo7YK QW5TrnAM8BtjrHEFBT1nnzPIX5hkFSgYDIY5YWtu7sEj77A/IyY2tjkrCHJswSUNCkOAXQRKNrH TWwt7EHxWOR9w54PO02RM6QKX1jwuVP3rfyZ9erI5w5WxFYTzpysOUVcKL+MKsOAHuihhulWBBR VT2PjyRS/6RzMhxkLMqg4HN89F7F69fmjX10A9vKUYQ6hq71ZoBW08OOSdKbdCEO6QYZ0Rucj7S LzhJztYs+c0eDxRu7lDpVLfrhjRUBtzH2WcwZPV5+MKCdgmK/1sXsgHrjYn4UrxW3OkewgEDNV2 +2OnzltO/ejac4xcssXNWigD9I5DbP4dAT6djeZnrV1ygT7N85sfEK7SZBvwuSSPWdMwNSMtYpy 98RfkqTbPdQbU2xSSZEXFGvEnajuFlNqeTgd/pq44jf6uOfZl5MZ/2DE6UiWCMQa X-Received: by 2002:a05:600c:1548:b0:4a3:59c9:a756 with SMTP id 5b1f17b1804b1-4bb88800013mr813935605e9.6.1796163623793; Tue, 01 Dec 2026 14:20:23 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbb97e5356sm384941995e9.4.2026.12.01.14.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 14:20:23 -0800 (PST) Date: Tue, 1 Dec 2026 22:20:22 +0000 From: David Laight To: "Nysal Jan K.A." Cc: linuxppc-dev@lists.ozlabs.org, Jeevitha Palanisamy , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "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 Subject: Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg Message-ID: <20261201222022.166b43eb@pumpkin> In-Reply-To: <20261201170926.39183e2a@pumpkin> References: <20261125174035.1412724-1-nysal@linux.ibm.com> <20261125174035.1412724-2-nysal@linux.ibm.com> <20261126112714.021a3e66@pumpkin> <20261201144804.6a0270d5@pumpkin> <20261201145831.7d897df2@pumpkin> <20261201170926.39183e2a@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 1 Dec 2026 17:09:26 +0000 David Laight wrote: > On Tue, 1 Dec 2026 14:58:31 +0000 > David Laight wrote: > > > On Tue, 1 Dec 2026 14:48:04 +0000 > > David Laight wrote: > > > > > On Tue, 1 Dec 2026 19:22:06 +0530 > > > "Nysal Jan K.A." wrote: > > > > > > > On Thu, Nov 26, 2026 at 11:27:14AM +0000, David Laight wrote: > > > > > On Wed, 25 Nov 2026 23:10:22 +0530 > > > > > "Nysal Jan K.A." wrote: > > > > > > > > > > > > > > > > > +#ifdef CONFIG_HAVE_CMPXCHG_DOUBLE > > > > > > +union __u128_halves { > > > > > > + u128 full __mode(PTI); > > > > > > + struct { > > > > > > + u64 low, high; > > > > > > > > > > There seems to be a mismatch between the register order that PTI > > > > > assigns and the one that C uses. > > > > > It might be less confusing to swap low and high in the above > > > > > and only use 'full' (probably renamed) in the asm statement. > > > > > > > > > > > > > I can swap high and low here to indicate that it maps to the big-endian > > > > register layout if that makes it less confusing. > > > > > > But AFICT it doesn't (if I believe the AI from google for "ppc64le lq word order". > > > The high bits (from EA + 8) end up in the even register and the low bits > > > (from EA) in the odd register. > > > > But that doesn't match a test I just did on godbolt. > > If the order is backwards then you do need to swap low and high > > and only use 'full' (aka full_partially_be) for the asm constraint. > > I'm getting more confused. I don't have a cpu to test this on either. > The above AI says you can do (reg + reg), but godbolt's gcc 16.2.0 > will only assemble (reg + const*16). > See https://www.godbolt.org/z/KParbvPa7 > (and fiddle with what is assigned to [v]) > > I also found this comment in a patch to qemu: > + /* Note that the low part is always in RD+1, even in LE mode. */ > + lo = cpu_gpr[rd + 1]; > + hi = cpu_gpr[rd]; > > So it might be that gcc is actually getting it wrong. > Needs testing on a physical cpu. Answering myself again... It might 'just' be that the resister pair assignments that gcc uses for __int128 are the opposite way around the those the cpu uses for lq/stq instructions. That means that you can't use lq/stq to read/write an __int128 from memory. The asm code is all consistent L[x] accesses 'reg+1' to get the low 64 bits (ie the LE mode the cpu is inverting A3 as well as inverting the lower address bits). So I think you need something like: /* gcc assigns the registers in the opposite order to the hardware */ union reg_pair { u128 reg_pair __mode(PTI); struct { u64 high, low; }; }; and then only access high/low from C and reg_pair from the asm constraint. (It might need a bigger comment...) David > > David > > > > > David > > > > > > > > I suspect (as in the other email I just sent) that when you do: > > > u128 x; > > > > > > asm(... : "=r" (x)) > > > you are getting the register that holds the low bits of 'x'. > > > But you want the one containing the high bits so that you can use L[] > > > to reference the low bits. > > > The code might appear to work because on a function call the lower > > > register contains the low bits; so, if the register isn't reused, > > > L[x] will be the high bits. > > > > > > You might be able to tell which registers gcc thinks are 'live' > > > by adding one to the clobber list. > > > You can't add one that is in use; so it should force an alternative > > > register allocation. > > > > > > David > > > > > > > > > > > >