Update copyright years
[deliverable/binutils-gdb.git] / gas / config / tc-xtensa.c
index 2ed8adafd24d5e03fb2785d91c142a2f1738b433..fe8ec0fe3800908ea91bf6d18300c5a7122ce2de 100644 (file)
@@ -1,6 +1,5 @@
 /* tc-xtensa.c -- Assemble Xtensa instructions.
-   Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 2003-2014 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -19,8 +18,8 @@
    the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-#include <limits.h>
 #include "as.h"
+#include <limits.h>
 #include "sb.h"
 #include "safe-ctype.h"
 #include "tc-xtensa.h"
@@ -75,9 +74,6 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP";
 bfd_boolean density_supported = XCHAL_HAVE_DENSITY;
 bfd_boolean absolute_literals_supported = XSHAL_USE_ABSOLUTE_LITERALS;
 
-/* Maximum width we would pad an unreachable frag to get alignment.  */
-#define UNREACHABLE_MAX_WIDTH  8
-
 static vliw_insn cur_vinsn;
 
 unsigned xtensa_num_pipe_stages;
@@ -1324,18 +1320,18 @@ xtensa_end_directive (int ignore ATTRIBUTE_UNUSED)
 
   md_flush_pending_output ();
 
-  switch (end_directive)
+  switch ((int) end_directive)
     {
-    case (directiveE) XTENSA_UNDEFINED:
+    case XTENSA_UNDEFINED:
       discard_rest_of_line ();
       return;
 
-    case directive_density:
+    case (int) directive_density:
       as_warn (_(".end [no-]density is ignored"));
       demand_empty_rest_of_line ();
       break;
 
-    case directive_absolute_literals:
+    case (int) directive_absolute_literals:
       if (!absolute_literals_supported && !end_negated)
        {
          as_warn (_("Xtensa absolute literals option not supported; ignored"));
@@ -1455,6 +1451,9 @@ xtensa_literal_pseudo (int ignored ATTRIBUTE_UNUSED)
   if (use_literal_section || directive_state[directive_absolute_literals])
     dest_seg = now_seg;
 
+  /* FIXME, despite the previous comments, dest_seg is unused...  */
+  (void) dest_seg;
+
   /* All literals are aligned to four-byte boundaries.  */
   frag_align (2, 0, 0);
   record_alignment (now_seg, 2);
@@ -1826,6 +1825,7 @@ expression_maybe_register (xtensa_opcode opc, int opnd, expressionS *tok)
     {
       bfd_reloc_code_real_type reloc;
       segT t = expression (tok);
+
       if (t == absolute_section
          && xtensa_operand_is_PCrelative (isa, opc, opnd) == 1)
        {
@@ -3235,15 +3235,16 @@ xg_immeds_fit (const TInsn *insn)
   gas_assert (insn->insn_type == ITYPE_INSN);
   for (i = 0; i < n; ++i)
     {
-      const expressionS *expr = &insn->tok[i];
+      const expressionS *exp = &insn->tok[i];
+
       if (xtensa_operand_is_register (isa, insn->opcode, i) == 1)
        continue;
 
-      switch (expr->X_op)
+      switch (exp->X_op)
        {
        case O_register:
        case O_constant:
-         if (xg_check_operand (expr->X_add_number, insn->opcode, i))
+         if (xg_check_operand (exp->X_add_number, insn->opcode, i))
            return FALSE;
          break;
 
@@ -3279,15 +3280,16 @@ xg_symbolic_immeds_fit (const TInsn *insn,
 
   for (i = 0; i < n; ++i)
     {
-      const expressionS *expr = &insn->tok[i];
+      const expressionS *exp = &insn->tok[i];
+
       if (xtensa_operand_is_register (isa, insn->opcode, i) == 1)
        continue;
 
-      switch (expr->X_op)
+      switch (exp->X_op)
        {
        case O_register:
        case O_constant:
-         if (xg_check_operand (expr->X_add_number, insn->opcode, i))
+         if (xg_check_operand (exp->X_add_number, insn->opcode, i))
            return FALSE;
          break;
 
@@ -3307,8 +3309,8 @@ xg_symbolic_immeds_fit (const TInsn *insn,
 
          /* If it is a weak symbol or a symbol in a different section,
             it cannot be known to fit at assembly time.  */
-         if (S_IS_WEAK (expr->X_add_symbol)
-             || S_GET_SEGMENT (expr->X_add_symbol) != pc_seg)
+         if (S_IS_WEAK (exp->X_add_symbol)
+             || S_GET_SEGMENT (exp->X_add_symbol) != pc_seg)
            {
              /* For a direct call with --no-longcalls, be optimistic and
                 assume it will be in range.  If the symbol is weak and
@@ -3318,16 +3320,16 @@ xg_symbolic_immeds_fit (const TInsn *insn,
                 symbols even if longcalls is not enabled.  */
              if (is_direct_call_opcode (insn->opcode)
                  && ! pc_frag->tc_frag_data.use_longcalls
-                 && (! S_IS_WEAK (expr->X_add_symbol)
-                     || S_IS_DEFINED (expr->X_add_symbol)))
+                 && (! S_IS_WEAK (exp->X_add_symbol)
+                     || S_IS_DEFINED (exp->X_add_symbol)))
                return TRUE;
 
              return FALSE;
            }
 
-         symbolP = expr->X_add_symbol;
+         symbolP = exp->X_add_symbol;
          sym_frag = symbol_get_frag (symbolP);
-         target = S_GET_VALUE (symbolP) + expr->X_add_number;
+         target = S_GET_VALUE (symbolP) + exp->X_add_number;
          pc = pc_frag->fr_address + pc_offset;
 
          /* If frag has yet to be reached on this pass, assume it
@@ -3568,11 +3570,11 @@ xg_expand_to_stack (IStack *istack, TInsn *insn, int lateral_steps)
              /* Check to see if it fits.  */
              for (i = stack_size; i < istack->ninsn; i++)
                {
-                 TInsn *insn = &istack->insn[i];
+                 TInsn *tinsn = &istack->insn[i];
 
-                 if (insn->insn_type == ITYPE_INSN
-                     && !tinsn_has_symbolic_operands (insn)
-                     && !xg_immeds_fit (insn))
+                 if (tinsn->insn_type == ITYPE_INSN
+                     && !tinsn_has_symbolic_operands (tinsn)
+                     && !xg_immeds_fit (tinsn))
                    {
                      istack->ninsn = stack_size;
                      return FALSE;
@@ -4192,7 +4194,7 @@ xg_add_opcode_fix (TInsn *tinsn,
                   int opnum,
                   xtensa_format fmt,
                   int slot,
-                  expressionS *expr,
+                  expressionS *exp,
                   fragS *fragP,
                   offsetT offset)
 {
@@ -4212,15 +4214,15 @@ xg_add_opcode_fix (TInsn *tinsn,
     }
   else if (opcode == xtensa_const16_opcode)
     {
-      if (expr->X_op == O_lo16)
+      if (exp->X_op == O_lo16)
        {
          reloc = encode_reloc (slot);
-         expr->X_op = O_symbol;
+         exp->X_op = O_symbol;
        }
-      else if (expr->X_op == O_hi16)
+      else if (exp->X_op == O_hi16)
        {
          reloc = encode_alt_reloc (slot);
-         expr->X_op = O_symbol;
+         exp->X_op = O_symbol;
        }
     }
 
@@ -4234,7 +4236,7 @@ xg_add_opcode_fix (TInsn *tinsn,
   /* Handle erroneous "@h" and "@l" expressions here before they propagate
      into the symbol table where the generic portions of the assembler
      won't know what to do with them.  */
-  if (expr->X_op == O_lo16 || expr->X_op == O_hi16)
+  if (exp->X_op == O_lo16 || exp->X_op == O_hi16)
     {
       as_bad (_("invalid expression for operand %i of '%s'"),
              opnum + 1, xtensa_opcode_name (xtensa_default_isa, opcode));
@@ -4259,11 +4261,11 @@ xg_add_opcode_fix (TInsn *tinsn,
     }
 
   fmt_length = xtensa_format_length (xtensa_default_isa, fmt);
-  the_fix = fix_new_exp (fragP, offset, fmt_length, expr,
+  the_fix = fix_new_exp (fragP, offset, fmt_length, exp,
                         howto->pc_relative, reloc);
   the_fix->fx_no_overflow = 1;
-  the_fix->tc_fix_data.X_add_symbol = expr->X_add_symbol;
-  the_fix->tc_fix_data.X_add_number = expr->X_add_number;
+  the_fix->tc_fix_data.X_add_symbol = exp->X_add_symbol;
+  the_fix->tc_fix_data.X_add_number = exp->X_add_number;
   the_fix->tc_fix_data.slot = slot;
 
   return TRUE;
@@ -4521,12 +4523,18 @@ frag_format_size (const fragS *fragP)
         be accompanied by major changes to make use of that data.
 
         In any event, we can tell that we are expanding from a single-slot
-        three-byte format to a wider one with the logic below.  */
+        format to a wider one with the logic below.  */
 
-      if (fmt_size <= 3 && fragP->tc_frag_data.text_expansion[0] != 3)
-       return 3 + fragP->tc_frag_data.text_expansion[0];
-      else
-       return 3;
+      int i;
+      int relaxed_size = fmt_size + fragP->tc_frag_data.text_expansion[0];
+
+      for (i = 0; i < xtensa_isa_num_formats (isa); i++)
+       {
+         if (relaxed_size == xtensa_format_length (isa, i))
+           return relaxed_size;
+       }
+
+      return 3;
     }
 
   if (fragP->tc_frag_data.slot_subtypes[0] == RELAX_NARROW)
@@ -4643,6 +4651,12 @@ next_frag_is_loop_target (const fragS *fragP)
 }
 
 
+/* As specified in the relaxation table, when a loop instruction is
+   relaxed, there are 24 bytes between the loop instruction itself and
+   the first instruction in the loop.  */
+
+#define RELAXED_LOOP_INSN_BYTES 24
+
 static addressT
 next_frag_pre_opcode_bytes (const fragS *fragp)
 {
@@ -4665,7 +4679,7 @@ next_frag_pre_opcode_bytes (const fragS *fragp)
      been relaxed.  Note that we can assume that the LOOP
      instruction is in slot 0 because loops aren't bundleable.  */
   if (next_fragp->tc_frag_data.slot_subtypes[0] > RELAX_IMMED)
-      return get_expanded_loop_offset (next_opcode);
+      return get_expanded_loop_offset (next_opcode) + RELAXED_LOOP_INSN_BYTES;
 
   return 0;
 }
@@ -5004,16 +5018,22 @@ xtensa_find_unaligned_loops (bfd *abfd ATTRIBUTE_UNUSED,
              addressT frag_addr;
              xtensa_format fmt;
 
-             xtensa_insnbuf_from_chars
-               (isa, insnbuf, (unsigned char *) frag->fr_literal, 0);
-             fmt = xtensa_format_decode (isa, insnbuf);
-             op_size = xtensa_format_length (isa, fmt);
-             frag_addr = frag->fr_address % xtensa_fetch_width;
-
-             if (frag_addr + op_size > xtensa_fetch_width)
-               as_warn_where (frag->fr_file, frag->fr_line,
-                              _("unaligned loop: %d bytes at 0x%lx"),
-                              op_size, (long) frag->fr_address);
+             if (frag->fr_fix == 0)
+               frag = next_non_empty_frag (frag);
+             
+             if (frag)
+               {
+                 xtensa_insnbuf_from_chars
+                   (isa, insnbuf, (unsigned char *) frag->fr_literal, 0);
+                 fmt = xtensa_format_decode (isa, insnbuf);
+                 op_size = xtensa_format_length (isa, fmt);
+                 frag_addr = frag->fr_address % xtensa_fetch_width;
+                 
+                 if (frag_addr + op_size > xtensa_fetch_width)
+                   as_warn_where (frag->fr_file, frag->fr_line,
+                                  _("unaligned loop: %d bytes at 0x%lx"),
+                                  op_size, (long) frag->fr_address);
+               }
            }
          frag = frag->fr_next;
        }
@@ -5419,12 +5439,11 @@ md_assemble (char *str)
              bfd_reloc_code_real_type reloc;
              char *old_input_line_pointer;
              expressionS *tok = &orig_insn.extra_arg;
-             segT t;
 
              old_input_line_pointer = input_line_pointer;
              input_line_pointer = arg_strings[num_args - 1];
 
-             t = expression (tok);
+             expression (tok);
              if (tok->X_op == O_symbol
                  && ((reloc = xtensa_elf_suffix (&input_line_pointer, tok))
                      == BFD_RELOC_XTENSA_TLS_CALL))
@@ -7117,7 +7136,7 @@ xg_assemble_vliw_tokens (vliw_insn *vinsn)
        {
          gas_assert (finish_frag);
          frag_var (rs_machine_dependent,
-                   UNREACHABLE_MAX_WIDTH, UNREACHABLE_MAX_WIDTH,
+                   xtensa_fetch_width, xtensa_fetch_width,
                    RELAX_UNREACHABLE,
                    frag_now->fr_symbol, frag_now->fr_offset, NULL);
          xtensa_set_frag_assembly_state (frag_now);
@@ -7126,7 +7145,7 @@ xg_assemble_vliw_tokens (vliw_insn *vinsn)
        {
          gas_assert (finish_frag);
          frag_var (rs_machine_dependent,
-                   UNREACHABLE_MAX_WIDTH, UNREACHABLE_MAX_WIDTH,
+                   xtensa_fetch_width, xtensa_fetch_width,
                    RELAX_MAYBE_UNREACHABLE,
                    frag_now->fr_symbol, frag_now->fr_offset, NULL);
          xtensa_set_frag_assembly_state (frag_now);
@@ -7349,12 +7368,12 @@ static offsetT unrelaxed_frag_max_size (fragS *);
 static bfd_boolean
 is_narrow_branch_guaranteed_in_range (fragS *fragP, TInsn *tinsn)
 {
-  const expressionS *expr = &tinsn->tok[1];
-  symbolS *symbolP = expr->X_add_symbol;
-  offsetT max_distance = expr->X_add_number;
+  const expressionS *exp = &tinsn->tok[1];
+  symbolS *symbolP = exp->X_add_symbol;
+  offsetT max_distance = exp->X_add_number;
   fragS *target_frag;
 
-  if (expr->X_op != O_symbol)
+  if (exp->X_op != O_symbol)
     return FALSE;
 
   target_frag = symbol_get_frag (symbolP);
@@ -7395,9 +7414,36 @@ xtensa_mark_zcl_first_insns (void)
                    || fragP->fr_subtype == RELAX_CHECK_ALIGN_NEXT_OPCODE))
              {
                /* Find the loop frag.  */
-               fragS *targ_frag = next_non_empty_frag (fragP);
+               fragS *loop_frag = next_non_empty_frag (fragP);
                /* Find the first insn frag.  */
-               targ_frag = next_non_empty_frag (targ_frag);
+               fragS *targ_frag = next_non_empty_frag (loop_frag);
+
+             /* Handle a corner case that comes up in hardware
+                diagnostics.  The original assembly looks like this:
+                
+                loop aX, LabelA
+                <empty_frag>--not found by next_non_empty_frag
+                loop aY, LabelB
+
+                Depending on the start address, the assembler may or
+                may not change it to look something like this:
+
+                loop aX, LabelA
+                nop--frag isn't empty anymore
+                loop aY, LabelB
+
+                So set up to check the alignment of the nop if it
+                exists  */
+               while (loop_frag != targ_frag)
+                 {
+                   if (loop_frag->fr_type == rs_machine_dependent
+                       && (loop_frag->fr_subtype == RELAX_ALIGN_NEXT_OPCODE
+                           || loop_frag->fr_subtype 
+                           == RELAX_CHECK_ALIGN_NEXT_OPCODE))
+                     targ_frag = loop_frag;
+                   else
+                     loop_frag = loop_frag->fr_next;
+                 }
 
                /* Of course, sometimes (mostly for toy test cases) a
                   zero-cost loop instruction is the last in a section.  */
@@ -7441,12 +7487,12 @@ xtensa_mark_difference_of_two_symbols (void)
   for (expr_sym = expr_symbols; expr_sym; 
        expr_sym = symbol_get_tc (expr_sym)->next_expr_symbol)
     {
-      expressionS *expr = symbol_get_value_expression (expr_sym);
+      expressionS *exp = symbol_get_value_expression (expr_sym);
 
-      if (expr->X_op == O_subtract)
+      if (exp->X_op == O_subtract)
        {
-         symbolS *left = expr->X_add_symbol;
-         symbolS *right = expr->X_op_symbol;
+         symbolS *left = exp->X_add_symbol;
+         symbolS *right = exp->X_op_symbol;
          
          /* Difference of two symbols not in the same section
             are handled with relocations in the linker.  */
@@ -7848,7 +7894,6 @@ xtensa_fix_short_loop_frags (void)
     for (frchP = seg_info (s)->frchainP; frchP; frchP = frchP->frch_next)
       {
        fragS *fragP;
-       fragS *current_target = NULL;
        xtensa_opcode current_opcode = XTENSA_UNDEFINED;
 
        /* Walk over all of the fragments in a subsection.  */
@@ -7861,7 +7906,6 @@ xtensa_fix_short_loop_frags (void)
                TInsn t_insn;
                fragS *loop_frag = next_non_empty_frag (fragP);
                tinsn_from_chars (&t_insn, loop_frag->fr_opcode, 0);
-               current_target = symbol_get_frag (fragP->fr_symbol);
                current_opcode = t_insn.opcode;
                gas_assert (xtensa_opcode_is_loop (xtensa_default_isa,
                                               current_opcode) == 1);
@@ -8083,7 +8127,7 @@ xtensa_sanity_check (void)
 static bfd_boolean
 is_empty_loop (const TInsn *insn, fragS *fragP)
 {
-  const expressionS *expr;
+  const expressionS *exp;
   symbolS *symbolP;
   fragS *next_fragP;
 
@@ -8096,12 +8140,12 @@ is_empty_loop (const TInsn *insn, fragS *fragP)
   if (insn->ntok <= LOOP_IMMED_OPN)
     return FALSE;
 
-  expr = &insn->tok[LOOP_IMMED_OPN];
+  exp = &insn->tok[LOOP_IMMED_OPN];
 
-  if (expr->X_op != O_symbol)
+  if (exp->X_op != O_symbol)
     return FALSE;
 
-  symbolP = expr->X_add_symbol;
+  symbolP = exp->X_add_symbol;
   if (!symbolP)
     return FALSE;
 
@@ -8130,7 +8174,7 @@ is_empty_loop (const TInsn *insn, fragS *fragP)
 static bfd_boolean
 is_local_forward_loop (const TInsn *insn, fragS *fragP)
 {
-  const expressionS *expr;
+  const expressionS *exp;
   symbolS *symbolP;
   fragS *next_fragP;
 
@@ -8143,12 +8187,12 @@ is_local_forward_loop (const TInsn *insn, fragS *fragP)
   if (insn->ntok <= LOOP_IMMED_OPN)
     return FALSE;
 
-  expr = &insn->tok[LOOP_IMMED_OPN];
+  exp = &insn->tok[LOOP_IMMED_OPN];
 
-  if (expr->X_op != O_symbol)
+  if (exp->X_op != O_symbol)
     return FALSE;
 
-  symbolP = expr->X_add_symbol;
+  symbolP = exp->X_add_symbol;
   if (!symbolP)
     return FALSE;
 
@@ -8226,8 +8270,33 @@ get_text_align_power (unsigned target_size)
 {
   if (target_size <= 4)
     return 2;
-  gas_assert (target_size == 8);
-  return 3;
+
+  if (target_size <= 8)
+    return 3;
+
+  if (target_size <= 16)
+    return 4;
+
+  if (target_size <= 32)
+    return 5;
+
+  if (target_size <= 64)
+    return 6;
+
+  if (target_size <= 128)
+    return 7;
+
+  if (target_size <= 256)
+    return 8;
+
+  if (target_size <= 512)
+    return 9;
+
+  if (target_size <= 1024)
+    return 10;
+
+  gas_assert (0);
+  return 0;
 }
 
 
@@ -8300,19 +8369,17 @@ get_text_align_fill_size (addressT address,
 static int
 branch_align_power (segT sec)
 {
-  /* If the Xtensa processor has a fetch width of 8 bytes, and the section
-     is aligned to at least an 8-byte boundary, then a branch target need
-     only fit within an 8-byte aligned block of memory to avoid a stall.
-     Otherwise, try to fit branch targets within 4-byte aligned blocks
-     (which may be insufficient, e.g., if the section has no alignment, but
-     it's good enough).  */
-  if (xtensa_fetch_width == 8)
-    {
-      if (get_recorded_alignment (sec) >= 3)
-       return 3;
-    }
-  else
-    gas_assert (xtensa_fetch_width == 4);
+  /* If the Xtensa processor has a fetch width of X, and
+     the section is aligned to at least that boundary, then a branch
+     target need only fit within that aligned block of memory to avoid
+     a stall.  Otherwise, try to fit branch targets within 4-byte
+     aligned blocks (which may be insufficient, e.g., if the section
+     has no alignment, but it's good enough).  */
+  int fetch_align = get_text_align_power(xtensa_fetch_width);
+  int sec_align = get_recorded_alignment (sec);
+
+  if (sec_align >= fetch_align)
+    return fetch_align;
 
   return 2;
 }
@@ -8810,7 +8877,7 @@ find_address_of_next_align_frag (fragS **fragPP,
                  (*widens)++;
                  break;
                }
-             address += total_frag_text_expansion (fragP);;
+             address += total_frag_text_expansion (fragP);
              break;
 
            case RELAX_IMMED:
@@ -8938,7 +9005,7 @@ future_alignment_required (fragS *fragP, long stretch ATTRIBUTE_UNUSED)
        {
          if (this_frag->fr_subtype == RELAX_UNREACHABLE)
            {
-             gas_assert (opt_diff <= UNREACHABLE_MAX_WIDTH);
+             gas_assert (opt_diff <= (signed) xtensa_fetch_width);
              return opt_diff;
            }
          return 0;
@@ -8976,39 +9043,11 @@ future_alignment_required (fragS *fragP, long stretch ATTRIBUTE_UNUSED)
 /* The idea: widen everything you can to get a target or loop aligned,
    then start using NOPs.
 
-   When we must have a NOP, here is a table of how we decide
-   (so you don't have to fight through the control flow below):
-
    wide_nops   = the number of wide NOPs available for aligning
    narrow_nops = the number of narrow NOPs available for aligning
                 (a subset of wide_nops)
    widens      = the number of narrow instructions that should be widened
 
-   Desired   wide   narrow
-   Diff      nop    nop      widens
-   1           0      0         1
-   2           0      1         0
-   3a          1      0         0
-    b          0      1         1 (case 3a makes this case unnecessary)
-   4a          1      0         1
-    b          0      2         0
-    c          0      1         2 (case 4a makes this case unnecessary)
-   5a          1      0         2
-    b          1      1         0
-    c          0      2         1 (case 5b makes this case unnecessary)
-   6a          2      0         0
-    b          1      0         3
-    c          0      1         4 (case 6b makes this case unnecessary)
-    d          1      1         1 (case 6a makes this case unnecessary)
-    e          0      2         2 (case 6a makes this case unnecessary)
-    f          0      3         0 (case 6a makes this case unnecessary)
-   7a          1      0         4
-    b          2      0         1
-    c          1      1         2 (case 7b makes this case unnecessary)
-    d          0      1         5 (case 7a makes this case unnecessary)
-    e          0      2         3 (case 7b makes this case unnecessary)
-    f          0      3         1 (case 7b makes this case unnecessary)
-    g          1      2         1 (case 7b makes this case unnecessary)
 */
 
 static long
@@ -9018,9 +9057,13 @@ bytes_to_stretch (fragS *this_frag,
                  int num_widens,
                  int desired_diff)
 {
+  int nops_needed;
+  int nop_bytes;
+  int extra_bytes;
   int bytes_short = desired_diff - num_widens;
 
-  gas_assert (desired_diff >= 0 && desired_diff < 8);
+  gas_assert (desired_diff >= 0 
+             && desired_diff < (signed) xtensa_fetch_width);
   if (desired_diff == 0)
     return 0;
 
@@ -9047,100 +9090,58 @@ bytes_to_stretch (fragS *this_frag,
   /* From here we will need at least one NOP to get an alignment.
      However, we may not be able to align at all, in which case,
      don't widen.  */
-  if (this_frag->fr_subtype == RELAX_FILL_NOP)
+  nops_needed = desired_diff / 3;
+
+  /* If there aren't enough nops, don't widen.  */
+  if (nops_needed > wide_nops)
+    return 0;
+
+  /* First try it with all wide nops.  */
+  nop_bytes = nops_needed * 3;
+  extra_bytes = desired_diff - nop_bytes;
+
+  if (nop_bytes + num_widens >= desired_diff)
     {
-      switch (desired_diff)
-       {
-       case 1:
-         return 0;
-       case 2:
-         if (!this_frag->tc_frag_data.is_no_density && narrow_nops == 1)
-           return 2; /* case 2 */
-         return 0;
-       case 3:
-         if (wide_nops > 1)
-           return 0;
-         else
-           return 3; /* case 3a */
-       case 4:
-         if (num_widens >= 1 && wide_nops == 1)
-           return 3; /* case 4a */
-         if (!this_frag->tc_frag_data.is_no_density && narrow_nops == 2)
-           return 2; /* case 4b */
-         return 0;
-       case 5:
-         if (num_widens >= 2 && wide_nops == 1)
-           return 3; /* case 5a */
-         /* We will need two nops.  Are there enough nops
-            between here and the align target?  */
-         if (wide_nops < 2 || narrow_nops == 0)
-           return 0;
-         /* Are there other nops closer that can serve instead?  */
-         if (wide_nops > 2 && narrow_nops > 1)
-           return 0;
-         /* Take the density one first, because there might not be
-            another density one available.  */
-         if (!this_frag->tc_frag_data.is_no_density)
-           return 2; /* case 5b narrow */
-         else
-           return 3; /* case 5b wide */
-         return 0;
-       case 6:
-         if (wide_nops == 2)
-           return 3; /* case 6a */
-         else if (num_widens >= 3 && wide_nops == 1)
-           return 3; /* case 6b */
-         return 0;
-       case 7:
-         if (wide_nops == 1 && num_widens >= 4)
-           return 3; /* case 7a */
-         else if (wide_nops == 2 && num_widens >= 1)
-           return 3; /* case 7b */
-         return 0;
-       default:
-         gas_assert (0);
-       }
+      if (this_frag->fr_subtype == RELAX_FILL_NOP)
+       return 3;
+      else if (num_widens == extra_bytes)
+       return 1;
+      return 0;
     }
-  else
+
+  /* Add a narrow nop.  */
+  nops_needed++;
+  nop_bytes += 2;
+  extra_bytes -= 2;
+  if (narrow_nops == 0 || nops_needed > wide_nops)
+    return 0;
+
+  if (nop_bytes + num_widens >= desired_diff && extra_bytes >= 0)
     {
-      /* We will need a NOP no matter what, but should we widen
-        this instruction to help?
+      if (this_frag->fr_subtype == RELAX_FILL_NOP)
+       return !this_frag->tc_frag_data.is_no_density ? 2 : 3;
+      else if (num_widens == extra_bytes)
+       return 1;
+      return 0;
+    }
 
-        This is a RELAX_NARROW frag.  */
-      switch (desired_diff)
-       {
-       case 1:
-         gas_assert (0);
-         return 0;
-       case 2:
-       case 3:
-         return 0;
-       case 4:
-         if (wide_nops >= 1 && num_widens == 1)
-           return 1; /* case 4a */
-         return 0;
-       case 5:
-         if (wide_nops >= 1 && num_widens == 2)
-           return 1; /* case 5a */
-         return 0;
-       case 6:
-         if (wide_nops >= 2)
-           return 0; /* case 6a */
-         else if (wide_nops >= 1 && num_widens == 3)
-           return 1; /* case 6b */
-         return 0;
-       case 7:
-         if (wide_nops >= 1 && num_widens == 4)
-           return 1; /* case 7a */
-         else if (wide_nops >= 2 && num_widens == 1)
-           return 1; /* case 7b */
-         return 0;
-       default:
-         gas_assert (0);
-         return 0;
-       }
+  /* Replace a wide nop with a narrow nop--we can get here if
+     extra_bytes was negative in the previous conditional.  */
+  if (narrow_nops == 1)
+    return 0;
+  nop_bytes--;
+  extra_bytes++;
+  if (nop_bytes + num_widens >= desired_diff)
+    {
+      if (this_frag->fr_subtype == RELAX_FILL_NOP)
+       return !this_frag->tc_frag_data.is_no_density ? 2 : 3;
+      else if (num_widens == extra_bytes)
+       return 1;
+      return 0;
     }
-  gas_assert (0);
+
+  /* If we can't satisfy any of the above cases, then we can't align
+     using padding or fill nops.  */
   return 0;
 }
 
@@ -9596,7 +9597,6 @@ convert_frag_immed (segT segP,
       symbolS *gen_label = NULL;
       offsetT frag_offset;
       bfd_boolean first = TRUE;
-      bfd_boolean last_is_jump;
 
       /* It does not fit.  Find something that does and
          convert immediately.  */
@@ -9671,7 +9671,6 @@ convert_frag_immed (segT segP,
 
       total_size = 0;
       first = TRUE;
-      last_is_jump = FALSE;
       for (i = 0; i < istack.ninsn; i++)
        {
          TInsn *tinsn = &istack.insn[i];
@@ -10062,7 +10061,7 @@ xtensa_move_literals (void)
 {
   seg_list *segment;
   frchainS *frchain_from, *frchain_to;
-  fragS *search_frag, *next_frag, *last_frag, *literal_pool, *insert_after;
+  fragS *search_frag, *next_frag, *literal_pool, *insert_after;
   fragS **frag_splice;
   emit_state state;
   segT dest_seg;
@@ -10104,7 +10103,6 @@ xtensa_move_literals (void)
         frags in it.  */
       frag_variant (rs_fill, 0, 0, 0, NULL, 0, NULL);
       xtensa_set_frag_assembly_state (frag_now);
-      last_frag = frag_now;
       frag_variant (rs_fill, 0, 0, 0, NULL, 0, NULL);
       xtensa_set_frag_assembly_state (frag_now);
 
@@ -10167,9 +10165,9 @@ xtensa_move_literals (void)
   for (lit = literal_syms; lit; lit = lit->next)
     {
       symbolS *lit_sym = lit->sym;
-      segT dest_seg = symbol_get_frag (lit_sym)->tc_frag_data.lit_seg;
-      if (dest_seg)
-       S_SET_SEGMENT (lit_sym, dest_seg);
+      segT dseg = symbol_get_frag (lit_sym)->tc_frag_data.lit_seg;
+      if (dseg)
+       S_SET_SEGMENT (lit_sym, dseg);
     }
 }
 
@@ -10421,15 +10419,25 @@ cache_literal_section (bfd_boolean use_abs_literals)
     }
   else
     {
-      /* If the section name ends with ".text", then replace that suffix
-        instead of appending an additional suffix.  */
+      /* If the section name begins or ends with ".text", then replace
+        that portion instead of appending an additional suffix.  */
       size_t len = strlen (text_name);
-      if (len >= 5 && strcmp (text_name + len - 5, ".text") == 0)
+      if (len >= 5
+         && (strcmp (text_name + len - 5, ".text") == 0
+             || strncmp (text_name, ".text", 5) == 0))
        len -= 5;
 
       name = xmalloc (len + strlen (base_name) + 1);
-      strcpy (name, text_name);
-      strcpy (name + len, base_name);
+      if (strncmp (text_name, ".text", 5) == 0)
+       {
+         strcpy (name, base_name);
+         strcat (name, text_name + 5);
+       }
+      else
+       {
+         strcpy (name, text_name);
+         strcpy (name + len, base_name);
+       }
     }
 
   /* Canonicalize section names to allow renaming literal sections.
@@ -11191,7 +11199,6 @@ xg_get_single_slot (xtensa_opcode opcode)
 void
 istack_init (IStack *stack)
 {
-  memset (stack, 0, sizeof (IStack));
   stack->ninsn = 0;
 }
 
@@ -11401,20 +11408,20 @@ tinsn_to_slotbuf (xtensa_format fmt,
 
   for (i = 0; i < noperands; i++)
     {
-      expressionS *expr = &tinsn->tok[i];
+      expressionS *exp = &tinsn->tok[i];
       int rc;
       unsigned line;
       char *file_name;
       uint32 opnd_value;
 
-      switch (expr->X_op)
+      switch (exp->X_op)
        {
        case O_register:
          if (xtensa_operand_is_visible (isa, opcode, i) == 0)
            break;
          /* The register number has already been checked in
             expression_maybe_register, so we don't need to check here.  */
-         opnd_value = expr->X_add_number;
+         opnd_value = exp->X_add_number;
          (void) xtensa_operand_encode (isa, opcode, i, &opnd_value);
          rc = xtensa_operand_set_field (isa, opcode, i, fmt, slot, slotbuf,
                                         opnd_value);
@@ -11429,7 +11436,7 @@ tinsn_to_slotbuf (xtensa_format fmt,
          /* It is a constant and we called this function
             then we have to try to fit it.  */
          xtensa_insnbuf_set_operand (slotbuf, fmt, slot, opcode, i,
-                                     expr->X_add_number, file_name, line);
+                                     exp->X_add_number, file_name, line);
          break;
 
        default:
@@ -11783,8 +11790,8 @@ vinsn_to_insnbuf (vliw_insn *vinsn,
 
          for (i = 0; i < noperands; i++)
            {
-             expressionS* expr = &tinsn->tok[i];
-             switch (expr->X_op)
+             expressionS* exp = &tinsn->tok[i];
+             switch (exp->X_op)
                {
                case O_symbol:
                case O_lo16:
@@ -11799,15 +11806,15 @@ vinsn_to_insnbuf (vliw_insn *vinsn,
                          || tinsn->is_specific_opcode
                          || !xg_is_relaxable_insn (tinsn, 0))
                        {
-                         xg_add_opcode_fix (tinsn, i, fmt, slot, expr, fragP,
+                         xg_add_opcode_fix (tinsn, i, fmt, slot, exp, fragP,
                                             frag_offset - fragP->fr_literal);
                        }
                      else
                        {
-                         if (expr->X_op != O_symbol)
+                         if (exp->X_op != O_symbol)
                            as_bad (_("invalid operand"));
-                         tinsn->symbol = expr->X_add_symbol;
-                         tinsn->offset = expr->X_add_number;
+                         tinsn->symbol = exp->X_add_symbol;
+                         tinsn->offset = exp->X_add_number;
                        }
                    }
                  else
This page took 0.047196 seconds and 4 git commands to generate.