public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Allan Sandfeld Jensen <linux@carewolf.com>,
	       Kirill Yukhin <kirill.yukhin@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Uros Bizjak <ubizjak@gmail.com>
Subject: Re: [PATCH] [x86] Avoid builtins for SSE/AVX2 immidiate logical shifts
Date: Mon, 24 Apr 2017 09:38:00 -0000	[thread overview]
Message-ID: <20170424091737.GL1809@tucnak> (raw)
In-Reply-To: <201704241101.29634.linux@carewolf.com>

On Mon, Apr 24, 2017 at 11:01:29AM +0200, Allan Sandfeld Jensen wrote:
> On Monday 24 April 2017, Jakub Jelinek wrote:
> > On Mon, Apr 24, 2017 at 10:34:58AM +0200, Allan Sandfeld Jensen wrote:
> > > That is a different instruction. That is the vpsllw not vpsllwi
> > > 
> > > The intrinsics I changed is the immediate version, I didn't change the
> > > non- immediate version. It is probably a bug if you can give
> > > non-immediate values to the immediate only intrinsic. At least both
> > > versions handles it, if in different ways, but is is illegal arguments.
> > 
> > The documentation is unclear on that and I've only recently fixed up some
> > cases where these intrinsics weren't able to handle non-constant arguments
> > in some cases, while both ICC and clang coped with that fine.
> > So it is clearly allowed and handled by all the compilers and needs to be
> > supported, people use that in real-world code.
> > 
> Undoubtedly it happens. I just make a mistake myself that created that case. 
> But it is rather unfortunate, and means we make wrong code currently for 
> corner case values.

The intrinsic documentation is poor, usually you have a good documentation
on what the instructions do, and then you just have to guess what the
intrinsics do.  You can of course ask Intel for clarification.

If you try:
#include <x86intrin.h>

__m128i
foo (__m128i a, int b)
{
  return _mm_slli_epi16 (a, b);
}
and call it with 257 from somewhere else, you can see that all the compilers
will give you zero vector.  And similarly if you use 257 literally instead
of b.  So what the intrinsic (unlike the instruction)
actually does is that it compares all bits of the imm8 argument (supposedly
using unsigned comparison) and if it is bigger than 15 (or 7 or 31 or 63
depending on the bitsize of element) it yields 0 vector.

	Jakub

  parent reply	other threads:[~2017-04-24  9:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <201704221338.46300.linux@carewolf.com>
2017-04-24  7:43 ` Allan Sandfeld Jensen
2017-04-24  7:47   ` Jakub Jelinek
2017-04-24  8:02     ` Allan Sandfeld Jensen
2017-04-24  8:25       ` Jakub Jelinek
2017-04-24  8:25         ` Allan Sandfeld Jensen
2017-04-24  8:38           ` Jakub Jelinek
2017-04-24  8:40             ` Allan Sandfeld Jensen
2017-04-24  8:54               ` Allan Sandfeld Jensen
2017-04-24  8:57               ` Jakub Jelinek
2017-04-24 14:43     ` Allan Sandfeld Jensen
2017-05-02 10:17       ` Jakub Jelinek
2017-05-02 11:22         ` Allan Sandfeld Jensen
2017-05-02 15:58         ` Marc Glisse
     [not found] ` <201704241101.29634.linux@carewolf.com>
2017-04-24  9:38   ` Jakub Jelinek [this message]
2017-04-24  9:38     ` Allan Sandfeld Jensen
2017-04-24  9:17 Allan Sandfeld Jensen

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=20170424091737.GL1809@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kirill.yukhin@gmail.com \
    --cc=linux@carewolf.com \
    --cc=ubizjak@gmail.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).