public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia 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: Thu, 14 Mar 2024 00:10:29 +0000	[thread overview]
Message-ID: <bug-114327-4-xht8PnYsbY@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 #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For (ignore the strict aliasing issue):
```
typedef signed _BitInt(256) B;

[[gnu::noinline]]
B
foo (signed char c, B b)
{
  return b % c;
}

int
main (void)
{
  B x = foo (1, -3); // -3 % 1 -> 0
 // if (x)
 //   __builtin_abort();
    signed long *t = (signed long *)&x;
  for(int i = 0;i < sizeof(B)/sizeof(long); i++ )
  {
    __builtin_printf("%lx\n", t[i]);
  }
  return 0;
}
```
We get:
```
0
ffffffffffffffff
ffffffffffffffff
ffffffffffffffff
```

Which makes it seem like we are doing the sign extend when the value was the
result was 0.

Even:
> B x = foo (3, -3); // -3 % 3 -> 0

Gives the wrong similar result.

  parent reply	other threads:[~2024-03-14  0:10 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 [this message]
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
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-xht8PnYsbY@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).