Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2771627pxj; Sun, 6 Jun 2021 13:32:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZeUn5DBIxZxnOW72FBNJiSBo9tYEbb6LSVAAQGvQAIpmJcOlWf2poHjY+vs+GSWRb2ByA X-Received: by 2002:a05:6402:40c:: with SMTP id q12mr16437007edv.0.1623011545569; Sun, 06 Jun 2021 13:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623011545; cv=none; d=google.com; s=arc-20160816; b=W7B2BKh+ZpXpKVetSvrQp5UeuMeF7E2cF/l0LfV8c9mgqvTJ90aPnF867EyVQnfEPa iJfkqq2ery98dhYxqoKpEeXp0JZny8Gtt+1pY/528u2y4YqeneSm/79orcUUlbOiDeRA JoXj0MMEfLT/VUrmYYpHXT/Vf9rKlaqlQ3EuWqynX7rEMoOX3GC5ZW+ZAWIRj54SLAvL B3HnhxY2Yva//NJlso7I1ai+4Ahmku5RZY/tMiaEB6mBLhREyw93QNxRyyf6Z4IzEqDy G2Y8hsPG5vq1fTZnTQ18hUQXS82pr3YW68LvCvw3hVPvMB7QOUFfRxin+m8VG9t12UXy HV3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=wwMW5o+UFbBHFid8fK5HBBtc3wsY1pNKKnf0zeMMfiw=; b=R1E0eVp0lJ6R15LcFc/UqE7ZJ4eecHSHzatfwEwTRPPsBxPBmf0NZMFz0xhT1R+RqU 64utkujuumjl1bebIpF0WQCw5XrafHC8UGymAtE4a1+3xYnEV5LQnFhH6kOf+2tzNRHq 658Mt2VBaPulxBtw8UoVzHjlo/gSg4uimLgPGOCIsrd9oVfIPx805W6AAIr2EHHHoPvC oHrysSwTiX+yBDftMUQ+sYFlKyG+e9R57W362pURtxrtsi+qY0aX7xsjQc4FmRR7PWBC ImbfujhRYbLf/EOr1yc6/tanyU4L3239k3VcFau5gtYPpqxJ2sdoyA+YJAeQGxGkj5pY /Zkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s2si10200929edt.551.2021.06.06.13.32.03; Sun, 06 Jun 2021 13:32:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbhFFUc0 (ORCPT + 99 others); Sun, 6 Jun 2021 16:32:26 -0400 Received: from gate.crashing.org ([63.228.1.57]:54568 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbhFFUcZ (ORCPT ); Sun, 6 Jun 2021 16:32:25 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 156KQInJ013180; Sun, 6 Jun 2021 15:26:18 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 156KQGXe013177; Sun, 6 Jun 2021 15:26:16 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Sun, 6 Jun 2021 15:26:16 -0500 From: Segher Boessenkool To: Linus Torvalds Cc: Alan Stern , "Paul E. McKenney" , Peter Zijlstra , Will Deacon , Andrea Parri , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Linux Kernel Mailing List , linux-toolchains@vger.kernel.org, linux-arch Subject: Re: [RFC] LKMM: Add volatile_if() Message-ID: <20210606202616.GC18427@gate.crashing.org> References: <20210605145739.GB1712909@rowland.harvard.edu> <20210606001418.GH4397@paulmck-ThinkPad-P17-Gen-1> <20210606012903.GA1723421@rowland.harvard.edu> <20210606115336.GS18427@gate.crashing.org> <20210606184021.GY18427@gate.crashing.org> <20210606195242.GA18427@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 06, 2021 at 01:11:53PM -0700, Linus Torvalds wrote: > On Sun, Jun 6, 2021 at 12:56 PM Segher Boessenkool > wrote: > > > > Yes, I know. But it is literally the *only* way to *always* get a > > conditional branch: by writing one. > > The thing is, I don't actually believe you. Fortune favours the bold! > The barrier() thing can work - all we need to do is to simply make it > impossible for gcc to validly create anything but a conditional > branch. And the only foolproof way of doing that is by writing a branch. > If either side of the thing have an asm that cannot be combined, gcc > simply doesn't have any choice in the matter. There's no other valid > model than a conditional branch around it (of some sort - doing an > indirect branch that has a data dependency isn't wrong either, it just > wouldn't be something that a sane compiler would generate because it's > obviously much slower and more complicated). Or push something to the stack and return. Or rewrite the whole thing as an FSM. Or or or. (And yes, there are existing compilers that can do both of these things on some code). > We are very used to just making the compiler generate the code we > need. That is, fundamentally, what any use of inline asm is all about. > We want the compiler to generate all the common cases and all the > regular instructions. > > The conditional branch itself - and the instructions leading up to it > - are exactly those "common regular instructions" that we'd want the > compiler to generate. That is in fact more true here than for most > inline asm, exactly because there are so many different possible > combinations of conditional branches (equal, not equal, less than,..) > and so many ways to generate the code that generates the condition. > > So we are much better off letting the compiler do all that for us - > it's very much what the compiler is good at. Yes, exactly. I am saying that if you depend on that some C code you write will result in some particular machine code, without actually *forcing* the compiler to output that exact machine code, then you will be disappointed. Maybe not today, and maybe it will take years, if you are lucky. (s/forcing/instructing/ of course, compilers have feelings too!) Segher