public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tkoenig at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/97282] division done twice for modulo and divsion for 128-bit integers Date: Sat, 03 Oct 2020 23:18:42 +0000 [thread overview] Message-ID: <bug-97282-4-mvzZsLHGiF@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-97282-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97282 --- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- And here is a version which uses two 64-bit numbers for calculation of he sum of decimal digits as a benchmark for the division and modulo: unsigned long digsum3 (myint x) { unsigned long ret; __uint64_t high, low; const unsigned long int rem_high[10] = {0,6,2,8,4,0,6,2,8,4}; const unsigned long int foo_high[10] = {0x0000000000000000, 0x1999999999999999, 0x3333333333333333, 0x4CCCCCCCCCCCCCCC, 0x6666666666666666, 0x8000000000000000, 0x9999999999999999, 0xB333333333333333, 0xCCCCCCCCCCCCCCCC, 0xE666666666666666 }; high = x >> 64; low = x; ret = 0; while (low > 0 || high > 0) { unsigned long r_high, r_low, r_sum, r_carry; r_high = high % 10; r_carry = rem_high[r_high]; high = high / 10; r_low = low % 10; low = low / 10; low = low + foo_high[r_high]; r_sum = r_low + r_carry; if (r_sum >= 10) { r_sum = r_sum - 10; low ++; } ret = ret + r_sum; } return ret; } It is _much_ faster, taking around 250 to 260 cycles per calculation, a speedup of a factor of around 8 versus the original code.
next prev parent reply other threads:[~2020-10-03 23:18 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-03 16:37 [Bug rtl-optimization/97282] New: " tkoenig at gcc dot gnu.org 2020-10-03 16:37 ` [Bug rtl-optimization/97282] " tkoenig at gcc dot gnu.org 2020-10-03 23:18 ` tkoenig at gcc dot gnu.org [this message] 2020-10-05 11:00 ` jakub at gcc dot gnu.org 2020-10-05 13:37 ` jakub at gcc dot gnu.org 2020-10-06 8:33 ` cvs-commit at gcc dot gnu.org 2021-08-15 11:23 ` pinskia 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-97282-4-mvzZsLHGiF@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: linkBe 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).