From: Richard Biener <richard.guenther@gmail.com>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] doc: clarify semantics of vector bitwise shifts
Date: Wed, 24 May 2023 15:21:09 +0200 [thread overview]
Message-ID: <CAFiYyc2iDXr__4ELi_R_1zpMTV3Md6quN-AQ4uBCUOM=seRaGw@mail.gmail.com> (raw)
In-Reply-To: <20230524125332.30839-1-amonakov@ispras.ru>
On Wed, May 24, 2023 at 2:54 PM Alexander Monakov via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Explicitly say that bitwise shifts for narrow types work similar to
> element-wise C shifts with integer promotions, which coincides with
> OpenCL semantics.
Do we need to clarify that v << w with v being a vector of shorts
still yields a vector of shorts and not a vector of ints?
Btw, I don't see this promotion reflected in the IL. For
typedef short v8hi __attribute__((vector_size(16)));
v8hi foo (v8hi a, v8hi b)
{
return a << b;
}
I get no masking of 'b' and vector lowering if the target doens't handle it
yields
short int _5;
short int _6;
_5 = BIT_FIELD_REF <a_1(D), 16, 0>;
_6 = BIT_FIELD_REF <b_2(D), 16, 0>;
_7 = _5 << _6;
which we could derive ranges from for _6 (apparantly we don't yet). Even
typedef int v8hi __attribute__((vector_size(16)));
v8hi x;
int foo (v8hi a, v8hi b)
{
x = a << b;
return (b[0] > 33);
}
isn't optimized currently (but could - note I've used 'int' elements here).
So, I don't see us making sure the hardware does the right thing for
out-of bound values.
Richard.
> gcc/ChangeLog:
>
> * doc/extend.texi (Vector Extensions): Clarify bitwise shift
> semantics.
> ---
> gcc/doc/extend.texi | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> index e426a2eb7d..6b4e94b6a1 100644
> --- a/gcc/doc/extend.texi
> +++ b/gcc/doc/extend.texi
> @@ -12026,7 +12026,12 @@ elements in the operand.
> It is possible to use shifting operators @code{<<}, @code{>>} on
> integer-type vectors. The operation is defined as following: @code{@{a0,
> a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
> -@dots{}, an >> bn@}}@. Vector operands must have the same number of
> +@dots{}, an >> bn@}}@. When the base type is narrower than @code{int},
> +element-wise shifts are performed as if operands underwent C integer
> +promotions, like in OpenCL. This makes vector shifts by up to 31 bits
> +well-defined for vectors with @code{char} and @code{short} base types.
> +
> +Operands of binary vector operations must have the same number of
> elements.
>
> For convenience, it is allowed to use a binary vector operation
> --
> 2.39.2
>
next prev parent reply other threads:[~2023-05-24 13:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 12:53 Alexander Monakov
2023-05-24 13:21 ` Richard Biener [this message]
2023-05-24 14:21 ` Alexander Monakov
2023-05-24 16:28 Richard Biener
2023-05-24 18:36 ` Alexander Monakov
2023-05-25 6:50 ` Richard Biener
2023-05-25 10:46 ` Richard Biener
2023-05-30 14:49 ` Alexander Monakov
2023-05-31 7:12 ` Richard Biener
2023-06-01 18:25 ` Alexander Monakov
2023-06-02 7:07 ` Matthias Kretz
2023-06-02 7:49 ` Alexander Monakov
2023-06-02 9:03 ` Matthias Kretz
2023-06-02 9:24 ` Alexander Monakov
2023-06-02 9:34 ` Matthias Kretz
2023-06-02 9:36 ` Richard Biener
2023-06-02 9:39 ` Richard Biener
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='CAFiYyc2iDXr__4ELi_R_1zpMTV3Md6quN-AQ4uBCUOM=seRaGw@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=amonakov@ispras.ru \
--cc=gcc-patches@gcc.gnu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).