public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "spatel at rotateright dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/62191] New: extra shift generated for vector integer division by constant 2
Date: Tue, 19 Aug 2014 18:24:00 -0000	[thread overview]
Message-ID: <bug-62191-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62191

            Bug ID: 62191
           Summary: extra shift generated for vector integer division by
                    constant 2
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: spatel at rotateright dot com

Using gcc 4.9:

$ cat sdiv.c
typedef int vecint __attribute__((vector_size(16))); 
vecint f(vecint x) { 
    return x/2;
} 

$ gcc -O2 sdiv.c -S -o  -
...
    movdqa    %xmm0, %xmm1
    psrad    $31, %xmm1    <--- splat the sign bit
    psrld    $31, %xmm1    <--- then shift sign bit down to LSB
    paddd    %xmm1, %xmm0  <--- add sign bit to quotient
    psrad    $1, %xmm0     <--- div via alg shift right
    ret

--------------------------------------------------------------

I don't think the first shift right algebraic is necessary. We splat the sign
bit and then shift that right logically, so the upper bits are all zero'd
anyway. 

This is a special case for signed integer division by 2. You need that first
'psrad' for any other power of 2 because the subsequent logical shift would not
also be a shift of 31.


             reply	other threads:[~2014-08-19 18:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19 18:24 spatel at rotateright dot com [this message]
2020-09-03 20:50 ` [Bug target/62191] " gabravier at gmail dot com

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=bug-62191-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).