Skip to content

Commit 02ecaad

Browse files
committed
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 mmcloughlin#50
1 parent 2d7a9dd commit 02ecaad

File tree

4 files changed

+61
-53
lines changed

4 files changed

+61
-53
lines changed

internal/load/annoyingaliases.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ arch=${GOROOT}/src/cmd/asm/internal/arch/arch.go
1212
echo
1313
echo 'package load'
1414
echo
15-
echo 'var annoyingaliases = map[string]string{'
15+
echo 'var annoyingaliases = []alias{'
1616

1717
awk '
1818
/archX86/ { x86=1 }
@@ -27,7 +27,7 @@ arch=${GOROOT}/src/cmd/asm/internal/arch/arch.go
2727
sub(/x86\.A/, "", to)
2828
2929
if(from != to) {
30-
printf("\t\"%s\": \"%s\",\n", from, to)
30+
printf("\t{\"%s\", \"%s\"},\n", from, to)
3131
}
3232
}
3333
' ${arch}

internal/load/load.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,19 @@ func (l *Loader) Load() ([]inst.Instruction, error) {
7474
im[e.Opcode] = e
7575
}
7676

77-
// Apply list of aliases.
78-
for from, to := range aliases {
79-
if existing, found := im[from]; found {
80-
im[to].Forms = append(im[to].Forms, existing.Forms...)
77+
// Merge aliased forms. This is primarily for MOVQ (issue #50).
78+
for _, a := range aliases {
79+
if existing, found := im[a.From]; found {
80+
im[a.To].Forms = append(im[a.To].Forms, existing.Forms...)
8181
}
82-
cpy := *im[to]
83-
cpy.Opcode = from
84-
cpy.AliasOf = to
85-
im[from] = &cpy
82+
}
83+
84+
// Apply list of aliases.
85+
for _, a := range aliases {
86+
cpy := *im[a.To]
87+
cpy.Opcode = a.From
88+
cpy.AliasOf = a.To
89+
im[a.From] = &cpy
8690
}
8791

8892
// Dedupe forms.

internal/load/tables.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import (
44
"github.com/mmcloughlin/avo/internal/inst"
55
)
66

7+
// alias defines an opcode alias.
8+
type alias struct {
9+
From string
10+
To string
11+
}
12+
713
// aliases defines a list of opcode aliases. Where possible these are extracted
814
// from the code (see note below).
9-
var aliases = map[string]string{
15+
var aliases = []alias{
1016
// The PSHUFD/PSHUFL alias is not recorded in the list of "Annoying aliases" below. However the instructions are identical.
1117
//
1218
// 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{
1723
//
1824
// {APSHUFD, yxshuf, Pq, opBytes{0x70, 0}},
1925
//
20-
"PSHUFD": "PSHUFL",
26+
{"PSHUFD", "PSHUFL"},
2127
}
2228

2329
// Go contains a list of self-proclaimed "Annoying aliases", as follows. We use
@@ -88,9 +94,7 @@ var aliases = map[string]string{
8894
//go:generate ./annoyingaliases.sh zannoyingaliases.go
8995

9096
func init() {
91-
for from, to := range annoyingaliases {
92-
aliases[from] = to
93-
}
97+
aliases = append(aliases, annoyingaliases...)
9498
}
9599

96100
// extras is simply a list of extra instructions to add to the database.

internal/load/zannoyingaliases.go

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)