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: asm(...) and how to properly align jump labels


Richard Henderson <rth@redhat.com> writes:

> On Fri, Nov 28, 2003 at 01:18:48AM +0100, Denys Duchier wrote:
>> 
>> FAKE_OPCODE3:
>>   asm(".byte 3");
>>   asm(".p2align 4,3");
>>   asm(" TRUE_OPCODE3:");
>>   execute_opcode3();
>>
>[...]
>
> If you're going to do this, I recommend something like
>
> 	OPCODE3:
> 	  asm (" whatever data");
> 	  execute_opcode3();
>
> 	  ...
>
> 	  void *addr;
> 	  addr = labels[next_opcode];
> 	  addr += sizeof_data;
> 	  goto *addr;

Hi Richard, and thank you for for response

However, I am really sorry to be obtuse, but what exactly is this
fixing in my code?  I am not worried about _getting_ the correct
label.  That's easy with some additional assembly code.

> And have the data sized such that it is a multiple of the required
> instruction alignment of the platform.  E.g. 4 for risc machines.

well, that's what the .p2align was for.  the .byte 3 guarantees that
the opcode appears at least once, and the .p2align 4,3 guarantees that
the next label is aligned and that the intervening bytes are filled
with the opcode too.

My question was really about the platform-specific magic number to use
for instruction alignment.

Cheers,

-- 
Dr. Denys Duchier
Équipe Calligramme
LORIA, Nancy, FRANCE


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