public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ARM long branch stubs: cleanup2
@ 2009-03-17 17:12 Christophe LYON
  2009-04-01 15:06 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe LYON @ 2009-03-17 17:12 UTC (permalink / raw)
  To: Binutils

[-- Attachment #1: Type: text/plain, Size: 180 bytes --]

Hi all,

I propose the attached small patch which improves readability of some 
loops. It's probably a matter of taste, but I find this version easier 
to understand.

Christophe.

[-- Attachment #2: loops.changelog --]
[-- Type: text/plain, Size: 133 bytes --]

2009-03-17  Christophe Lyon  <christophe.lyon@st.com>

	bfd/
	* elf32-arm.c (group_sections): Rewrite loops for better
	readability.

[-- Attachment #3: loops.patch --]
[-- Type: text/plain, Size: 2814 bytes --]

Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.182
diff -u -p -r1.182 elf32-arm.c
--- bfd/elf32-arm.c	17 Mar 2009 14:50:48 -0000	1.182
+++ bfd/elf32-arm.c	17 Mar 2009 17:08:10 -0000
@@ -3525,7 +3525,6 @@ group_sections (struct elf32_arm_link_ha
     {
       asection *tail = *list;
       asection *head;
-      asection *tp;
 
       if (tail == bfd_abs_section_ptr)
 	continue;
@@ -3535,38 +3534,35 @@ group_sections (struct elf32_arm_link_ha
 	 section may be required for an interrupt vector in bare metal
 	 code.  */
 #define NEXT_SEC PREV_SEC
-      head = tail;
-      tp = NULL;
-      for (;;)
-	{
-	  asection *h = PREV_SEC (head);
-	  NEXT_SEC (head) = tp;
-	  if (h == NULL)
-	    break;
-	  tp = head;
-	  head = h;
-	}
+      head = NULL;
+      while (tail != NULL)
+        {
+          /* Pop from tail */
+          asection *item = tail;
+          tail = PREV_SEC(item);
+
+          /* Push on head */
+          NEXT_SEC(item) = head;
+          head = item;
+        }
 
       while (head != NULL)
 	{
 	  asection *curr;
 	  asection *next;
-	  bfd_size_type total;
+	  bfd_vma stub_group_start = head->output_offset;
+	  bfd_vma end_of_next;
 
 	  curr = head;
-	  total = 0;
-	  while ((next = NEXT_SEC (curr)) != NULL)
+	  while (NEXT_SEC (curr) != NULL)
 	    {
-	      if ( (total + next->output_offset - curr->output_offset
-		    + next->size)
-		   < stub_group_size )
-		{
-		  total += next->output_offset - curr->output_offset;
-		}
-	      else
+	      next = NEXT_SEC(curr);
+	      end_of_next = next->output_offset + next->size;
+	      if (end_of_next - stub_group_start >= stub_group_size)
+		/* End of NEXT is too far from start, so stop */
 		break;
-
-	    curr = next;
+	      /* Add NEXT to the group. */
+	      curr = next;
 	    }
 
 	  /* OK, the size from the start to the start of CURR is less
@@ -3588,20 +3584,17 @@ group_sections (struct elf32_arm_link_ha
 	     bytes after the stub section can be handled by it too.  */
 	  if (!stubs_always_after_branch)
 	    {
-	      total = head->size;
+	      stub_group_start = curr->output_offset + curr->size;
+
 	      while (next != NULL)
 		{
-		  if ( (total + next->output_offset - head->output_offset
-			+ next->size)
-		       < stub_group_size )
-		    {
-		      total += next->output_offset - head->output_offset;
-		    }
-		  else
+		  end_of_next = next->output_offset + next->size;
+		  if (end_of_next - stub_group_start >= stub_group_size)
+		    /* End of NEXT is too far from stubs, so stop */
 		    break;
-
+		  /* Add NEXT to the stub group */
 		  head = next;
-		  next = NEXT_SEC (head);
+		  next = NEXT_SEC(head);
 		  htab->stub_group[head->id].link_sec = curr;
 		}
 	    }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ARM long branch stubs: cleanup2
  2009-03-17 17:12 ARM long branch stubs: cleanup2 Christophe LYON
@ 2009-04-01 15:06 ` Nick Clifton
  2009-04-01 15:35   ` Christophe LYON
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2009-04-01 15:06 UTC (permalink / raw)
  To: Christophe LYON; +Cc: Binutils

Hi Christophe,

> I propose the attached small patch which improves readability of some 
> loops. It's probably a matter of taste, but I find this version easier 
> to understand.

Approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ARM long branch stubs: cleanup2
  2009-04-01 15:06 ` Nick Clifton
@ 2009-04-01 15:35   ` Christophe LYON
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe LYON @ 2009-04-01 15:35 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Binutils

On 01.04.2009 17:06, Nick Clifton wrote:
> Hi Christophe,
> 
>> I propose the attached small patch which improves readability of some 
>> loops. It's probably a matter of taste, but I find this version easier 
>> to understand.
> 
> Approved - please apply.
> 
Thanks, committed after fixing a few missing spaces before parentheses.

Christophe.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-01 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-17 17:12 ARM long branch stubs: cleanup2 Christophe LYON
2009-04-01 15:06 ` Nick Clifton
2009-04-01 15:35   ` Christophe LYON

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).