Page 2 of 2

Re: single bit test in one instruction

PostPosted: Thu Apr 03, 2014 9:37 pm
by amylaar
notzed wrote:There's no BTST, and AND doesn't take a literal so you would have to load the register first (with 1 or two instruction overhead) ... but a single bit-test of any bit can be performed in one instruction:

Code: Select all
        ;; Test bit X is set
        lsl     r0,r1,#(31-X)
        blt     .bit_is_set
        bgte    .bit_is_not_set


More background over here: http://a-hackers-craic.blogspot.com.au/2013/08/epiphany-bit-test.html

Maybe it's common knowledge but as i had to 'discover it' it may save someone else the search.


gcc's epiphany port already knew that, but it failed to tell that this flag-setting-by-shift is a cheap operation, so the combiner rejected this.
I've pushed a patch:

commit 38d6f8f22721a54298d485fbeb6cbe0f63d046b8
Author: Joern Rennecke <joern.rennecke@embecosm.com>
Date: Thu Apr 3 22:22:42 2014 +0100

gcc:
* config/epiphany/epiphany.c (epiphany_rtx_cost): Compare
with CC_N_NE / CC_C_LTU / CC_C_GTU carries no extra cost for
its operands.
gcc/testsuite:
* gcc.target/epiphany/btst-1.c: New test.

Re: single bit test in one instruction

PostPosted: Sat Apr 05, 2014 12:10 am
by notzed
amylaar wrote:gcc's epiphany port already knew that, but it failed to tell that this flag-setting-by-shift is a cheap operation, so the combiner rejected this.

Nice.