Correct powerpc spe opcode lookup

Message ID 20180508130118.GZ28782@bubble.grove.modra.org
State New
Headers show
Series
  • Correct powerpc spe opcode lookup
Related show

Commit Message

Alan Modra May 8, 2018, 1:01 p.m.
Defining SPE2_OPCD_SEGS as 13 discounts the possibility that we'd
ever look up spe2_opcd_indices[14..16], which I think is possible.
Extend that array to size 16+1, using the macros we use to index the
array.  Similarly use the index macros for PPC_OPCD_SEGS and
VLE_OPCD_SEGS.

	* ppc-dis.c (PPC_OPCD_SEGS): Define using PPC_OP.
	(VLE_OPCD_SEGS, SPE2_OPCD_SEGS): Similarly, using macros used to
	partition opcode space for index lookup.


-- 
Alan Modra
Australia Development Lab, IBM

Comments

Peter Bergner May 8, 2018, 7:48 p.m. | #1
On 5/8/18 8:01 AM, Alan Modra wrote:
> 	* ppc-dis.c (PPC_OPCD_SEGS): Define using PPC_OP.

> 	(VLE_OPCD_SEGS, SPE2_OPCD_SEGS): Similarly, using macros used to

> 	partition opcode space for index lookup.


I like it, thanks.


A somewhat related question: We have two methods of implementing extended
mnemonics.  One is adding them to the appropriate *_opcodes[] table (eg, "mr",
"vmr", etc.) and the other is placing them in the powerpc_macros[] table
(eg, slwi, clrrdi, etc.).

Both methods seem to have their benefits.  However, my big issue with the
powerpc_macros[] table is that any extended mnemonic implemented using it
cannot be disassembled to the extended mnemonic, meaning you always get the
base instruction instead.  For example, "slwi r3,r4,3" is always disassembled
as "rlwinm r3,r4,3,0,28" even though slwi is much more readable.  We also get
bad error messages in the case the base instruction isn't supported:

bergner@pike:~/binutils/BUGS$ cat slwi.s 
	.text
	slwi	3,4,3
bergner@pike:~/binutils/BUGS$ as -a32 -mvle slwi.s 
slwi.s: Assembler messages:
slwi.s:2: Error: unrecognized opcode: `rlwinm'

This is due to powerpc_macros[] doesn't have the deprecated field like the
*_opcodes[] tables do, so some unsupported extended mnemonics still get
added to the hash table, so we translate it to the unsupported base insn
and then we die.

Should we just remove powerpc_macros[] and move its entries into the
appropriate *_opcodes[] tables?  Or do you have another option that
allows us to disassemble those extended mnemonics in powerpc_macros[]?

Peter
Alan Modra May 9, 2018, 3:03 a.m. | #2
On Tue, May 08, 2018 at 02:48:50PM -0500, Peter Bergner wrote:
> Should we just remove powerpc_macros[] and move its entries into the

> appropriate *_opcodes[] tables?


If you want to, that's fine with me.  You'll need to write some fancy
insert and extract functions.

-- 
Alan Modra
Australia Development Lab, IBM
Peter Bergner May 9, 2018, 3:40 a.m. | #3
On 5/8/18 10:03 PM, Alan Modra wrote:
> On Tue, May 08, 2018 at 02:48:50PM -0500, Peter Bergner wrote:

>> Should we just remove powerpc_macros[] and move its entries into the

>> appropriate *_opcodes[] tables?

> 

> If you want to, that's fine with me.  You'll need to write some fancy

> insert and extract functions.


I think since there are a fair amount, it'll probably be easiest to convert
a few at a time until they're all gone.  Then I can delete the table itself.
Thanks.

Peter

Patch

diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c
index 0f7d7bacfb..412aae000d 100644
--- a/opcodes/ppc-dis.c
+++ b/opcodes/ppc-dis.c
@@ -367,12 +367,12 @@  powerpc_init_dialect (struct disassemble_info *info)
   POWERPC_DIALECT(info) = dialect;
 }
 
-#define PPC_OPCD_SEGS 64
-static unsigned short powerpc_opcd_indices[PPC_OPCD_SEGS+1];
-#define VLE_OPCD_SEGS 32
-static unsigned short vle_opcd_indices[VLE_OPCD_SEGS+1];
-#define SPE2_OPCD_SEGS 13
-static unsigned short spe2_opcd_indices[SPE2_OPCD_SEGS+1];
+#define PPC_OPCD_SEGS (1 + PPC_OP (-1))
+static unsigned short powerpc_opcd_indices[PPC_OPCD_SEGS + 1];
+#define VLE_OPCD_SEGS (1 + VLE_OP_TO_SEG (VLE_OP (-1, 0xffff)))
+static unsigned short vle_opcd_indices[VLE_OPCD_SEGS + 1];
+#define SPE2_OPCD_SEGS (1 + SPE2_XOP_TO_SEG (SPE2_XOP (-1)))
+static unsigned short spe2_opcd_indices[SPE2_OPCD_SEGS + 1];
 
 /* Calculate opcode table indices to speed up disassembly,
    and init dialect.  */