public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Roger Sayle" <roger@nextmovesoftware.com>
To: <gcc-patches@gcc.gnu.org>
Cc: "'Richard Sandiford'" <richard.sandiford@arm.com>
Subject: [Committed] Bug fix to new wi::bitreverse_large function.
Date: Wed, 7 Jun 2023 23:54:37 +0100	[thread overview]
Message-ID: <009d01d99993$0a433840$1ec9a8c0$@nextmovesoftware.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 879 bytes --]


Richard Sandiford was, of course, right to be warry of new code without
much test coverage.  Converting the nvptx backend to use the BITREVERSE
rtx infrastructure, has resulted in far more exhaustive testing and
revealed a subtle bug in the new wi::bitreverse implementation.  The
code needs to use HOST_WIDE_INT_1U (instead of 1) to avoid unintended
sign extension.

This patch has been tested on nvptx-none hosted on x86_64-pc-linux-gnu
(with a minor tweak to use BITREVERSE), where it fixes regressions of
the 32-bit test vectors in gcc.target/nvptx/brev-2.c and the 64-bit
test vectors in gcc.target/nvptx/brevll-2.c.  Committed as obvious.


2023-06-07  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        * wide-int.cc (wi::bitreverse_large): Use HOST_WIDE_INT_1U to
        avoid sign extension/undefined behaviour when setting each bit.


Thanks,
Roger
--


[-- Attachment #2: patchwi.txt --]
[-- Type: text/plain, Size: 456 bytes --]

diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc
index 24bdce2..ab92ee6 100644
--- a/gcc/wide-int.cc
+++ b/gcc/wide-int.cc
@@ -786,7 +786,7 @@ wi::bitreverse_large (HOST_WIDE_INT *val, const HOST_WIDE_INT *xval,
 	  unsigned int d = (precision - 1) - s;
 	  block = d / HOST_BITS_PER_WIDE_INT;
 	  offset = d & (HOST_BITS_PER_WIDE_INT - 1);
-          val[block] |= 1 << offset;
+          val[block] |= HOST_WIDE_INT_1U << offset;
 	}
     }
 

                 reply	other threads:[~2023-06-07 22:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='009d01d99993$0a433840$1ec9a8c0$@nextmovesoftware.com' \
    --to=roger@nextmovesoftware.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).