avogen: make mov generator deterministic
This commit is contained in:
@@ -9,57 +9,57 @@ import (
|
||||
|
||||
func (c *Context) mov(a, b operand.Op, an, bn int, t *types.Basic) {
|
||||
switch {
|
||||
case an == 1 && bn == 1 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 1 && bn == 1:
|
||||
c.MOVB(a, b)
|
||||
case an == 1 && bn == 4 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0 && an == 1 && bn == 4:
|
||||
c.MOVBLSX(a, b)
|
||||
case an == 1 && bn == 4 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0 && an == 1 && bn == 4:
|
||||
c.MOVBLZX(a, b)
|
||||
case an == 1 && bn == 8 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0 && an == 1 && bn == 8:
|
||||
c.MOVBQSX(a, b)
|
||||
case an == 1 && bn == 8 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0 && an == 1 && bn == 8:
|
||||
c.MOVBQZX(a, b)
|
||||
case an == 1 && bn == 2 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0 && an == 1 && bn == 2:
|
||||
c.MOVBWSX(a, b)
|
||||
case an == 1 && bn == 2 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0 && an == 1 && bn == 2:
|
||||
c.MOVBWZX(a, b)
|
||||
case an == 4 && bn == 4 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 4 && bn == 4:
|
||||
c.MOVL(a, b)
|
||||
case an == 4 && bn == 8 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0 && an == 4 && bn == 8:
|
||||
c.MOVLQSX(a, b)
|
||||
case an == 4 && bn == 8 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0 && an == 4 && bn == 8:
|
||||
c.MOVLQZX(a, b)
|
||||
case an == 16 && bn == 16 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 16 && bn == 16:
|
||||
c.MOVOU(a, b)
|
||||
case an == 16 && bn == 8 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 8 && bn == 8:
|
||||
c.MOVQ(a, b)
|
||||
case an == 8 && bn == 16 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 8 && bn == 16:
|
||||
c.MOVQ(a, b)
|
||||
case an == 16 && bn == 16 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 16 && bn == 8:
|
||||
c.MOVQ(a, b)
|
||||
case an == 8 && bn == 8 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 16 && bn == 16:
|
||||
c.MOVQ(a, b)
|
||||
case an == 16 && bn == 8 && (t.Info()&types.IsFloat) != 0:
|
||||
case (t.Info()&types.IsFloat) != 0 && an == 8 && bn == 16:
|
||||
c.MOVSD(a, b)
|
||||
case an == 16 && bn == 16 && (t.Info()&types.IsFloat) != 0:
|
||||
case (t.Info()&types.IsFloat) != 0 && an == 16 && bn == 8:
|
||||
c.MOVSD(a, b)
|
||||
case an == 8 && bn == 16 && (t.Info()&types.IsFloat) != 0:
|
||||
case (t.Info()&types.IsFloat) != 0 && an == 16 && bn == 16:
|
||||
c.MOVSD(a, b)
|
||||
case an == 16 && bn == 16 && (t.Info()&types.IsFloat) != 0:
|
||||
case (t.Info()&types.IsFloat) != 0 && an == 4 && bn == 16:
|
||||
c.MOVSS(a, b)
|
||||
case an == 4 && bn == 16 && (t.Info()&types.IsFloat) != 0:
|
||||
case (t.Info()&types.IsFloat) != 0 && an == 16 && bn == 4:
|
||||
c.MOVSS(a, b)
|
||||
case an == 16 && bn == 4 && (t.Info()&types.IsFloat) != 0:
|
||||
case (t.Info()&types.IsFloat) != 0 && an == 16 && bn == 16:
|
||||
c.MOVSS(a, b)
|
||||
case an == 2 && bn == 2 && (t.Info()&types.IsInteger) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && an == 2 && bn == 2:
|
||||
c.MOVW(a, b)
|
||||
case an == 2 && bn == 4 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0 && an == 2 && bn == 4:
|
||||
c.MOVWLSX(a, b)
|
||||
case an == 2 && bn == 4 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0 && an == 2 && bn == 4:
|
||||
c.MOVWLZX(a, b)
|
||||
case an == 2 && bn == 8 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) == 0 && an == 2 && bn == 8:
|
||||
c.MOVWQSX(a, b)
|
||||
case an == 2 && bn == 8 && (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0:
|
||||
case (t.Info()&types.IsInteger) != 0 && (t.Info()&types.IsUnsigned) != 0 && an == 2 && bn == 8:
|
||||
c.MOVWQZX(a, b)
|
||||
default:
|
||||
c.AddErrorMessage("could not deduce mov instruction")
|
||||
|
||||
@@ -3,6 +3,7 @@ package gen
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/mmcloughlin/avo/internal/inst"
|
||||
@@ -57,6 +58,7 @@ func (m *mov) instruction(i inst.Instruction) {
|
||||
cond := fmt.Sprintf("(t.Info() & %s) %s 0", c, cmp[on])
|
||||
conds = append(conds, cond)
|
||||
}
|
||||
sort.Strings(conds)
|
||||
m.Printf("case %s:\n", strings.Join(conds, " && "))
|
||||
m.Printf("c.%s(a, b)\n", i.Opcode)
|
||||
}
|
||||
@@ -93,7 +95,9 @@ func flags(i inst.Instruction) map[string]bool {
|
||||
return f
|
||||
}
|
||||
|
||||
type movsize struct{ A, B int }
|
||||
type movsize struct{ A, B int8 }
|
||||
|
||||
func (s movsize) sortkey() uint16 { return (uint16(s.A) << 8) | uint16(s.B) }
|
||||
|
||||
func formsizes(i inst.Instruction) ([]movsize, error) {
|
||||
set := map[movsize]bool{}
|
||||
@@ -117,10 +121,11 @@ func formsizes(i inst.Instruction) ([]movsize, error) {
|
||||
for s := range set {
|
||||
ss = append(ss, s)
|
||||
}
|
||||
sort.Slice(ss, func(i, j int) bool { return ss[i].sortkey() < ss[j].sortkey() })
|
||||
return ss, nil
|
||||
}
|
||||
|
||||
var opsize = map[string]int{
|
||||
var opsize = map[string]int8{
|
||||
"imm8": -1,
|
||||
"imm16": -1,
|
||||
"imm32": -1,
|
||||
|
||||
Reference in New Issue
Block a user