internal/load: use alias slice for determinism

Previously aliases were stored in a map which was causing
non-deterministic code generation (see recent build failures). This diff
changes to a slice to avoid this problem.

Updates #50
This commit is contained in:
Michael McLoughlin
2019-01-20 23:06:42 -08:00
parent 2d7a9ddb6c
commit 02ecaad4e4
4 changed files with 61 additions and 53 deletions

View File

@@ -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}

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"},
}