public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libgcc/114327] `-CST % 1` is wrong for _BitInt()
Date: Fri, 15 Mar 2024 18:05:20 +0000	[thread overview]
Message-ID: <bug-114327-4-ZJnXQMPEHW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114327-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:a6dab195f7041671166b9aa6a37e0db4236c829d

commit r14-9498-ga6dab195f7041671166b9aa6a37e0db4236c829d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Mar 15 19:04:33 2024 +0100

    libgcc: Fix quotient and/or remainder negation in __divmodbitint4
[PR114327]

    While for __mulbitint3 we actually don't negate anything and perform the
    multiplication in unsigned style always, for __divmodbitint4 if the
operands
    aren't unsigned and are negative, we negate them first and then try to
    negate them as needed at the end.
    quotient is negated if just one of the operands was negated and the other
    wasn't or vice versa, and remainder is negated if the first operand was
    negated.
    The case which doesn't work correctly is if due to limited range of the
    operands we perform the division/modulo in some smaller number of limbs
    and then extend it to the desired precision of the quotient and/or
    remainder results.  If they aren't negated, the extension is done with
    memset to 0, if they are negated, the extension was done with memset
    to -1.  The problem is that if the quotient or remainder is zero,
    then bitint_negate negates it again to zero (that is ok), but we should
    then extend with memset to 0, not memset to -1.

    The following patch achieves that by letting bitint_negate also check if
    the negated operand is zero and changes the memset argument based on that.

    2024-03-15  Jakub Jelinek  <jakub@redhat.com>

            PR libgcc/114327
            * libgcc2.c (bitint_negate): Return UWtype bitwise or of all the
limbs
            before negation rather than void.
            (__divmodbitint4): Determine whether to fill in the upper limbs
after
            negation based on whether bitint_negate returned 0 or non-zero,
rather
            then always filling with -1.

            * gcc.dg/torture/bitint-63.c: New test.

  parent reply	other threads:[~2024-03-15 18:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 19:06 [Bug libgcc/114327] New: wrong code with _BitInt() modulo at -O0 zsojka at seznam dot cz
2024-03-14  0:00 ` [Bug libgcc/114327] `-CST % 1` is wrong for _BitInt() pinskia at gcc dot gnu.org
2024-03-14  0:10 ` pinskia at gcc dot gnu.org
2024-03-14  5:31 ` zsojka at seznam dot cz
2024-03-14 12:57 ` jakub at gcc dot gnu.org
2024-03-15 18:05 ` cvs-commit at gcc dot gnu.org [this message]
2024-03-15 18:07 ` jakub at gcc dot gnu.org

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-114327-4-ZJnXQMPEHW@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).