This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: arm/thumb bugs


On Mon, 12 Nov 2001, Philip Blundell wrote:
>In message <3BF003A7.F2FE2F5@acter.ch>, Adrian von Bidder writes:
>>The switch statements translate to code like
>>.LCB6:
>>        ldr     r2, .L20
>>        lsl     r3, r3, #2
>>        ldr     r0, [r3, r2]
>>        mov     pc, r0
>>        .align  2
>>        .align  2
>>.L18:
>>        b       .L3
>>        b       .L10
>>	...
>>
>>when compiling with -fpic. On thumb, the branch only takes +/- 2040
>>bytes as addresses, so branches out of that range are generated quite
>>fast in big functions.
>
>It looks to me like there are bigger problems with that code than out-of-range branches.  Does it actually work at all, even with small functions?
>
>You probably want to arrange to emit something like:
>
>	lsl	r3, r3, #2
>	add	r1, pc, #(.Lb - . - 4)		@ adr r1, .Lb
>	ldr	r3, [r1, r3]
>	add	r3, r1
>	mov	pc, r3
>
>.Lb
>	.word	.L1 - .Lb
>	.word	.L2 - .Lb
>	.word	.L3 - .Lb
>
>.L1:
>	...
>.L2:
>	...

The SH port works this way and even chooses .byte or .word (and .long ?)
if required. You may have a look at it.

Hartmut


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]