Files
avo/reg/reg_test.go

181 lines
3.6 KiB
Go
Raw Normal View History

2018-11-11 22:17:06 -06:00
package reg
import (
"testing"
"testing/quick"
)
func TestIDFields(t *testing.T) {
f := func(v uint8, kind Kind, idx Index) bool {
id := newid(v, kind, idx)
return id.Kind() == kind && id.Index() == idx
}
if err := quick.Check(f, nil); err != nil {
t.Fatal(err)
}
}
func TestIDIsVirtual(t *testing.T) {
cases := []Virtual{
GeneralPurpose.Virtual(42, S64),
Vector.Virtual(42, S128),
all: AVX-512 (#217) Extends avo to support most AVX-512 instruction sets. The instruction type is extended to support suffixes. The K family of opmask registers is added to the register package, and the operand package is updated to support the new operand types. Move instruction deduction in `Load` and `Store` is extended to support KMOV* and VMOV* forms. Internal code generation packages were overhauled. Instruction database loading required various messy changes to account for the additional complexities of the AVX-512 instruction sets. The internal/api package was added to introduce a separation between instruction forms in the database, and the functions avo provides to create them. This was required since with instruction suffixes there is no longer a one-to-one mapping between instruction constructors and opcodes. AVX-512 bloated generated source code size substantially, initially increasing compilation and CI test times to an unacceptable level. Two changes were made to address this: 1. Instruction constructors in the `x86` package moved to an optab-based approach. This compiles substantially faster than the verbose code generation we had before. 2. The most verbose code-generated tests are moved under build tags and limited to a stress test mode. Stress test builds are run on schedule but not in regular CI. An example of AVX-512 accelerated 16-lane MD5 is provided to demonstrate and test the new functionality. Updates #20 #163 #229 Co-authored-by: Vaughn Iverson <vsivsi@yahoo.com>
2021-11-12 18:35:36 -08:00
Opmask.Virtual(42, S64),
}
for _, r := range cases {
if !r.ID().IsVirtual() {
t.FailNow()
}
}
}
func TestIDIsPhysical(t *testing.T) {
all: AVX-512 (#217) Extends avo to support most AVX-512 instruction sets. The instruction type is extended to support suffixes. The K family of opmask registers is added to the register package, and the operand package is updated to support the new operand types. Move instruction deduction in `Load` and `Store` is extended to support KMOV* and VMOV* forms. Internal code generation packages were overhauled. Instruction database loading required various messy changes to account for the additional complexities of the AVX-512 instruction sets. The internal/api package was added to introduce a separation between instruction forms in the database, and the functions avo provides to create them. This was required since with instruction suffixes there is no longer a one-to-one mapping between instruction constructors and opcodes. AVX-512 bloated generated source code size substantially, initially increasing compilation and CI test times to an unacceptable level. Two changes were made to address this: 1. Instruction constructors in the `x86` package moved to an optab-based approach. This compiles substantially faster than the verbose code generation we had before. 2. The most verbose code-generated tests are moved under build tags and limited to a stress test mode. Stress test builds are run on schedule but not in regular CI. An example of AVX-512 accelerated 16-lane MD5 is provided to demonstrate and test the new functionality. Updates #20 #163 #229 Co-authored-by: Vaughn Iverson <vsivsi@yahoo.com>
2021-11-12 18:35:36 -08:00
cases := []Physical{AL, AH, AX, EAX, RAX, X1, Y2, Z31, K1}
for _, r := range cases {
if !r.ID().IsPhysical() {
t.FailNow()
}
}
}
2018-11-11 22:17:06 -06:00
func TestSpecSize(t *testing.T) {
2018-11-11 22:17:06 -06:00
cases := []struct {
Spec Spec
Size uint
2018-11-11 22:17:06 -06:00
}{
2018-12-06 17:26:33 -08:00
{S0, 0},
2018-11-11 22:17:06 -06:00
{S8L, 1},
{S8H, 1},
{S16, 2},
{S32, 4},
{S64, 8},
{S128, 16},
{S256, 32},
{S512, 64},
}
for _, c := range cases {
if c.Spec.Size() != c.Size {
t.Errorf("%v.Size() = %d; expect = %d", c.Spec, c.Spec.Size(), c.Size)
2018-11-11 22:17:06 -06:00
}
}
}
2018-12-02 23:59:29 -08:00
func TestToVirtual(t *testing.T) {
v := GeneralPurpose.Virtual(42, S32)
if ToVirtual(v) != v {
t.Errorf("ToVirtual(v) != v for virtual register")
}
if ToVirtual(ECX) != nil {
t.Errorf("ToVirtual should be nil for physical registers")
}
}
func TestToPhysical(t *testing.T) {
v := GeneralPurpose.Virtual(42, S32)
if ToPhysical(v) != nil {
t.Errorf("ToPhysical should be nil for virtual registers")
}
if ToPhysical(ECX) != ECX {
t.Errorf("ToPhysical(p) != p for physical register")
}
}
func TestFamilyLookup(t *testing.T) {
cases := []struct {
Family *Family
ID Index
Spec Spec
Expect Physical
}{
{GeneralPurpose, 0, S8, AL},
{GeneralPurpose, 1, S8L, CL},
{GeneralPurpose, 2, S8H, DH},
{GeneralPurpose, 3, S16, BX},
{GeneralPurpose, 9, S32, R9L},
{GeneralPurpose, 13, S64, R13},
{GeneralPurpose, 13, S512, nil},
{GeneralPurpose, 133, S64, nil},
{Vector, 1, S128, X1},
{Vector, 13, S256, Y13},
{Vector, 27, S512, Z27},
{Vector, 1, S16, nil},
{Vector, 299, S256, nil},
all: AVX-512 (#217) Extends avo to support most AVX-512 instruction sets. The instruction type is extended to support suffixes. The K family of opmask registers is added to the register package, and the operand package is updated to support the new operand types. Move instruction deduction in `Load` and `Store` is extended to support KMOV* and VMOV* forms. Internal code generation packages were overhauled. Instruction database loading required various messy changes to account for the additional complexities of the AVX-512 instruction sets. The internal/api package was added to introduce a separation between instruction forms in the database, and the functions avo provides to create them. This was required since with instruction suffixes there is no longer a one-to-one mapping between instruction constructors and opcodes. AVX-512 bloated generated source code size substantially, initially increasing compilation and CI test times to an unacceptable level. Two changes were made to address this: 1. Instruction constructors in the `x86` package moved to an optab-based approach. This compiles substantially faster than the verbose code generation we had before. 2. The most verbose code-generated tests are moved under build tags and limited to a stress test mode. Stress test builds are run on schedule but not in regular CI. An example of AVX-512 accelerated 16-lane MD5 is provided to demonstrate and test the new functionality. Updates #20 #163 #229 Co-authored-by: Vaughn Iverson <vsivsi@yahoo.com>
2021-11-12 18:35:36 -08:00
{Opmask, 1, S64, K1},
{Opmask, 8, S64, nil},
{Opmask, 0, S64, K0},
}
for _, c := range cases {
got := c.Family.Lookup(c.ID, c.Spec)
if got != c.Expect {
t.Errorf("idx=%v spec=%v: lookup got %v expect %v", c.ID, c.Spec, got, c.Expect)
}
}
}
func TestPhysicalAs(t *testing.T) {
cases := []struct {
Register Physical
Spec Spec
Expect Physical
}{
{DX, S8L, DL},
{DX, S8H, DH},
{DX, S8, DL},
{DX, S16, DX},
{DX, S32, EDX},
{DX, S64, RDX},
{DX, S256, nil},
}
for _, c := range cases {
got := c.Register.as(c.Spec)
if got != c.Expect {
t.Errorf("%s.as(%v) = %v; expect %v", c.Register.Asm(), c.Spec, got, c.Expect)
}
}
}
func TestVirtualAs(t *testing.T) {
v := GeneralPurpose.Virtual(0, S64)
specs := []Spec{S8, S8L, S8H, S16, S32, S64}
for _, s := range specs {
if v.as(s).Mask() != s.Mask() {
t.FailNow()
}
}
}
func TestLookupPhysical(t *testing.T) {
cases := []struct {
Kind Kind
Index Index
Spec Spec
Expect Physical
}{
{KindGP, 0, S8L, AL},
{KindGP, 1, S8H, CH},
{KindGP, 7, S8, DIB},
{KindGP, 8, S16, R8W},
{KindGP, 9, S32, R9L},
{KindGP, 10, S64, R10},
{KindVector, 7, S128, X7},
{KindVector, 17, S256, Y17},
{KindVector, 27, S512, Z27},
all: AVX-512 (#217) Extends avo to support most AVX-512 instruction sets. The instruction type is extended to support suffixes. The K family of opmask registers is added to the register package, and the operand package is updated to support the new operand types. Move instruction deduction in `Load` and `Store` is extended to support KMOV* and VMOV* forms. Internal code generation packages were overhauled. Instruction database loading required various messy changes to account for the additional complexities of the AVX-512 instruction sets. The internal/api package was added to introduce a separation between instruction forms in the database, and the functions avo provides to create them. This was required since with instruction suffixes there is no longer a one-to-one mapping between instruction constructors and opcodes. AVX-512 bloated generated source code size substantially, initially increasing compilation and CI test times to an unacceptable level. Two changes were made to address this: 1. Instruction constructors in the `x86` package moved to an optab-based approach. This compiles substantially faster than the verbose code generation we had before. 2. The most verbose code-generated tests are moved under build tags and limited to a stress test mode. Stress test builds are run on schedule but not in regular CI. An example of AVX-512 accelerated 16-lane MD5 is provided to demonstrate and test the new functionality. Updates #20 #163 #229 Co-authored-by: Vaughn Iverson <vsivsi@yahoo.com>
2021-11-12 18:35:36 -08:00
{KindOpmask, 1, S64, K1},
}
for _, c := range cases {
if got := LookupPhysical(c.Kind, c.Index, c.Spec); !Equal(got, c.Expect) {
t.FailNow()
}
}
}
func TestLookupIDSelf(t *testing.T) {
all: AVX-512 (#217) Extends avo to support most AVX-512 instruction sets. The instruction type is extended to support suffixes. The K family of opmask registers is added to the register package, and the operand package is updated to support the new operand types. Move instruction deduction in `Load` and `Store` is extended to support KMOV* and VMOV* forms. Internal code generation packages were overhauled. Instruction database loading required various messy changes to account for the additional complexities of the AVX-512 instruction sets. The internal/api package was added to introduce a separation between instruction forms in the database, and the functions avo provides to create them. This was required since with instruction suffixes there is no longer a one-to-one mapping between instruction constructors and opcodes. AVX-512 bloated generated source code size substantially, initially increasing compilation and CI test times to an unacceptable level. Two changes were made to address this: 1. Instruction constructors in the `x86` package moved to an optab-based approach. This compiles substantially faster than the verbose code generation we had before. 2. The most verbose code-generated tests are moved under build tags and limited to a stress test mode. Stress test builds are run on schedule but not in regular CI. An example of AVX-512 accelerated 16-lane MD5 is provided to demonstrate and test the new functionality. Updates #20 #163 #229 Co-authored-by: Vaughn Iverson <vsivsi@yahoo.com>
2021-11-12 18:35:36 -08:00
cases := []Physical{AL, AH, AX, EAX, RAX, X1, Y2, Z31, K1}
for _, r := range cases {
if got := LookupID(r.ID(), r.spec()); !Equal(got, r) {
t.FailNow()
}
}
}