internal/opcodesextra: curated extra instructions (#345)

Supporting extra instructions not included in the Opcodes database is
currently a challenge. Short of migrating to an entirely different source
(such as #23), the options are either to patch the XML data file or to append
additional instructions at the loading phase.

An example of patching the XML was shown in the as-yet unlanded PR #234. This
shows the XML patching approach is unwieldy and requires more information than
we actually need (for example instruction form encodings).

In #335 we discussed the alternative of adding extra instructions during
loading. This has the advantage of using avo's simpler internal data
structure.

This PR prepares for using that approach by adding an `internal/opcodesextra`
package, intended to contain manually curated lists of extra instructions to
add to the instruction database during loading. At the moment, the only
instruction added here is the `MOVLQZX` instruction that's already handled
this way.

Updates #335 #234 #23
This commit is contained in:
Michael McLoughlin
2022-11-27 18:32:31 -08:00
committed by GitHub
parent fa3cfb0153
commit a0ea0f3e6f
4 changed files with 55 additions and 37 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/mmcloughlin/avo/internal/inst"
"github.com/mmcloughlin/avo/internal/opcodescsv"
"github.com/mmcloughlin/avo/internal/opcodesextra"
"github.com/mmcloughlin/avo/internal/opcodesxml"
)
@@ -86,7 +87,7 @@ func (l *Loader) Load() ([]inst.Instruction, error) {
}
// Add extras to our list.
for _, e := range extras {
for _, e := range opcodesextra.Instructions() {
im[e.Opcode] = e
}

View File

@@ -1,7 +1,5 @@
package load
import "github.com/mmcloughlin/avo/internal/inst"
// alias defines an opcode alias.
type alias struct {
From string
@@ -142,37 +140,3 @@ var maskrequired = map[string]bool{
"VSCATTERQPD": true,
"VSCATTERQPS": true,
}
// extras is simply a list of extra instructions to add to the database.
var extras = []*inst.Instruction{
// MOVLQZX does not appear in either x86 CSV or Opcodes, but does appear in stdlib assembly.
//
// Reference: https://github.com/golang/go/blob/048c9164a0c5572df18325e377473e7893dbfb07/src/runtime/asm_amd64.s#L451-L453
//
// TEXT ·reflectcall(SB), NOSPLIT, $0-32
// MOVLQZX argsize+24(FP), CX
// DISPATCH(runtime·call32, 32)
//
// Reference: https://github.com/golang/go/blob/048c9164a0c5572df18325e377473e7893dbfb07/src/cmd/internal/obj/x86/asm6.go#L1217
//
// {AMOVLQZX, yml_rl, Px, opBytes{0x8b}},
//
// Reference: https://github.com/golang/go/blob/048c9164a0c5572df18325e377473e7893dbfb07/src/cmd/internal/obj/x86/asm6.go#L515-L517
//
// var yml_rl = []ytab{
// {Zm_r, 1, argList{Yml, Yrl}},
// }
//
{
Opcode: "MOVLQZX",
Summary: "Move with Zero-Extend",
Forms: []inst.Form{
{
Operands: []inst.Operand{
{Type: "m32", Action: inst.R},
{Type: "r64", Action: inst.W},
},
},
},
},
}