This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/83832] New: [RX] Improve bittests
- From: "olegendo at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 14 Jan 2018 09:05:51 +0000
- Subject: [Bug target/83832] New: [RX] Improve bittests
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83832
Bug ID: 83832
Summary: [RX] Improve bittests
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: olegendo at gcc dot gnu.org
Target Milestone: ---
Target: rx*-*-*
If a bit test is done with only a single bit in the constant, the btst
instruction should be used to get smaller code.
When testing for constants such a 0xFF or 0xFFFF a zero_extend is emitted
followed by a compare against zero. These 2 instructions can be folded into a
single tst instruction to improve execution speed.
These are just a few observations, probably there are more.
int bittest_0 (int x)
{
return x & 0xFF ? 4 : 60;
// 5b 11 movu.b r1, r1
// 61 01 cmp #0, r1
// better (speed):
// fd 78 c1 ff 00 tst #255, r1
}
int bittest_1 (int x)
{
return x & 0xFFFF ? 4 : 60;
// 5b 11 movu.b r1, r1
// 61 01 cmp #0, r1
// better (speed):
// fd 78 c1 ff 00 tst #255, r1
}
int bittest_2 (int x)
{
return x & 0xFE ? 4 : 60;
// fd 78 c1 fe 00 tst #254, r1
}
int bittest_3 (unsigned int x)
{
return x & (1 << 1) ? 4 : 60;
// fd 74 c1 02 tst #2, r1
// better (code size):
// 7c 11 btst #1, r1
}
int bittest_4 (unsigned char* x)
{
return *x & (1 << 1) ? 4 : 60;
// cc 1e mov.b [r1], r14
// fd 74 ce 02 tst #2, r14
// better (code size):
// f4 11 btst #1, [r1].b
}