<html lang="en">
<head>
<title>Xtensa Automatic Alignment - Using as</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using as">
<meta name="generator" content="makeinfo 4.8">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Xtensa-Optimizations.html#Xtensa-Optimizations" title="Xtensa Optimizations">
<link rel="prev" href="Density-Instructions.html#Density-Instructions" title="Density Instructions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
@import url("../raisonance.css");
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Xtensa-Automatic-Alignment"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Density-Instructions.html#Density-Instructions">Density Instructions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Xtensa-Optimizations.html#Xtensa-Optimizations">Xtensa Optimizations</a>
<hr>
</div>

<h5 class="subsubsection">8.34.3.2 Automatic Instruction Alignment</h5>

<p><a name="index-alignment-of-_0040code_007bLOOP_007d-instructions-1778"></a><a name="index-alignment-of-_0040code_007bENTRY_007d-instructions-1779"></a><a name="index-alignment-of-branch-targets-1780"></a><a name="index-g_t_0040code_007bLOOP_007d-instructions_002c-alignment-1781"></a><a name="index-g_t_0040code_007bENTRY_007d-instructions_002c-alignment-1782"></a><a name="index-branch-target-alignment-1783"></a>
The Xtensa assembler will automatically align certain instructions, both
to optimize performance and to satisfy architectural requirements.

   <p>As an optimization to improve performance, the assembler attempts to
align branch targets so they do not cross instruction fetch boundaries. 
(Xtensa processors can be configured with either 32-bit or 64-bit
instruction fetch widths.)  An
instruction immediately following a call is treated as a branch target
in this context, because it will be the target of a return from the
call.  This alignment has the potential to reduce branch penalties at
some expense in code size.  The assembler will not attempt to align
labels with the prefixes <code>.Ln</code> and <code>.LM</code>, since these labels
are used for debugging information and are not typically branch targets. 
This optimization is enabled by default.  You can disable it with the
`<samp><span class="samp">--no-target-align</span></samp>' command-line option (see <a href="Xtensa-Options.html#Xtensa-Options">Command Line Options</a>).

   <p>The target alignment optimization is done without adding instructions
that could increase the execution time of the program.  If there are
density instructions in the code preceding a target, the assembler can
change the target alignment by widening some of those instructions to
the equivalent 24-bit instructions.  Extra bytes of padding can be
inserted immediately following unconditional jump and return
instructions. 
This approach is usually successful in aligning many, but not all,
branch targets.

   <p>The <code>LOOP</code> family of instructions must be aligned such that the
first instruction in the loop body does not cross an instruction fetch
boundary (e.g., with a 32-bit fetch width, a <code>LOOP</code> instruction
must be on either a 1 or 2 mod 4 byte boundary).  The assembler knows
about this restriction and inserts the minimal number of 2 or 3 byte
no-op instructions to satisfy it.  When no-op instructions are added,
any label immediately preceding the original loop will be moved in order
to refer to the loop instruction, not the newly generated no-op
instruction.  To preserve binary compatibility across processors with
different fetch widths, the assembler conservatively assumes a 32-bit
fetch width when aligning <code>LOOP</code> instructions (except if the first
instruction in the loop is a 64-bit instruction).

   <p>Similarly, the <code>ENTRY</code> instruction must be aligned on a 0 mod 4
byte boundary.  The assembler satisfies this requirement by inserting
zero bytes when required.  In addition, labels immediately preceding the
<code>ENTRY</code> instruction will be moved to the newly aligned instruction
location.

   </body></html>

