This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/25671] New: test_bit() compilation does not expand to "bt" instruction
- From: "avi at argo dot co dot il" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Jan 2006 15:24:53 -0000
- Subject: [Bug target/25671] New: test_bit() compilation does not expand to "bt" instruction
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
the code
int test_bit(unsigned long *words, int bit)
{
int wsize = (sizeof *words) * 8;
return (words[bit / wsize] & (1 << (bit % wsize))) != 0;
}
can compile to
xor %rax, %rax
bt %rsi, (%rdi)
setc %al
but instead compiles to a much longer sequence, using many more registers,
which is probably slower as well. If gcc recognized this common idiom (like it
recognizes bit rotate sequences), smaller and more optimal code would be
generated (especially if the result of the test is in an if statement - it
could boil down to a bt; jc sequence).
--
Summary: test_bit() compilation does not expand to "bt"
instruction
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: avi at argo dot co dot il
GCC build triplet: x86_64-redhat-linux
GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25671