opcodes: make use of __builtin_popcount when available

Message ID 20210621152156.3116400-1-andrew.burgess@embecosm.com
State New
Headers show
  • opcodes: make use of __builtin_popcount when available
Related show

Commit Message

Andrew Burgess June 21, 2021, 3:21 p.m.
This commit provides a small performance improvement when starting up
CGEN based disassemblers by making use of __builtin_popcount.

The #if check used in this commit was copied from bfd/elf32-arm.c
where __builtin_popcount is also used.

I ran into this code while investigating some GDB tests that would
occasionally timeout.  One of the reason these tests were having
problems is that the m16c and m32c disassemblers take so long to
initialise themselves.  Speeding up count_decodable_bits helps, but is
not a total solution.  Still, this felt like an easy win which added
minimal extra complexity, so I figure its worth doing.


	* cgen-dis.c (count_decodable_bits): Use __builtin_popcount when
 opcodes/ChangeLog  | 5 +++++
 opcodes/cgen-dis.c | 4 ++++
 2 files changed, 9 insertions(+)



H.J. Lu via Binutils June 22, 2021, 1:27 a.m. | #1
On Mon, Jun 21, 2021 at 04:21:56PM +0100, Andrew Burgess wrote:
> 	* cgen-dis.c (count_decodable_bits): Use __builtin_popcount when

> 	available.


Alan Modra
Australia Development Lab, IBM


diff --git a/opcodes/cgen-dis.c b/opcodes/cgen-dis.c
index 6a93060edd5..1a5d1ae8459 100644
--- a/opcodes/cgen-dis.c
+++ b/opcodes/cgen-dis.c
@@ -40,6 +40,9 @@  static int
 count_decodable_bits (const CGEN_INSN *insn)
   unsigned mask = CGEN_INSN_BASE_MASK (insn);
+#if GCC_VERSION >= 3004
+  return __builtin_popcount (mask);
   int bits = 0;
   unsigned m;
@@ -49,6 +52,7 @@  count_decodable_bits (const CGEN_INSN *insn)
   return bits;
 /* Add an instruction to the hash chain.  */