public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch] opcodes/z8k-opc.h regenerated
@ 2009-09-04 13:00 Tristan Gingold
  2009-09-04 15:33 ` Nick Clifton
  0 siblings, 1 reply; 19+ messages in thread
From: Tristan Gingold @ 2009-09-04 13:00 UTC (permalink / raw)
  To: binutils

Hi,

strangely enough the regenerated opcodes/z8k-opc.h is different from the
previous one.  Hence this patch.

Ok to commit ?  (Will back-port too).

(Not sure z8k is still in use by someone but who knows ?)


Tristan.

2009-09-04  Tristan Gingold  <gingold@adacore.com>

	* z8k-opc.h: Regenerate.


Index: z8k-opc.h
===================================================================
RCS file: /cvs/src/src/opcodes/z8k-opc.h,v
retrieving revision 1.12
diff -c -r1.12 z8k-opc.h
*** z8k-opc.h	25 Aug 2009 03:13:44 -0000	1.12
--- z8k-opc.h	4 Sep 2009 12:58:55 -0000
***************
*** 1820,1840 ****
  "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_X+(ARG_RS),},
  	{CLASS_BIT+6,CLASS_BIT+0,CLASS_REGN0+(ARG_RS),CLASS_REG+(ARG_RD),CLASS_ADDRESS+(ARG_SRC),0,0,0,0,},2,4,74},
  
! /* 1100 dddd imm8 *** ldb rbd,imm8 */
  {
  #ifdef NICENAMES
! "ldb rbd,imm8",8,5,0x00,
  #endif
  "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_IMM+(ARG_IMM8),},
! 	{CLASS_BIT+0xc,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),0,0,0,0,0,0,},2,2,74},
  
! /* 0010 0000 0000 dddd imm8 imm8 *** ldb rbd,imm8 */
  {
  #ifdef NICENAMES
! "ldb rbd,imm8",8,7,0x00,
  #endif
  "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_IMM+(ARG_IMM8),},
! 	{CLASS_BIT+2,CLASS_BIT+0,CLASS_BIT+0,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),CLASS_IMM+(ARG_IMM8),0,0,0,},2,4,74},
  
  /* 1010 0000 ssss dddd *** ldb rbd,rbs */
  {
--- 1820,1840 ----
  "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_X+(ARG_RS),},
  	{CLASS_BIT+6,CLASS_BIT+0,CLASS_REGN0+(ARG_RS),CLASS_REG+(ARG_RD),CLASS_ADDRESS+(ARG_SRC),0,0,0,0,},2,4,74},
  
! /* 0010 0000 0000 dddd imm8 imm8 *** ldb rbd,imm8 */
  {
  #ifdef NICENAMES
! "ldb rbd,imm8",8,7,0x00,
  #endif
  "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_IMM+(ARG_IMM8),},
! 	{CLASS_BIT+2,CLASS_BIT+0,CLASS_BIT+0,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),CLASS_IMM+(ARG_IMM8),0,0,0,},2,4,74},
  
! /* 1100 dddd imm8 *** ldb rbd,imm8 */
  {
  #ifdef NICENAMES
! "ldb rbd,imm8",8,5,0x00,
  #endif
  "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_IMM+(ARG_IMM8),},
! 	{CLASS_BIT+0xc,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),0,0,0,0,0,0,},2,2,74},
  
  /* 1010 0000 ssss dddd *** ldb rbd,rbs */
  {
***************
*** 3791,3797 ****
  /* 1000 1000 ssss dddd *** xorb rbd,rbs */
  {
  #ifdef NICENAMES
! "xorb rbd,rbs",8,4,0x1c,
  #endif
  "xorb",OPC_xorb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_REG_BYTE+(ARG_RS),},
  	{CLASS_BIT+8,CLASS_BIT+8,CLASS_REG+(ARG_RS),CLASS_REG+(ARG_RD),0,0,0,0,0,},2,2,203},
--- 3791,3797 ----
  /* 1000 1000 ssss dddd *** xorb rbd,rbs */
  {
  #ifdef NICENAMES
! "xorb rbd,rbs",8,4,0x01,
  #endif
  "xorb",OPC_xorb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_REG_BYTE+(ARG_RS),},
  	{CLASS_BIT+8,CLASS_BIT+8,CLASS_REG+(ARG_RS),CLASS_REG+(ARG_RD),0,0,0,0,0,},2,2,203},
***************
*** 3799,3805 ****
  /* 1000 1000 ssss dddd *** xorb rbd,rbs */
  {
  #ifdef NICENAMES
! "xorb rbd,rbs",8,4,0x01,
  #endif
  "xorb",OPC_xorb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_REG_BYTE+(ARG_RS),},
  	{CLASS_BIT+8,CLASS_BIT+8,CLASS_REG+(ARG_RS),CLASS_REG+(ARG_RD),0,0,0,0,0,},2,2,203},
--- 3799,3805 ----
  /* 1000 1000 ssss dddd *** xorb rbd,rbs */
  {
  #ifdef NICENAMES
! "xorb rbd,rbs",8,4,0x1c,
  #endif
  "xorb",OPC_xorb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_REG_BYTE+(ARG_RS),},
  	{CLASS_BIT+8,CLASS_BIT+8,CLASS_REG+(ARG_RS),CLASS_REG+(ARG_RD),0,0,0,0,0,},2,2,203},

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-04 13:00 [Patch] opcodes/z8k-opc.h regenerated Tristan Gingold
@ 2009-09-04 15:33 ` Nick Clifton
  2009-09-07  8:30   ` Tristan Gingold
  0 siblings, 1 reply; 19+ messages in thread
From: Nick Clifton @ 2009-09-04 15:33 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

Hi Tristan,

> strangely enough the regenerated opcodes/z8k-opc.h is different from the
> previous one.  Hence this patch.
> 
> Ok to commit ?  (Will back-port too).

Approved - please apply.

Cheers
   Nick

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-04 15:33 ` Nick Clifton
@ 2009-09-07  8:30   ` Tristan Gingold
  2009-09-07 11:18     ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Tristan Gingold @ 2009-09-07  8:30 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils


On Sep 4, 2009, at 5:33 PM, Nick Clifton wrote:

> Hi Tristan,
>
>> strangely enough the regenerated opcodes/z8k-opc.h is different  
>> from the
>> previous one.  Hence this patch.
>> Ok to commit ?  (Will back-port too).
>
> Approved - please apply.

Thanks.  Committed on both head and 2_20 branch.

Tristan.

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07  8:30   ` Tristan Gingold
@ 2009-09-07 11:18     ` Alan Modra
  2009-09-07 11:37       ` Alan Modra
  2009-09-07 11:38       ` Tristan Gingold
  0 siblings, 2 replies; 19+ messages in thread
From: Alan Modra @ 2009-09-07 11:18 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Nick Clifton, binutils

On Mon, Sep 07, 2009 at 10:29:32AM +0200, Tristan Gingold wrote:
>
> On Sep 4, 2009, at 5:33 PM, Nick Clifton wrote:
>
>> Hi Tristan,
>>
>>> strangely enough the regenerated opcodes/z8k-opc.h is different from 
>>> the
>>> previous one.  Hence this patch.
>>> Ok to commit ?  (Will back-port too).
>>
>> Approved - please apply.
>
> Thanks.  Committed on both head and 2_20 branch.

Even more strangely, my freshly regenerated z8k-opc.h matches the
previous revision.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 11:18     ` Alan Modra
@ 2009-09-07 11:37       ` Alan Modra
  2009-09-07 11:47         ` Tristan Gingold
  2009-09-07 12:12         ` Alan Modra
  2009-09-07 11:38       ` Tristan Gingold
  1 sibling, 2 replies; 19+ messages in thread
