nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

how to align instructions?

Von: Tim Frink (plfriko@yahoo.de) [Profil]
Datum: 18.02.2008 11:03
Message-ID: <pan.2008.02.18.10.03.37.513999@yahoo.de>
Newsgroup: alt.lang.asm
Hi,

a known compiler optimization is to align branch targets
in order to avoid misalignment penalties and to improve
pipeline behavior for superscalar systems.

I was wondering how this is done in practice (for example
by the assembler when execute the ".align" directive).
Let's say you want to align all branch targets to an alignment
of 8 bytes. So, when you create a new basic block, you must
take care that the address of the first instruction in this
block is (MOD 8).

One way to achieve this would be to leave the memory addresses
between the last instruction of the previous block and the
first instruction of the block to be aligned unused (sort of
hole in the instruction memory) like this:

Block X:    ...
0x80000006: jge %d9,5,38 <_L3>

[hole]

Block X+1:
0x80000010: 8         mov %d8,0


But I think that this is not feasible since the program execution
will fail. The processor increments the program counter to the
instruction (target of fall-through edge) directly behind the
branch instruction (of the previous block) which would be assumed
at 0x8000000A (assume instructions are 32-bit wide). So, the program
counter will points to an address where no instruction is stored.


Another idea would be to perform a padding with NOPs between
the branch instruction and the branch targets like:

Block X:    ...
0x80000006: jge %d9,5,38 <_L3>
0x8000000A: nop (32-bit)
0x8000000E: nop (16-bit, for simplicity)

Block X+1:
0x80000010: 8         mov %d8,0

The problem here is that the NOPs somehow contradict the definition
of a basic block which should be left exclusively with the
last instruction. Here for Block X, the basic block is left
once at the JGE instruction and once after the second NOP.


So, both solutions seem not to be the right one. It would be possible
to add the NOPs before the branch instruction but I don't know
if this is feasible by an assembler which processes the instructions
sequentially.

Do you have any ideas how my alignment problem could be solved efficiently?

Regards,
Tim






[ Auf dieses Posting antworten ]

Antworten