1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- This file documents the GNU Assembler "as". 4 5Copyright (C) 1991-2021 Free Software Foundation, Inc. 6 7Permission is granted to copy, distribute and/or modify this document 8under the terms of the GNU Free Documentation License, Version 1.3 9or any later version published by the Free Software Foundation; 10with no Invariant Sections, with no Front-Cover Texts, and with no 11Back-Cover Texts. A copy of the license is included in the 12section entitled "GNU Free Documentation License". 13 --> 14<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 15<head> 16<title>Using as: Xtensa Automatic Alignment</title> 17 18<meta name="description" content="Using as: Xtensa Automatic Alignment"> 19<meta name="keywords" content="Using as: Xtensa Automatic Alignment"> 20<meta name="resource-type" content="document"> 21<meta name="distribution" content="global"> 22<meta name="Generator" content="makeinfo"> 23<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 24<link href="index.html#Top" rel="start" title="Top"> 25<link href="AS-Index.html#AS-Index" rel="index" title="AS Index"> 26<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 27<link href="Xtensa-Optimizations.html#Xtensa-Optimizations" rel="up" title="Xtensa Optimizations"> 28<link href="Xtensa-Relaxation.html#Xtensa-Relaxation" rel="next" title="Xtensa Relaxation"> 29<link href="Density-Instructions.html#Density-Instructions" rel="previous" title="Density Instructions"> 30<style type="text/css"> 31<!-- 32a.summary-letter {text-decoration: none} 33blockquote.smallquotation {font-size: smaller} 34div.display {margin-left: 3.2em} 35div.example {margin-left: 3.2em} 36div.indentedblock {margin-left: 3.2em} 37div.lisp {margin-left: 3.2em} 38div.smalldisplay {margin-left: 3.2em} 39div.smallexample {margin-left: 3.2em} 40div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 41div.smalllisp {margin-left: 3.2em} 42kbd {font-style:oblique} 43pre.display {font-family: inherit} 44pre.format {font-family: inherit} 45pre.menu-comment {font-family: serif} 46pre.menu-preformatted {font-family: serif} 47pre.smalldisplay {font-family: inherit; font-size: smaller} 48pre.smallexample {font-size: smaller} 49pre.smallformat {font-family: inherit; font-size: smaller} 50pre.smalllisp {font-size: smaller} 51span.nocodebreak {white-space:nowrap} 52span.nolinebreak {white-space:nowrap} 53span.roman {font-family:serif; font-weight:normal} 54span.sansserif {font-family:sans-serif; font-weight:normal} 55ul.no-bullet {list-style: none} 56--> 57</style> 58 59 60</head> 61 62<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 63<a name="Xtensa-Automatic-Alignment"></a> 64<div class="header"> 65<p> 66Previous: <a href="Density-Instructions.html#Density-Instructions" accesskey="p" rel="previous">Density Instructions</a>, Up: <a href="Xtensa-Optimizations.html#Xtensa-Optimizations" accesskey="u" rel="up">Xtensa Optimizations</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p> 67</div> 68<hr> 69<a name="Automatic-Instruction-Alignment"></a> 70<h4 class="subsubsection">9.55.3.2 Automatic Instruction Alignment</h4> 71<a name="index-alignment-of-LOOP-instructions"></a> 72<a name="index-alignment-of-branch-targets"></a> 73<a name="index-LOOP-instructions_002c-alignment"></a> 74<a name="index-branch-target-alignment"></a> 75 76<p>The Xtensa assembler will automatically align certain instructions, both 77to optimize performance and to satisfy architectural requirements. 78</p> 79<p>As an optimization to improve performance, the assembler attempts to 80align branch targets so they do not cross instruction fetch boundaries. 81(Xtensa processors can be configured with either 32-bit or 64-bit 82instruction fetch widths.) An 83instruction immediately following a call is treated as a branch target 84in this context, because it will be the target of a return from the 85call. This alignment has the potential to reduce branch penalties at 86some expense in code size. 87This optimization is enabled by default. You can disable it with the 88‘<samp>--no-target-align</samp>’ command-line option (see <a href="Xtensa-Options.html#Xtensa-Options">Command-line Options</a>). 89</p> 90<p>The target alignment optimization is done without adding instructions 91that could increase the execution time of the program. If there are 92density instructions in the code preceding a target, the assembler can 93change the target alignment by widening some of those instructions to 94the equivalent 24-bit instructions. Extra bytes of padding can be 95inserted immediately following unconditional jump and return 96instructions. 97This approach is usually successful in aligning many, but not all, 98branch targets. 99</p> 100<p>The <code>LOOP</code> family of instructions must be aligned such that the 101first instruction in the loop body does not cross an instruction fetch 102boundary (e.g., with a 32-bit fetch width, a <code>LOOP</code> instruction 103must be on either a 1 or 2 mod 4 byte boundary). The assembler knows 104about this restriction and inserts the minimal number of 2 or 3 byte 105no-op instructions to satisfy it. When no-op instructions are added, 106any label immediately preceding the original loop will be moved in order 107to refer to the loop instruction, not the newly generated no-op 108instruction. To preserve binary compatibility across processors with 109different fetch widths, the assembler conservatively assumes a 32-bit 110fetch width when aligning <code>LOOP</code> instructions (except if the first 111instruction in the loop is a 64-bit instruction). 112</p> 113<p>Previous versions of the assembler automatically aligned <code>ENTRY</code> 114instructions to 4-byte boundaries, but that alignment is now the 115programmer’s responsibility. 116</p> 117<hr> 118<div class="header"> 119<p> 120Previous: <a href="Density-Instructions.html#Density-Instructions" accesskey="p" rel="previous">Density Instructions</a>, Up: <a href="Xtensa-Optimizations.html#Xtensa-Optimizations" accesskey="u" rel="up">Xtensa Optimizations</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p> 121</div> 122 123 124 125</body> 126</html> 127