single bit test in one instruction

Re: single bit test in one instruction

Postby amylaar » Thu Apr 03, 2014 9:37 pm

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.
amylaar
 
Posts: 31
Joined: Thu Jan 10, 2013 3:06 pm

Re: single bit test in one instruction

Postby notzed » Sat Apr 05, 2014 12:10 am

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.
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia

Previous

Return to Assembly

Who is online

Users browsing this forum: No registered users and 2 guests

cron