public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/97759] New: Could std::has_single_bit implementation be faster?
@ 2020-11-09  0:01 gcc-bugs at marehr dot dialup.fu-berlin.de
  2020-11-09  5:41 ` [Bug libstdc++/97759] Could std::has_single_bit " tkoenig at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: gcc-bugs at marehr dot dialup.fu-berlin.de @ 2020-11-09  0:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97759
           Summary: Could std::has_single_bit implementation be faster?
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de
  Target Milestone: ---

Hello gcc-team,

we are thrilled that C++20 offers some efficient bit implementation and that we
could exchange some of our own implementation with the standardized ones,
making the code more accessible.

I replaced our implementation and noticed that `std::has_single_bit` was slower
than what we had before by around 30%. (The other functions matched our
timings.)

Additionally, we have a (micro-)benchmark that compares the standard arithmetic
bit trick
(https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2) with
the implementation where popcount == 1. We decided to use the arithmetic
version, because we measured that it was faster than popcount on our machines
(mostly intel processors).

Interestingly, it seems that the popcount benchmark matches the
std::has_single_bit time-wise, so I guess that std::has_single_bit is
implemented via popcount.

Those timings could be reproduced at an unknown location
https://quick-bench.com/q/Y28keu_mSh25WwhO05T4SKrbHpk

I don't know how to fix this, but I would expect that the optimizer would
recognize popcount=1 and knows that there is a more efficient version. Or
change the implementation to arithmetic, where again the optimizer could decide
to replace that by a popcount if that is more efficient on some architecture?

Thank you!

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

end of thread, other threads:[~2024-03-04 22:56 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09  0:01 [Bug libstdc++/97759] New: Could std::has_single_bit implementation be faster? gcc-bugs at marehr dot dialup.fu-berlin.de
2020-11-09  5:41 ` [Bug libstdc++/97759] Could std::has_single_bit " tkoenig at gcc dot gnu.org
2020-11-09  8:16 ` rguenth at gcc dot gnu.org
2020-11-09  9:13 ` crazylht at gmail dot com
2020-11-09 10:44 ` jakub at gcc dot gnu.org
2020-11-09 11:00 ` jakub at gcc dot gnu.org
2020-11-09 11:13 ` redi at gcc dot gnu.org
2020-11-09 23:28 ` gcc-bugs at marehr dot dialup.fu-berlin.de
2020-11-09 23:28 ` gcc-bugs at marehr dot dialup.fu-berlin.de
2020-11-09 23:55 ` gcc-bugs at marehr dot dialup.fu-berlin.de
2020-11-10  0:16 ` gcc-bugs at marehr dot dialup.fu-berlin.de
2020-11-10  2:15 ` crazylht at gmail dot com
2020-11-10  8:57 ` redi at gcc dot gnu.org
2021-08-03  5:51 ` pinskia at gcc dot gnu.org
2022-03-03 11:08 ` peter at cordes dot ca
2024-03-04 22:56 ` 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).