From: "H. Peter Anvin" <hpa@zytor.com>
To: 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: ASM flags in general
Date: Mon, 27 Jul 2015 12:04:56 -0700 [thread overview]
Message-ID: <55B680D8.5070702@zytor.com> (raw)
In-Reply-To: <1438019319-19731-1-git-send-email-uros_bizjak1@t-2.net>
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."
Those are the kind of places where having per-site conditional code
makes sense.
-hpa
next prev parent reply other threads:[~2015-07-27 19:05 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 ` H. Peter Anvin [this message]
2015-07-27 20:01 ` ASM flags in general Uros Bizjak
2015-07-27 21:14 ` H. Peter Anvin
2015-07-27 20:38 ` Andy Lutomirski
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=55B680D8.5070702@zytor.com \
--to=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