From a0ea0f3e6f986aaa2437847d41c3b3304a5a0bf7 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 27 Nov 2022 18:32:31 -0800 Subject: [PATCH] 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 --- internal/load/load.go | 3 ++- internal/load/tables.go | 36 --------------------------- internal/opcodesextra/instructions.go | 18 ++++++++++++++ internal/opcodesextra/movlqzx.go | 35 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 internal/opcodesextra/instructions.go create mode 100644 internal/opcodesextra/movlqzx.go diff --git a/internal/load/load.go b/internal/load/load.go index ae684d6..3c3aa31 100644 --- a/internal/load/load.go +++ b/internal/load/load.go @@ -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 } diff --git a/internal/load/tables.go b/internal/load/tables.go index 67ac40b..5697879 100644 --- a/internal/load/tables.go +++ b/internal/load/tables.go @@ -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}, - }, - }, - }, - }, -} diff --git a/internal/opcodesextra/instructions.go b/internal/opcodesextra/instructions.go new file mode 100644 index 0000000..b25537a --- /dev/null +++ b/internal/opcodesextra/instructions.go @@ -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 +} diff --git a/internal/opcodesextra/movlqzx.go b/internal/opcodesextra/movlqzx.go new file mode 100644 index 0000000..a1ed531 --- /dev/null +++ b/internal/opcodesextra/movlqzx.go @@ -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}, + }, + }, + }, + }, +}