public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/97459] New: __uint128_t remainder for division by 3
@ 2020-10-16 13:33 tkoenig at gcc dot gnu.org
  2020-10-16 15:22 ` [Bug rtl-optimization/97459] " jakub at gcc dot gnu.org
                   ` (26 more replies)
  0 siblings, 27 replies; 28+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-10-16 13:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97459
           Summary: __uint128_t remainder for division by 3
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkoenig at gcc dot gnu.org
  Target Milestone: ---

The following two functions are equivalent:

unsigned r3_128u_v1 (__uint128_t n)
{
  unsigned long a;
  a = (n >> 64) + (n & 0xffffffffffffffff);
  return a % 3;
}

unsigned r3_128u_v2 (__uint128_t n)
{
  return (unsigned) (n%3);
}

and the first one is definitely faster.

(The approach is due to Hacker's Delight, 2nd edition, "Remainder by
Summing Digits". There are also other interesting approaches there.)

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-08-15 11:24 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16 13:33 [Bug rtl-optimization/97459] New: __uint128_t remainder for division by 3 tkoenig at gcc dot gnu.org
2020-10-16 15:22 ` [Bug rtl-optimization/97459] " jakub at gcc dot gnu.org
2020-10-16 15:52 ` jakub at gcc dot gnu.org
2020-10-16 15:57 ` jakub at gcc dot gnu.org
2020-10-17 12:22 ` tkoenig at gcc dot gnu.org
2020-10-18  7:33 ` tkoenig at gcc dot gnu.org
2020-10-18  9:11 ` jakub at gcc dot gnu.org
2020-10-19 11:51 ` jakub at gcc dot gnu.org
2020-10-19 12:05 ` jakub at gcc dot gnu.org
2020-10-20 18:16 ` tkoenig at gcc dot gnu.org
2020-10-23 16:56 ` tkoenig at gcc dot gnu.org
2020-10-24 18:09 ` tkoenig at gcc dot gnu.org
2020-10-24 18:14 ` tkoenig at gcc dot gnu.org
2020-10-26  5:28 ` tkoenig at gcc dot gnu.org
2020-11-08  9:31 ` tkoenig at gcc dot gnu.org
2020-11-08 10:24 ` jakub at gcc dot gnu.org
2020-11-08 19:28 ` tkoenig at gcc dot gnu.org
2020-11-08 19:33 ` tkoenig at gcc dot gnu.org
2020-11-26 19:12 ` jakub at gcc dot gnu.org
2020-11-27 13:26 ` jakub at gcc dot gnu.org
2020-11-27 15:10 ` jakub at gcc dot gnu.org
2020-11-27 18:34 ` jakub at gcc dot gnu.org
2020-11-30  9:57 ` cvs-commit at gcc dot gnu.org
2020-12-01 15:25 ` cvs-commit at gcc dot gnu.org
2020-12-02 10:41 ` cvs-commit at gcc dot gnu.org
2020-12-02 13:36 ` jakub at gcc dot gnu.org
2020-12-03 19:55 ` tkoenig at gcc dot gnu.org
2021-08-15 11:24 ` pinskia at gcc dot gnu.org

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).