diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-06-21 15:10:14 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-06-22 09:53:13 +0100 |
commit | 46b8b3d6f87c0c65d908e3f6c83532d7286868b9 (patch) | |
tree | 57add5491a7bfe6be32c0127311fbc4b544e1421 /opcodes | |
parent | ded5cb94441b2a47a75a0b1d26218f0d5e3dca28 (diff) | |
download | fsf-binutils-gdb-46b8b3d6f87c0c65d908e3f6c83532d7286868b9.zip fsf-binutils-gdb-46b8b3d6f87c0c65d908e3f6c83532d7286868b9.tar.gz fsf-binutils-gdb-46b8b3d6f87c0c65d908e3f6c83532d7286868b9.tar.bz2 |
opcodes: make use of __builtin_popcount when available
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.
Diffstat (limited to 'opcodes')
-rw-r--r-- | opcodes/ChangeLog | 5 | ||||
-rw-r--r-- | opcodes/cgen-dis.c | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 0dab08e..20e0524 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -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 diff --git a/opcodes/cgen-dis.c b/opcodes/cgen-dis.c index 6a93060..1a5d1ae 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); +#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. */ |