Skip to content

Commit

Permalink
internal/inst: suffix classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Jan 20, 2021
1 parent d270957 commit d60cc02
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/inst/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ func UniqueSuffixes(is []Instruction) []Suffix {
return suffixes
}

// SuffixesClasses returns all possible classes of suffix combinations.
func SuffixesClasses(is []Instruction) map[string][]Suffixes {
classes := map[string][]Suffixes{}
for _, i := range is {
for _, f := range i.Forms {
if !f.AcceptsSuffixes() {
continue
}
class := f.SuffixesClass()
if _, ok := classes[class]; ok {
continue
}
classes[class] = f.SupportedSuffixes()
}
}
return classes
}

// ISAs returns all the unique ISAs seen in the given instructions.
func ISAs(is []Instruction) []string {
set := map[string]bool{}
Expand Down
25 changes: 25 additions & 0 deletions internal/inst/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@ func TestAcceptsSuffixes(t *testing.T) {
}
}

func TestSuffixesClasses(t *testing.T) {
// Verify that all instructions in a suffix class support the same suffixes.
reps := map[string][]inst.Suffixes{}
for _, i := range inst.Instructions {
for _, f := range i.Forms {
if !f.AcceptsSuffixes() {
continue
}

class := f.SuffixesClass()
expect, ok := reps[class]
if !ok {
t.Logf("new class %q: representative from instruction %s", class, i.Opcode)
reps[class] = f.SupportedSuffixes()
continue
}

got := f.SupportedSuffixes()
if !reflect.DeepEqual(expect, got) {
t.Fatalf("suffixes mismatch for class %q", class)
}
}
}
}

func TestSuffixesHaveSummaries(t *testing.T) {
set := map[inst.Suffix]bool{}
for _, i := range inst.Instructions {
Expand Down
21 changes: 21 additions & 0 deletions internal/inst/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ func (f Form) AcceptsSuffixes() bool {
return f.Broadcast || f.EmbeddedRounding || f.SuppressAllExceptions || f.Zeroing
}

// SuffixesClass returns a key representing the class of instruction suffixes it
// accepts. All instructions sharing a suffix class accept the same suffixes.
// Returns the empty string if the form takes no suffixes.
func (f Form) SuffixesClass() string {
var parts []string
for _, flag := range []struct {
Name string
Enabled bool
}{
{"er", f.EmbeddedRounding},
{"sae", f.SuppressAllExceptions},
{"bcst", f.Broadcast},
{"z", f.Zeroing},
} {
if flag.Enabled {
parts = append(parts, flag.Name)
}
}
return strings.Join(parts, "_")
}

// SupportedSuffixes returns the list of all possible suffix combinations
// supported by this instruction form.
func (f Form) SupportedSuffixes() []Suffixes {
Expand Down

0 comments on commit d60cc02

Please sign in to comment.