opcodes: make use of __builtin_popcount when available
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 21 Jun 2021 14:10:14 +0000 (15:10 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 22 Jun 2021 08:53:13 +0000 (09:53 +0100)
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.

opcodes/ChangeLog:

* cgen-dis.c (count_decodable_bits): Use __builtin_popcount when
available.

opcodes/ChangeLog
opcodes/cgen-dis.c

index 0dab08e6e54c7a77d13de008413495907831394a..20e0524a1bf1d67f15010bd260d389e844646d5e 100644 (file)
@@ -1,3 +1,8 @@
+2021-06-22  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * cgen-dis.c (count_decodable_bits): Use __builtin_popcount when
+       available.
+
 2021-06-22  Alan Modra  <amodra@gmail.com>
 
        * pj-dis.c (print_insn_pj): Don't print trailing tab.  Do
index 6a93060edd5891303668bbe1c75ba845c21e9885..1a5d1ae84591538097907d07b2d21a949cc843bc 100644 (file)
@@ -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);
+#else
   int bits = 0;
   unsigned m;
 
@@ -49,6 +52,7 @@ count_decodable_bits (const CGEN_INSN *insn)
        ++bits;
     }
   return bits;
+#endif
 }
 
 /* Add an instruction to the hash chain.  */
This page took 0.029145 seconds and 4 git commands to generate.