public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>,
	Uros Bizjak <uros_bizjak1@t-2.net>,
	linux-kernel@vger.kernel.org
Cc: x86@kernel.org, Uros Bizjak <ubizjak@gmail.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: ASM flags in general
Date: Mon, 27 Jul 2015 13:38:10 -0700	[thread overview]
Message-ID: <55B696B2.3000702@kernel.org> (raw)
In-Reply-To: <55B680D8.5070702@zytor.com>

On 07/27/2015 12:04 PM, H. Peter Anvin wrote:
> On 07/27/2015 10:48 AM, Uros Bizjak wrote:
>> From: Uros Bizjak <ubizjak@gmail.com>
>>
>> This patch introduces GCC ASM flags to bitops.
>>
>> The new functionality depends on __GCC_ASM_FLAG_OUTPUTS__ preprocessor
>> symbol, which is automatically set by GCC version 6 or later when
>> ASM flags feature is supported.
>>
>> The improvement can be illustrated with following code snipped.
>> Instead of:
>>
>
> This might be a good time to bring up this proposal I made in private
> recently in public:
>
> In the next version (6.0) of gcc, there will be support for emitting
> flags as outputs from inline assembly.  We obviously want to use this,
> but I think it would be better to not have to have two copies for each
> bit of assembly, for old and new gcc.
>
> I have been thinking about it, and have checked with how gcc actually
> handles "bool" as outputs.  It turns out that using "bool" in asm output
> is perfectly well defined on x86, and is defined as a byte output which
> is required to be 0 or 1.  This is consistent with how the "set"
> instruction operates.
>
> As such, I would like to propose the following:
>
> 1. We change the actual type of the output variable for these asm
> statements to bool.
> 2. Define the following macros:
>
> #ifdef __GCC_ASM_FLAGS_OUTPUT__
>
> #define CC_SET(c)
> #define CC_OUT(c) "=@cc" #c
>
> #else
>
> #define CC_SET(c) "\n\tset" #c " %[cc_" #c "]"
> #define CC_OUT(c) [cc_ ## c] "=qm" (v)
>
> #endif
>
>
> A sample use would be something like this:
>
> unsigned long x, y, z;
> bool carry;
>
> asm("add %3,%0"
>      CC_SET(c)
>      : "=r" (z), CC_OUT(c) (carry)
>      : "0" (x), "rm" (y));
>
>
>
> I wonder if using "set" would be a performance regression over "sbb" for
> the existing bitops, in which case it would slot quite nicely into this
> scheme.
>
> I have been working in the background on a patchset for this, but as my
> life is incredibly crazy at the moment progress has been slow.  However,
> this is the way I'd like to see a patchset, with appropriate tests for
> regression in between:
>
> 1. A patchset that uses "bool" for this type of boolean outputs.
> 2. A patchset to change "sbb" to "set" where appropriate.
> 3. Introducing the above macros.
> 4. Using the macros where it makes sense.
>
> Linus also commented, quite correctly:
>
> "That said, I think we should look at actually changing some of the
> functions we use.
>
> For example, I think cmpxchg really should use ZF once we have flag
> outputs rather than comparing old and new.  That changes the whole way
> we use it.
>
> There may be other places where we might want to make those kind of
> bigger changes."
>

As long as we're thinking about this stuff, there are bunch of places 
where we use exception fixups and do awful things involving translating 
them to error codes.  Ideally they'd use as goto instead, but last time 
I checked, GCC was quite picky and didn't like output constraints and 
asm goto at the same time.  Maybe GCC could fix this at some point, but 
using condition code outputs might be reasonable, too.

Doing this would make put_user_ex and similar completely unnecessary, I 
think.

--Andy



  parent reply	other threads:[~2015-07-27 20:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-27 17:48 [PATCH v2] x86: Introduce ASM flags to bitops Uros Bizjak
2015-07-27 19:04 ` ASM flags in general H. Peter Anvin
2015-07-27 20:01   ` Uros Bizjak
2015-07-27 21:14     ` H. Peter Anvin
2015-07-27 20:38   ` Andy Lutomirski [this message]
2015-07-27 21:04     ` H. Peter Anvin
2015-07-27 22:43       ` Andy Lutomirski
     [not found]         ` <BFA94A6B-8E68-4990-8737-F1F470D47F6A@zytor.com>
2015-07-27 23:36           ` Andy Lutomirski
     [not found]             ` <E2EE4512-30B2-4E73-B91A-DC1A9AA0AF6C@zytor.com>
2015-07-27 23:49               ` Andy Lutomirski
2015-07-27 23:56                 ` H. Peter Anvin
2015-07-27 23:58                   ` Andy Lutomirski
2015-07-28  0:03                     ` H. Peter Anvin
2015-07-28  0:35                     ` H. Peter Anvin
2015-07-28  0:41                       ` Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55B696B2.3000702@kernel.org \
    --to=luto@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=ubizjak@gmail.com \
    --cc=uros_bizjak1@t-2.net \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox