From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id C218D3858CD1 for ; Sun, 7 Jan 2024 15:10:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C218D3858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hesbynett.no Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C218D3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=116.202.254.214 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704640231; cv=none; b=xfoffFbhPCa+sEYZH/xner1UQA+bzLLrWq9E6Y1rrmmAIjxNLUy49s7nypVj51PNVmrLMnyWAsqmVV96QIT9DAIl1uH25Py6IuUxr1vtwPxhD6w6bI0cxrMu5cVivWzyaq/3CVyDh27j+trxDD9s8kUizifz/C3YdvyXiaTs79E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704640231; c=relaxed/simple; bh=F3eDqXqyWlNi/uCrdfv9X8QYxccy+ooU9KZmLyDMApA=; h=To:From:Subject:Date:Message-ID:Mime-Version; b=UlwYfk4DXW63Mcqkapn9DXiCVom7T2bqLhljHTfw7rAeEvo1p2BDYHWDHhApb0GSUMivKDs2DdAKao+eu67T9hNe39q7lyHUCXNpEjfWOMGjd3Ay6/bkuFMhgTG/kXMDU/tmknTH3b8QPpRl9BUraP/Bw6N2NazlvnhNjfUgR2U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1rMUnB-0007oG-NR for gcc-help@gcc.gnu.org; Sun, 07 Jan 2024 16:10:25 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-help@gcc.gnu.org From: David Brown Subject: Re: Odd error with the "X" inline assembly constraint Date: Sun, 7 Jan 2024 16:10:21 +0100 Message-ID: References: <20240105184612.GE19790@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla Thunderbird Content-Language: en-GB In-Reply-To: <20240105184612.GE19790@gate.crashing.org> X-Spam-Status: No, score=-3030.6 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 05/01/2024 19:46, Segher Boessenkool wrote: > On Fri, Jan 05, 2024 at 05:30:51PM +0100, David Brown via Gcc-help wrote: >> However, when I use just "asm ("" : "+X" (x));", I get an error message >> "error: inconsistent operand constraints in an 'asm'". I have no idea >> why this is an issue. > > The C constraint means "Any operand whatsoever is allowed." Here you > are saying to use it both as input and as output, and GCC does not know > how to reload wherever it chose to put it. > It doesn't need to reload it - the "+" says it will be read, then possibly changed and returned in the same place. It is geared towards inline assembly that modifies something - you'd use it for the "x" in assembly doing "x += a;", unlike for "x = a + b;". No reloads are needed because the same register or memory address is used for input and output. > Using "X" for outputs is strange already, fwiw, but tieing it to an > input is, hrm, let's call it "creative" :-) Sure, this is a little "creative". After all, the assembly template itself is intentionally blank. It is similar in principal to the commonly used asm("" ::: "memory") barrier. It is an example of fully portable assembly! > >> I'd imagine that the "X" operand doesn't see much use in real inline >> assembly > > It is used rather often. But usually for inputs, and (as you found out) > trying to use if for an input and for an output at the same time does > not work reliably. > > "+" really creates two operands, and ties them together. Writing > asm("oink" : "+X"(bla)); > is shorthand for > asm("oink" : "=X"(bla) : "0"(bla)); > I don't know if these are /exactly/ the same, but they are certainly similar. I can't see any reason for there to be a special issue with "X" here. I have not seen any complications with "g", meaning "general-purpose register or memory". But sometimes data can be in a register that is not general-purpose - such as a floating point register, or a SIMD register - and then I'd rather not have extra instructions added to force it to fit a "g" operand.