A question about thumb2 cbnz/cbz implementation in thumb2.md

Chung-Lin Tang cltang at codesourcery.com
Mon Nov 29 09:05:58 UTC 2010


In the ARM architecture: Under ARM mode, the PC(r15) register value is 
"address of current insn + 8", while in Thumb mode (including Thumb-2), 
it is "address of current insn + 4"

With the way the cbz/cbnz immediate is defined, which is 0--126 (even), 
the branch range is then: +4 to +130  :)

On the issue of the doloop_end pattern for ARM/Thumb-2 in the context of 
enabling SMS, I actually have tried it in the past. IIRC, I used a 
"subs+bne" assembly sequence then.

Chung-Lin


On 2010/11/29 下午 04:37, Revital1 Eres wrote:
> OK, thanks for your answer.
> Is there other instruction for backward jumps that can be used
> to replace cmp to zero+bne?
>
> btw, in the following link of thumb-2 instructions set I understood that
> the label can appear before the branch so it was confusing...
>
> CB{N}Z Rn,<label>  If Rn {== or !=} 0 then PC := label. label is (this
> instruction + 4-130).
>
> http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf
>
> Thanks,
> Revital
>
>
>
>
> From:	Chung-Lin Tang<cltang at codesourcery.com>
> To:	Revital1 Eres/Haifa/IBM at IBMIL
> Cc:	linaro-toolchain at lists.linaro.org
> Date:	29/11/2010 10:21 AM
> Subject:	Re: A question about thumb2 cbnz/cbz implementation in
>              thumb2.md
>
>
>
> Unfortunately, cbnz/cbz has a 6-bit:'0' (7-bit aligned to 2) immediate
> offset that is *zero extended*, i.e. it is only for forward branches.
>
> Chung-Lin
>
> On 2010/11/29 下午 04:14, Revital1 Eres wrote:
>>
>> Hello,
>>
>> I have a question about cbnz/cbz thumb-2 instruction implementation in
>> thumb2.md file:
>>
>> I have an example where we jump to a label which appears before the
> branch;
>> for example:
>>
>>           L4
>>           ...
>>           cmp     r3, 0
>>           bne     .L4
>>
>> It seems that cbnz instruction should be applied in this loop; replacing
>> cmp+bne; however, cbnz fails to be applied as diff = ADDRESS (L4) -
> ADDRESS
>> (bne .L4) is negative and according to thumb2_cbz in thumb2.md it should
>> be 2<=diff<=128 (please see snippet below taken from thumb2_cbz).
>>
>> So I want to double check if the current implementation of thumb2_cbnz
>> in thumb2.md needs to be changed to enable it.
>>
>> The following is from thumb2_cbnz in thumb2.md:
>>
>>     [(set (attr "length")
>>           (if_then_else
>>               (and (ge (minus (match_dup 1) (pc)) (const_int 2))
>>                    (le (minus (match_dup 1) (pc)) (const_int 128))
>>                    (eq (symbol_ref ("which_alternative")) (const_int 0)))
>>               (const_int 2)
>>               (const_int 8)))]
>>
>> Thanks,
>> Revital
>>
>>
>> _______________________________________________
>> linaro-toolchain mailing list
>> linaro-toolchain at lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/linaro-toolchain
>
>
>




More information about the linaro-toolchain mailing list