public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "intvnut at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/36041] New: Speed up builtin_popcountll Date: Fri, 25 Apr 2008 00:35:00 -0000 [thread overview] Message-ID: <bug-36041-16111@http.gcc.gnu.org/bugzilla/> (raw) The current __builtin_popcountll (and likely __builtin_popcount) are fairly slow as compared to a simple, short C version derived from what can be found in Knuth's recent publications. The following short function is about 3x as fast as the __builtin version, which runs counter to the idea that __builtin_XXX provides access to implementations that are exemplars for a given platform. unsigned int popcount64(unsigned long long x) { x = (x & 0x5555555555555555ULL) + ((x >> 1) & 0x5555555555555555ULL); x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL); x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x >> 4) & 0x0F0F0F0F0F0F0F0FULL); return (x * 0x0101010101010101ULL) >> 56; } This version has the additional benefit that it omits the lookup table that the current "builtin" version uses. I measured the above function vs. __builtin_popcountll with a loop like the following: t1 = clock(); for (j = 0; j < 1000000; j++) for (i = 0; i < 1024; i++) pt = popcount64(data[i]); t2 = clock(); printf("popcount64 = %d clocks\n", t2 - t1); ...where data[] is a u64 that's preinitialized. I'll attach the exact source I used, which also includes two other possible implementations of popcountll. -- Summary: Speed up builtin_popcountll Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: intvnut at gmail dot com GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36041
next reply other threads:[~2008-04-25 0:35 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-04-25 0:35 intvnut at gmail dot com [this message] 2008-04-25 0:37 ` [Bug c/36041] " intvnut at gmail dot com 2008-04-25 0:40 ` [Bug middle-end/36041] " intvnut at gmail dot com 2008-04-25 8:45 ` rguenth at gcc dot gnu dot org 2008-04-25 12:29 ` intvnut at gmail dot com 2008-04-25 14:52 ` rguenth at gcc dot gnu dot org 2008-04-29 3:42 ` intvnut at gmail dot com 2010-02-21 1:34 ` manu at gcc dot gnu dot 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-36041-16111@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).