From: Richard Biener <richard.guenther@gmail.com>
To: gcc@gcc.gnu.org, Marc Glisse <marc.glisse@inria.fr>,
Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: What is the type of vector signed + vector unsigned?
Date: Tue, 29 Dec 2020 19:44:24 +0100 [thread overview]
Message-ID: <D29F20CD-B92F-446C-9196-1B600DC8F144@gmail.com> (raw)
In-Reply-To: <50e9877-9b37-a418-f420-aa4b9b1d59fe@stedding.saclay.inria.fr>
On December 29, 2020 6:42:30 PM GMT+01:00, Marc Glisse <marc.glisse@inria.fr> wrote:
>On Tue, 29 Dec 2020, Richard Sandiford via Gcc wrote:
>
>> Any thoughts on what f should return in the following testcase, given
>the
>> usual GNU behaviour of treating signed >> as arithmetic shift right?
>>
>> typedef int vs4 __attribute__((vector_size(16)));
>> typedef unsigned int vu4 __attribute__((vector_size(16)));
>> int
>> f (void)
>> {
>> vs4 x = { -1, -1, -1, -1 };
>> vu4 y = { 0, 0, 0, 0 };
>> return ((x + y) >> 1)[0];
>> }
>>
>> The C frontend takes the type of x+y from the first operand, so x+y
>> is signed and f returns -1.
>
>Symmetry is an important property of addition in C/C++.
>
>> The C++ frontend applies similar rules to x+y as it would to scalars,
>> with unsigned T having a higher rank than signed T, so x+y is
>unsigned
>> and f returns 0x7fffffff.
>
>That looks like the most natural choice.
>
>> FWIW, Clang treats x+y as signed, so f returns -1 for both C and C++.
>
>I think clang follows gcc and uses the type of the first operand.
The desired behavior is the one that OpenCL specifies. If it is implementation defined we should document behavior. I agree symmetry is nice but eventually the current C behavior is what OpenCL specifies.
Richard.
next prev parent reply other threads:[~2020-12-29 18:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-29 16:33 Richard Sandiford
2020-12-29 17:42 ` Marc Glisse
2020-12-29 18:44 ` Richard Biener [this message]
2020-12-29 19:19 ` Alexander Monakov
2021-01-04 13:51 ` 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=D29F20CD-B92F-446C-9196-1B600DC8F144@gmail.com \
--to=richard.guenther@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=marc.glisse@inria.fr \
--cc=richard.sandiford@arm.com \
/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).