Skip to content

Commit

Permalink
internal/opcodesextra: curated extra instructions (#345)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mmcloughlin committed Nov 28, 2022
1 parent fa3cfb0 commit a0ea0f3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
3 changes: 2 additions & 1 deletion internal/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
36 changes: 0 additions & 36 deletions internal/load/tables.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package load

import "github.com/mmcloughlin/avo/internal/inst"

// alias defines an opcode alias.
type alias struct {
From string
Expand Down Expand Up @@ -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},
},
},
},
},
}
18 changes: 18 additions & 0 deletions internal/opcodesextra/instructions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Package opcodesextra provides curated extensions to the instruction database.
package opcodesextra

import "github.com/mmcloughlin/avo/internal/inst"

// sets of extra instructions.
var sets = [][]*inst.Instruction{
movlqzx,
}

// Instructions returns a list of extras to add to the instructions database.
func Instructions() []*inst.Instruction {
var is []*inst.Instruction
for _, set := range sets {
is = append(is, set...)
}
return is
}
35 changes: 35 additions & 0 deletions internal/opcodesextra/movlqzx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package opcodesextra

import "github.com/mmcloughlin/avo/internal/inst"

// 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}},
// }
var movlqzx = []*inst.Instruction{
{
Opcode: "MOVLQZX",
Summary: "Move with Zero-Extend",
Forms: []inst.Form{
{
Operands: []inst.Operand{
{Type: "m32", Action: inst.R},
{Type: "r64", Action: inst.W},
},
},
},
},
}

0 comments on commit a0ea0f3

Please sign in to comment.