From: Alan Modra @ 2009-09-07 11:37 UTC (permalink / raw)
  To: Tristan Gingold, Nick Clifton, binutils

On Mon, Sep 07, 2009 at 08:48:45PM +0930, Alan Modra wrote:
> Even more strangely, my freshly regenerated z8k-opc.h matches the
> previous revision.

It's qsort instability.  These two entries have the same name

  {"------", 5, 8, "1100 dddd imm8", "ldb rbd,imm8", 0},
  {"------", 7, 8, "0010 0000 0000 dddd imm8 imm8", "ldb rbd,imm8", 0},

as do these two..

  {"-ZSP--", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
  {"*", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},

I'll commit a patch to fix the instability.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 11:18     ` Alan Modra
  2009-09-07 11:37       ` Alan Modra
@ 2009-09-07 11:38       ` Tristan Gingold
  1 sibling, 0 replies; 19+ messages in thread
From: Tristan Gingold @ 2009-09-07 11:38 UTC (permalink / raw)
  To: Alan Modra; +Cc: Nick Clifton, binutils


On Sep 7, 2009, at 1:18 PM, Alan Modra wrote:

> On Mon, Sep 07, 2009 at 10:29:32AM +0200, Tristan Gingold wrote:
>>
>> On Sep 4, 2009, at 5:33 PM, Nick Clifton wrote:
>>
>>> Hi Tristan,
>>>
>>>> strangely enough the regenerated opcodes/z8k-opc.h is different  
>>>> from
>>>> the
>>>> previous one.  Hence this patch.
>>>> Ok to commit ?  (Will back-port too).
>>>
>>> Approved - please apply.
>>
>> Thanks.  Committed on both head and 2_20 branch.
>
> Even more strangely, my freshly regenerated z8k-opc.h matches the
> previous revision.

Argh.  Maybe the host has an influence on the generation.  Should I  
revert my change ?

Will investigate later in any case.

Tristan.

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 11:37       ` Alan Modra
@ 2009-09-07 11:47         ` Tristan Gingold
  2009-09-07 12:12         ` Alan Modra
  1 sibling, 0 replies; 19+ messages in thread
From: Tristan Gingold @ 2009-09-07 11:47 UTC (permalink / raw)
  To: Alan Modra; +Cc: Nick Clifton, binutils


On Sep 7, 2009, at 1:37 PM, Alan Modra wrote:

> On Mon, Sep 07, 2009 at 08:48:45PM +0930, Alan Modra wrote:
>> Even more strangely, my freshly regenerated z8k-opc.h matches the
>> previous revision.
>
> It's qsort instability.  These two entries have the same name
>
>  {"------", 5, 8, "1100 dddd imm8", "ldb rbd,imm8", 0},
>  {"------", 7, 8, "0010 0000 0000 dddd imm8 imm8", "ldb rbd,imm8", 0},
>
> as do these two..
>
>  {"-ZSP--", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
>  {"*", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
>
> I'll commit a patch to fix the instability.

Well done!  Thanks.

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 11:37       ` Alan Modra
  2009-09-07 11:47         ` Tristan Gingold
@ 2009-09-07 12:12         ` Alan Modra
  2009-09-07 12:17           ` Andreas Schwab
  1 sibling, 1 reply; 19+ messages in thread
From: Alan Modra @ 2009-09-07 12:12 UTC (permalink / raw)
  To: Tristan Gingold, Nick Clifton, binutils

On Mon, Sep 07, 2009 at 09:07:43PM +0930, Alan Modra wrote:
> It's qsort instability.  These two entries have the same name
> 
>   {"------", 5, 8, "1100 dddd imm8", "ldb rbd,imm8", 0},
>   {"------", 7, 8, "0010 0000 0000 dddd imm8 imm8", "ldb rbd,imm8", 0},
> 
> as do these two..
> 
>   {"-ZSP--", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
>   {"*", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
> 
> I'll commit a patch to fix the instability.

	* z8kgen.c (func): Stabilize qsort of identically named entries.
	* z8k-opc.h: Regenerate.

Index: opcodes/z8kgen.c
===================================================================
RCS file: /cvs/src/src/opcodes/z8kgen.c,v
retrieving revision 1.16
diff -u -p -r1.16 z8kgen.c
--- opcodes/z8kgen.c	29 Aug 2009 22:11:02 -0000	1.16
+++ opcodes/z8kgen.c	7 Sep 2009 11:50:11 -0000
@@ -567,9 +567,14 @@ count (void)
 }
 
 static int
-func (struct op *a, struct op *b)
+func (const void *p1, const void *p2)
 {
-  return strcmp ((a)->name, (b)->name);
+  const struct op *a = p1;
+  const struct op *b = p2;
+  int ret = strcmp (a->name, b->name);
+  if (ret != 0)
+    return ret;
+  return p1 > p2;
 }
 
 
@@ -909,7 +914,7 @@ internal (void)
   memcpy (new_op, p, c * sizeof (struct op));
 
   /* Sort all names in table alphabetically.  */
-  qsort (new_op, c, sizeof (struct op), (int (*)(const void *, const void *))func);
+  qsort (new_op, c, sizeof (struct op), func);
 
   p = new_op;
   while (p->flags && p->flags[0] != '*')
@@ -965,7 +970,7 @@ gas (void)
   memcpy (new_op, p, c * sizeof (struct op));
 
   /* Sort all names in table alphabetically.  */
-  qsort (new_op, c, sizeof (struct op), (int (*)(const void *, const void *)) func);
+  qsort (new_op, c, sizeof (struct op), func);
 
   printf ("/* DO NOT EDIT!  -*- buffer-read-only: t -*-\n");
   printf ("   This file is automatically generated by z8kgen.  */\n\n");
Index: opcodes/z8k-opc.h
===================================================================
RCS file: /cvs/src/src/opcodes/z8k-opc.h,v
retrieving revision 1.13
diff -u -p -r1.13 z8k-opc.h
--- opcodes/z8k-opc.h	7 Sep 2009 08:14:09 -0000	1.13
+++ opcodes/z8k-opc.h	7 Sep 2009 11:50:10 -0000
@@ -1820,21 +1820,21 @@ const opcode_entry_type z8k_table[] = {
 "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_X+(ARG_RS),},
 	{CLASS_BIT+6,CLASS_BIT+0,CLASS_REGN0+(ARG_RS),CLASS_REG+(ARG_RD),CLASS_ADDRESS+(ARG_SRC),0,0,0,0,},2,4,74},
 
-/* 0010 0000 0000 dddd imm8 imm8 *** ldb rbd,imm8 */
+/* 1100 dddd imm8 *** ldb rbd,imm8 */
 {
 #ifdef NICENAMES
-"ldb rbd,imm8",8,7,0x00,
+"ldb rbd,imm8",8,5,0x00,
 #endif
 "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_IMM+(ARG_IMM8),},
-	{CLASS_BIT+2,CLASS_BIT+0,CLASS_BIT+0,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),CLASS_IMM+(ARG_IMM8),0,0,0,},2,4,74},
+	{CLASS_BIT+0xc,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),0,0,0,0,0,0,},2,2,74},
 
-/* 1100 dddd imm8 *** ldb rbd,imm8 */
+/* 0010 0000 0000 dddd imm8 imm8 *** ldb rbd,imm8 */
 {
 #ifdef NICENAMES
-"ldb rbd,imm8",8,5,0x00,
+"ldb rbd,imm8",8,7,0x00,
 #endif
 "ldb",OPC_ldb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_IMM+(ARG_IMM8),},
-	{CLASS_BIT+0xc,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),0,0,0,0,0,0,},2,2,74},
+	{CLASS_BIT+2,CLASS_BIT+0,CLASS_BIT+0,CLASS_REG+(ARG_RD),CLASS_IMM+(ARG_IMM8),CLASS_IMM+(ARG_IMM8),0,0,0,},2,4,74},
 
 /* 1010 0000 ssss dddd *** ldb rbd,rbs */
 {
@@ -3791,7 +3791,7 @@ const opcode_entry_type z8k_table[] = {
 /* 1000 1000 ssss dddd *** xorb rbd,rbs */
 {
 #ifdef NICENAMES
-"xorb rbd,rbs",8,4,0x01,
+"xorb rbd,rbs",8,4,0x1c,
 #endif
 "xorb",OPC_xorb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_REG_BYTE+(ARG_RS),},
 	{CLASS_BIT+8,CLASS_BIT+8,CLASS_REG+(ARG_RS),CLASS_REG+(ARG_RD),0,0,0,0,0,},2,2,203},
@@ -3799,7 +3799,7 @@ const opcode_entry_type z8k_table[] = {
 /* 1000 1000 ssss dddd *** xorb rbd,rbs */
 {
 #ifdef NICENAMES
-"xorb rbd,rbs",8,4,0x1c,
+"xorb rbd,rbs",8,4,0x01,
 #endif
 "xorb",OPC_xorb,0,{CLASS_REG_BYTE+(ARG_RD),CLASS_REG_BYTE+(ARG_RS),},
 	{CLASS_BIT+8,CLASS_BIT+8,CLASS_REG+(ARG_RS),CLASS_REG+(ARG_RD),0,0,0,0,0,},2,2,203},

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 12:12         ` Alan Modra
@ 2009-09-07 12:17           ` Andreas Schwab
  2009-09-07 12:29             ` Tristan Gingold
  2009-09-07 13:01             ` Alan Modra
  0 siblings, 2 replies; 19+ messages in thread
From: Andreas Schwab @ 2009-09-07 12:17 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Nick Clifton, binutils

Alan Modra <amodra@bigpond.net.au> writes:

>  static int
> -func (struct op *a, struct op *b)
> +func (const void *p1, const void *p2)
>  {
> -  return strcmp ((a)->name, (b)->name);
> +  const struct op *a = p1;
> +  const struct op *b = p2;
> +  int ret = strcmp (a->name, b->name);
> +  if (ret != 0)
> +    return ret;
> +  return p1 > p2;

Shouldn't that handle p1 < p2 as well?

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 12:17           ` Andreas Schwab
@ 2009-09-07 12:29             ` Tristan Gingold
  2009-09-07 13:08               ` Andreas Schwab
  2009-09-07 13:01             ` Alan Modra
  1 sibling, 1 reply; 19+ messages in thread
From: Tristan Gingold @ 2009-09-07 12:29 UTC (permalink / raw)
  To: Andreas Schwab, Alan Modra; +Cc: Nick Clifton, Binutils


On Sep 7, 2009, at 2:17 PM, Andreas Schwab wrote:

> Alan Modra <amodra@bigpond.net.au> writes:
>
>> static int
>> -func (struct op *a, struct op *b)
>> +func (const void *p1, const void *p2)
>> {
>> -  return strcmp ((a)->name, (b)->name);
>> +  const struct op *a = p1;
>> +  const struct op *b = p2;
>> +  int ret = strcmp (a->name, b->name);
>> +  if (ret != 0)
>> +    return ret;
>> +  return p1 > p2;
>
> Shouldn't that handle p1 < p2 as well?

(You reply to Alan but it is not explicitly listed as a recipient !)

Or:

  return (p1 > p2) * 2 - 1;

Tristan.


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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 12:17           ` Andreas Schwab
  2009-09-07 12:29             ` Tristan Gingold
@ 2009-09-07 13:01             ` Alan Modra
  1 sibling, 0 replies; 19+ messages in thread
From: Alan Modra @ 2009-09-07 13:01 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Tristan Gingold, Nick Clifton, binutils

On Mon, Sep 07, 2009 at 02:17:02PM +0200, Andreas Schwab wrote:
> Alan Modra <amodra@bigpond.net.au> writes:
> 
> >  static int
> > -func (struct op *a, struct op *b)
> > +func (const void *p1, const void *p2)
> >  {
> > -  return strcmp ((a)->name, (b)->name);
> > +  const struct op *a = p1;
> > +  const struct op *b = p2;
> > +  int ret = strcmp (a->name, b->name);
> > +  if (ret != 0)
> > +    return ret;
> > +  return p1 > p2;
> 
> Shouldn't that handle p1 < p2 as well?

Oops.  I ought to know better.

	* z8kgen.c (func): Fix thinko last patch.

Index: opcodes/z8kgen.c
===================================================================
RCS file: /cvs/src/src/opcodes/z8kgen.c,v
retrieving revision 1.17
diff -u -p -r1.17 z8kgen.c
--- opcodes/z8kgen.c	7 Sep 2009 12:11:20 -0000	1.17
+++ opcodes/z8kgen.c	7 Sep 2009 12:59:39 -0000
@@ -574,7 +574,7 @@ func (const void *p1, const void *p2)
   int ret = strcmp (a->name, b->name);
   if (ret != 0)
     return ret;
-  return p1 > p2;
+  return p1 > p2 ? 1 : -1;
 }
 
 
-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 12:29             ` Tristan Gingold
@ 2009-09-07 13:08               ` Andreas Schwab
  2009-09-07 13:20                 ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2009-09-07 13:08 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Alan Modra, Nick Clifton, Binutils

Tristan Gingold <gingold@adacore.com> writes:

> On Sep 7, 2009, at 2:17 PM, Andreas Schwab wrote:
>
>> Alan Modra <amodra@bigpond.net.au> writes:
>>
>>> static int
>>> -func (struct op *a, struct op *b)
>>> +func (const void *p1, const void *p2)
>>> {
>>> -  return strcmp ((a)->name, (b)->name);
>>> +  const struct op *a = p1;
>>> +  const struct op *b = p2;
>>> +  int ret = strcmp (a->name, b->name);
>>> +  if (ret != 0)
>>> +    return ret;
>>> +  return p1 > p2;
>>
>> Shouldn't that handle p1 < p2 as well?
>
> (You reply to Alan but it is not explicitly listed as a recipient !)

That's what Alan asked me to do (see the Mail-Followup-To header).

> Or:
>
>  return (p1 > p2) * 2 - 1;

Not sure whether you can count on p1 != p2.  A common idiom is
(p1 > p2) - (p1 < p2).

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 13:08               ` Andreas Schwab
@ 2009-09-07 13:20                 ` Alan Modra
  2009-09-07 14:40                   ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2009-09-07 13:20 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Tristan Gingold, Nick Clifton, Binutils

On Mon, Sep 07, 2009 at 03:05:58PM +0200, Andreas Schwab wrote:
> Not sure whether you can count on p1 != p2.

Does it matter?  Seems to me if qsort calls the comparison function
with p1 == p2, then it doesn't matter whether qsort "swaps" those
entries or not.  It would be a rather poor qsort implementation that
did this and then didn't terminate..

>  A common idiom is (p1 > p2) - (p1 < p2).

Feel free to fix it if you think this is necessary, or even just
desirable as the Right Thing To Do.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 13:20                 ` Alan Modra
@ 2009-09-07 14:40                   ` Andreas Schwab
  2009-09-07 21:58                     ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2009-09-07 14:40 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Nick Clifton, Binutils

I don't think you can actually use the address as the fallback, since it
can cause two elements to be compared differently depending on the their
relative position in the array, resulting in an inconsistent sort order.

Andreas.

2009-09-07  Andreas Schwab  <schwab@redhat.com>

	* z8kgen.c (func): Use bits field as fallback.
	* z8k-opc.h: Regenerate.

--- z8kgen.c.~1.18.~	2009-09-07 16:06:24.000000000 +0200
+++ z8kgen.c	2009-09-07 16:35:44.000000000 +0200
@@ -574,7 +574,9 @@ func (const void *p1, const void *p2)
   int ret = strcmp (a->name, b->name);
   if (ret != 0)
     return ret;
-  return p1 > p2 ? 1 : -1;
+  /* Use bits as the secondary key which is guaranteed to be
+     unique.  */
+  return strcmp (a->bits, b->bits);
 }
 
 

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 14:40                   ` Andreas Schwab
@ 2009-09-07 21:58                     ` Alan Modra
  2009-09-07 22:32                       ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2009-09-07 21:58 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Tristan Gingold, Nick Clifton, Binutils

On Mon, Sep 07, 2009 at 04:37:45PM +0200, Andreas Schwab wrote:
> I don't think you can actually use the address as the fallback, since it
> can cause two elements to be compared differently depending on the their
> relative position in the array, resulting in an inconsistent sort order.

The idea of using the address is to leave elements with the same key
in the order they occur in the original array.  That works with qsort
that sorts in place, ie. doesn't copy parts of the input array to
temporary storage.  A qsort that copies is quite a dismal
implementation, so I think we should be safe enough.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 21:58                     ` Alan Modra
@ 2009-09-07 22:32                       ` Andreas Schwab
  2009-09-07 23:43                         ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2009-09-07 22:32 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Nick Clifton, Binutils

Alan Modra <amodra@bigpond.net.au> writes:

> The idea of using the address is to leave elements with the same key
> in the order they occur in the original array.  That works with qsort
> that sorts in place, ie. doesn't copy parts of the input array to
> temporary storage.

The standard forbids that anyway.  But it does not forbid shuffling in a
way that the relative order of two elements changes even if that would
make them order backwards temporarily.  If you want a stable sort you
need to decide on the contents alone, not on the address.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 22:32                       ` Andreas Schwab
@ 2009-09-07 23:43                         ` Alan Modra
  2009-09-08  9:01                           ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2009-09-07 23:43 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Tristan Gingold, Nick Clifton, Binutils

On Tue, Sep 08, 2009 at 12:31:57AM +0200, Andreas Schwab wrote:
> Alan Modra <amodra@bigpond.net.au> writes:
> 
> > The idea of using the address is to leave elements with the same key
> > in the order they occur in the original array.  That works with qsort
> > that sorts in place, ie. doesn't copy parts of the input array to
> > temporary storage.
> 
> The standard forbids that anyway.  But it does not forbid shuffling in a
> way that the relative order of two elements changes even if that would
> make them order backwards temporarily.  If you want a stable sort you
> need to decide on the contents alone, not on the address.

 Well, I'm learning something I didn't know before.  I'm going to
 leave any further patches to this inconsequential bit of code to
 someone else..  Incidentally, your patch doesn't work either, since
 "bits" doesn't differ for the two "xorb rbd,rbs" patterns.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-07 23:43                         ` Alan Modra
@ 2009-09-08  9:01                           ` Andreas Schwab
  2009-09-08  9:35                             ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2009-09-08  9:01 UTC (permalink / raw)
  To: Binutils

Alan Modra <amodra@bigpond.net.au> writes:

>  Incidentally, your patch doesn't work either, since "bits" doesn't
>  differ for the two "xorb rbd,rbs" patterns.

You are right, but looking closer there are a lot more problems.
AFAICS, the extra xorb entry actually serves no purpose, in the gas
table it is indistinguishable from the other one, and it is only
included because of the wrong loop end condition.  And the -t mode
crashes because it requires writable strings.

(Alternatively we could rip out all but the -a mode.)

Andreas.

2009-09-08  Andreas Schwab  <schwab@linux-m68k.org>

	* z8kgen.c (struct op): Replace unused flavor with id.
	(opt): Remove extra xorb entry.
	(func): Use id field as fallback.
	(sub): Return new string, caller changed.
	(internal): Allocate end marker.  Assign unique id before sorting.
	(gas): Likewise.  Fix loop end condition.
	* z8k-opc.h: Regenerate.

--- opcodes/z8kgen.c.~1.18.~	2009-09-07 16:06:24.000000000 +0200
+++ opcodes/z8kgen.c	2009-09-08 10:43:52.000000000 +0200
@@ -17,7 +17,7 @@
    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-/* This program generates z8k-opc.h.  Compile with -fwritable-strings.  */
+/* This program generates z8k-opc.h.  */
 
 #include <stdio.h>
 #include "sysdep.h"
@@ -32,7 +32,8 @@ struct op
   char type;
   char *bits;
   char *name;
-  char *flavor;
+  /* Unique number for stable sorting.  */
+  int id;
 };
 
 #define iswhite(x) ((x) == ' ' || (x) == '\t')
@@ -547,7 +548,6 @@ static struct op opt[] =
   {"------", 7, 32, "1000 1100 dddd 0001", "ldctlb rbd,ctrl", 0},
   {"CZSVDH", 7, 32, "1000 1100 ssss 1001", "ldctlb ctrl,rbs", 0},
 
-  {"*", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
   {"*", 0, 0, 0, 0, 0}
 };
 
@@ -574,7 +574,7 @@ func (const void *p1, const void *p2)
   int ret = strcmp (a->name, b->name);
   if (ret != 0)
     return ret;
-  return p1 > p2 ? 1 : -1;
+  return a->id > b->id ? 1 : -1;
 }
 
 
@@ -826,9 +826,12 @@ chewname (char **name)
   return nargs;
 }
 
-static void
+static char *
 sub (char *x, char c)
 {
+  /* Create copy.  */
+  char *ret = xstrdup (x);
+  x = ret;
   while (*x)
     {
       if (x[0] == c && x[1] == c &&
@@ -839,6 +842,7 @@ sub (char *x, char c)
 	}
       x++;
     }
+  return ret;
 }
 
 
@@ -909,9 +913,14 @@ static void
 internal (void)
 {
   int c = count ();
-  struct op *new_op = xmalloc (sizeof (struct op) * c);
+  int id;
+  struct op *new_op = xmalloc (sizeof (struct op) * (c + 1));
   struct op *p = opt;
-  memcpy (new_op, p, c * sizeof (struct op));
+  memcpy (new_op, p, (c + 1) * sizeof (struct op));
+
+  /* Assign unique id.  */
+  for (id = 0; id < c; id++)
+    new_op[id].id = id;
 
   /* Sort all names in table alphabetically.  */
   qsort (new_op, c, sizeof (struct op), func);
@@ -937,15 +946,15 @@ internal (void)
 	  /* Skip the r and sub the string.  */
 	  s++;
 	  c = s[1];
-	  sub (p->bits, c);
+	  p->bits = sub (p->bits, c);
 	}
 	if (s[0] == '(' && s[3] == ')')
 	{
-	  sub (p->bits, s[2]);
+	  p->bits = sub (p->bits, s[2]);
 	}
 	if (s[0] == '(')
 	{
-	  sub (p->bits, s[-1]);
+	  p->bits = sub (p->bits, s[-1]);
 	}
 
 	s++;
@@ -962,12 +971,17 @@ static void
 gas (void)
 {
   int c = count ();
+  int id;
   struct op *p = opt;
   int idx = -1;
   char *oldname = "";
-  struct op *new_op = xmalloc (sizeof (struct op) * c);
+  struct op *new_op = xmalloc (sizeof (struct op) * (c + 1));
+
+  memcpy (new_op, p, (c + 1) * sizeof (struct op));
 
-  memcpy (new_op, p, c * sizeof (struct op));
+  /* Assign unique id.  */
+  for (id = 0; id < c; id++)
+    new_op[id].id = id;
 
   /* Sort all names in table alphabetically.  */
   qsort (new_op, c, sizeof (struct op), func);
@@ -1284,7 +1298,7 @@ gas (void)
   printf ("#ifdef DEFINE_TABLE\n");
   printf ("const opcode_entry_type z8k_table[] = {\n");
 
-  while (new_op->flags && new_op->flags[0])
+  while (new_op->flags && new_op->flags[0] != '*')
     {
       int nargs;
       int length;

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [Patch] opcodes/z8k-opc.h regenerated
  2009-09-08  9:01                           ` Andreas Schwab
@ 2009-09-08  9:35                             ` Alan Modra
  0 siblings, 0 replies; 19+ messages in thread
From: Alan Modra @ 2009-09-08  9:35 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Binutils

On Tue, Sep 08, 2009 at 11:01:34AM +0200, Andreas Schwab wrote:
> 	* z8kgen.c (struct op): Replace unused flavor with id.
> 	(opt): Remove extra xorb entry.
> 	(func): Use id field as fallback.
> 	(sub): Return new string, caller changed.
> 	(internal): Allocate end marker.  Assign unique id before sorting.
> 	(gas): Likewise.  Fix loop end condition.
> 	* z8k-opc.h: Regenerate.

OK, thanks!

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2009-09-08  9:35 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04 13:00 [Patch] opcodes/z8k-opc.h regenerated Tristan Gingold
2009-09-04 15:33 ` Nick Clifton
2009-09-07  8:30   ` Tristan Gingold
2009-09-07 11:18     ` Alan Modra
2009-09-07 11:37       ` Alan Modra
2009-09-07 11:47         ` Tristan Gingold
2009-09-07 12:12         ` Alan Modra
2009-09-07 12:17           ` Andreas Schwab
2009-09-07 12:29             ` Tristan Gingold
2009-09-07 13:08               ` Andreas Schwab
2009-09-07 13:20                 ` Alan Modra
2009-09-07 14:40                   ` Andreas Schwab
2009-09-07 21:58                     ` Alan Modra
2009-09-07 22:32                       ` Andreas Schwab
2009-09-07 23:43                         ` Alan Modra
2009-09-08  9:01                           ` Andreas Schwab
2009-09-08  9:35                             ` Alan Modra
2009-09-07 13:01             ` Alan Modra
2009-09-07 11:38       ` Tristan Gingold

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).