Skip to content

Commit

Permalink
fix reproducibility bug and regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Nov 28, 2022
1 parent 5e03aaa commit 56c8783
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 404 deletions.
20 changes: 17 additions & 3 deletions build/zinstructions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions internal/inst/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func (i Instruction) IsConditionalBranch() bool {
return i.IsBranch() && i.Opcode != "JMP"
}

// Clone the instruction.
func (i Instruction) Clone() Instruction {
c := i
c.Forms = i.Forms.Clone()
return c
}

// Forms is a collection of instruction forms.
type Forms []Form

Expand Down Expand Up @@ -78,6 +85,15 @@ func (fs Forms) IsNiladic() bool {
return len(a) == 1 && a[0] == 0
}

// Clone the instruction forms.
func (fs Forms) Clone() Forms {
cs := make(Forms, 0, len(fs))
for _, f := range fs {
cs = append(cs, f.Clone())
}
return cs
}

// Form specifies one accepted set of operands for an instruction.
type Form struct {
// Instruction sets this instruction form requires.
Expand Down
69 changes: 69 additions & 0 deletions internal/inst/ztable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions internal/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,14 @@ func (l *Loader) Load() ([]inst.Instruction, error) {
// Convert to a slice. Sort instructions and forms for reproducibility.
is := make([]inst.Instruction, 0, len(im))
for _, i := range im {
sortforms(i.Forms)
is = append(is, *i)
}

sort.Slice(is, func(i, j int) bool {
return is[i].Opcode < is[j].Opcode
})

for _, i := range im {
sortforms(i.Forms)
}

return is, nil
}

Expand Down Expand Up @@ -834,7 +831,6 @@ func vexevex(fs []inst.Form) ([]inst.Form, error) {
}

if group[0].EncodingType != inst.EncodingTypeVEX || group[1].EncodingType != inst.EncodingTypeEVEX {
fmt.Println(group)
return nil, errors.New("expected pair of VEX/EVEX encoded forms")
}

Expand Down
9 changes: 8 additions & 1 deletion internal/opcodesextra/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ var sets = [][]*inst.Instruction{

// Instructions returns a list of extras to add to the instructions database.
func Instructions() []*inst.Instruction {
// Concatenate and clone the instruction lists. It can be convenient for
// forms lists and other data structures to be shared in the curated lists,
// but we want to return distinct copies here to avoid subtle bugs in
// consumers.
var is []*inst.Instruction
for _, set := range sets {
is = append(is, set...)
for _, i := range set {
c := i.Clone()
is = append(is, &c)
}
}
return is
}
10 changes: 8 additions & 2 deletions x86/zctors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions x86/zctors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 56c8783

Please sign in to comment.