diff --git a/internal/load/annoyingaliases.sh b/internal/load/annoyingaliases.sh index 370d126..ab50cef 100755 --- a/internal/load/annoyingaliases.sh +++ b/internal/load/annoyingaliases.sh @@ -12,7 +12,7 @@ arch=${GOROOT}/src/cmd/asm/internal/arch/arch.go echo echo 'package load' echo - echo 'var annoyingaliases = map[string]string{' + echo 'var annoyingaliases = []alias{' awk ' /archX86/ { x86=1 } @@ -27,7 +27,7 @@ arch=${GOROOT}/src/cmd/asm/internal/arch/arch.go sub(/x86\.A/, "", to) if(from != to) { - printf("\t\"%s\": \"%s\",\n", from, to) + printf("\t{\"%s\", \"%s\"},\n", from, to) } } ' ${arch} diff --git a/internal/load/load.go b/internal/load/load.go index 500499f..5c29dfe 100644 --- a/internal/load/load.go +++ b/internal/load/load.go @@ -74,15 +74,19 @@ func (l *Loader) Load() ([]inst.Instruction, error) { im[e.Opcode] = e } - // Apply list of aliases. - for from, to := range aliases { - if existing, found := im[from]; found { - im[to].Forms = append(im[to].Forms, existing.Forms...) + // Merge aliased forms. This is primarily for MOVQ (issue #50). + for _, a := range aliases { + if existing, found := im[a.From]; found { + im[a.To].Forms = append(im[a.To].Forms, existing.Forms...) } - cpy := *im[to] - cpy.Opcode = from - cpy.AliasOf = to - im[from] = &cpy + } + + // Apply list of aliases. + for _, a := range aliases { + cpy := *im[a.To] + cpy.Opcode = a.From + cpy.AliasOf = a.To + im[a.From] = &cpy } // Dedupe forms. diff --git a/internal/load/tables.go b/internal/load/tables.go index 6459045..185db28 100644 --- a/internal/load/tables.go +++ b/internal/load/tables.go @@ -4,9 +4,15 @@ import ( "github.com/mmcloughlin/avo/internal/inst" ) +// alias defines an opcode alias. +type alias struct { + From string + To string +} + // aliases defines a list of opcode aliases. Where possible these are extracted // from the code (see note below). -var aliases = map[string]string{ +var aliases = []alias{ // The PSHUFD/PSHUFL alias is not recorded in the list of "Annoying aliases" below. However the instructions are identical. // // Reference: https://github.com/golang/go/blob/048c9164a0c5572df18325e377473e7893dbfb07/src/cmd/internal/obj/x86/asm6.go#L1365 @@ -17,7 +23,7 @@ var aliases = map[string]string{ // // {APSHUFD, yxshuf, Pq, opBytes{0x70, 0}}, // - "PSHUFD": "PSHUFL", + {"PSHUFD", "PSHUFL"}, } // Go contains a list of self-proclaimed "Annoying aliases", as follows. We use @@ -88,9 +94,7 @@ var aliases = map[string]string{ //go:generate ./annoyingaliases.sh zannoyingaliases.go func init() { - for from, to := range annoyingaliases { - aliases[from] = to - } + aliases = append(aliases, annoyingaliases...) } // extras is simply a list of extra instructions to add to the database. diff --git a/internal/load/zannoyingaliases.go b/internal/load/zannoyingaliases.go index 65ad69f..ce7097f 100644 --- a/internal/load/zannoyingaliases.go +++ b/internal/load/zannoyingaliases.go @@ -2,42 +2,42 @@ package load -var annoyingaliases = map[string]string{ - "JA": "JHI", - "JAE": "JCC", - "JB": "JCS", - "JBE": "JLS", - "JC": "JCS", - "JE": "JEQ", - "JG": "JGT", - "JHS": "JCC", - "JL": "JLT", - "JLO": "JCS", - "JNA": "JLS", - "JNAE": "JCS", - "JNB": "JCC", - "JNBE": "JHI", - "JNC": "JCC", - "JNG": "JLE", - "JNGE": "JLT", - "JNL": "JGE", - "JNLE": "JGT", - "JNO": "JOC", - "JNP": "JPC", - "JNS": "JPL", - "JNZ": "JNE", - "JO": "JOS", - "JP": "JPS", - "JPE": "JPS", - "JPO": "JPC", - "JS": "JMI", - "JZ": "JEQ", - "MASKMOVDQU": "MASKMOVOU", - "MOVD": "MOVQ", - "MOVDQ2Q": "MOVQ", - "MOVNTDQ": "MOVNTO", - "MOVOA": "MOVO", - "PSLLDQ": "PSLLO", - "PSRLDQ": "PSRLO", - "PADDD": "PADDL", +var annoyingaliases = []alias{ + {"JA", "JHI"}, + {"JAE", "JCC"}, + {"JB", "JCS"}, + {"JBE", "JLS"}, + {"JC", "JCS"}, + {"JE", "JEQ"}, + {"JG", "JGT"}, + {"JHS", "JCC"}, + {"JL", "JLT"}, + {"JLO", "JCS"}, + {"JNA", "JLS"}, + {"JNAE", "JCS"}, + {"JNB", "JCC"}, + {"JNBE", "JHI"}, + {"JNC", "JCC"}, + {"JNG", "JLE"}, + {"JNGE", "JLT"}, + {"JNL", "JGE"}, + {"JNLE", "JGT"}, + {"JNO", "JOC"}, + {"JNP", "JPC"}, + {"JNS", "JPL"}, + {"JNZ", "JNE"}, + {"JO", "JOS"}, + {"JP", "JPS"}, + {"JPE", "JPS"}, + {"JPO", "JPC"}, + {"JS", "JMI"}, + {"JZ", "JEQ"}, + {"MASKMOVDQU", "MASKMOVOU"}, + {"MOVD", "MOVQ"}, + {"MOVDQ2Q", "MOVQ"}, + {"MOVNTDQ", "MOVNTO"}, + {"MOVOA", "MOVO"}, + {"PSLLDQ", "PSLLO"}, + {"PSRLDQ", "PSRLO"}, + {"PADDD", "PADDL"}, }