Why Thumb-2 only allows very limited access to the PC?

Carrot Wei carrot@google.com
Tue Jan 5 07:42:00 GMT 2010


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


thanks
Guozhi



More information about the Gcc mailing list