This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why Thumb-2 only allows very limited access to the PC?
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Carrot Wei <carrot at google dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 05 Jan 2010 11:06:38 +0000
- Subject: Re: Why Thumb-2 only allows very limited access to the PC?
- References: <7587b291001042342m1f5437faib94c55b20792f5d2@mail.gmail.com>
On Tue, 2010-01-05 at 15:42 +0800, Carrot Wei wrote:
> Hi
>
> In function arm_load_pic_register in file arm.c there are following code:
>
> if (TARGET_ARM)
> {
> ...
> }
> else if (TARGET_THUMB2)
> {
> /* Thumb-2 only allows very limited access to the PC. Calculate the
> address in a temporary register. */
> if (arm_pic_register != INVALID_REGNUM)
> {
> pic_tmp = gen_rtx_REG (SImode,
> thumb_find_work_register (saved_regs));
> }
> else
> {
> gcc_assert (can_create_pseudo_p ());
> pic_tmp = gen_reg_rtx (Pmode);
> }
>
> emit_insn (gen_pic_load_addr_thumb2 (pic_reg, pic_rtx));
> emit_insn (gen_pic_load_dot_plus_four (pic_tmp, labelno));
> emit_insn (gen_addsi3 (pic_reg, pic_reg, pic_tmp));
> }
> else /* TARGET_THUMB1 */
> {
> ...
> }
>
> The comment said "Thumb-2 only allows very limited access to the PC.
> Calculate the address in a temporary register.". So the generated code
> is a little more complex than thumb1. Could anybody help to give more
> explanation on the limitation thumb2 has compared to thumb1?
>
> The generated instructions by this function for thumb1 is listed
> following, both instructions are available under thumb2.
>
> ldr r3, .L2
> .LPIC0:
> add r3, pc
I didn't write the comment, but I think the limitation is relative to
ARM not thumb1. Thumb2 code generator is a variation on the ARM code
generator, so the author was most likely thinking of that rather than
Thumb1.
R.