From 3881907ec85d70485ecd1f08f32c429bb4c4da93 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Mon, 26 Nov 2018 23:53:07 -0800 Subject: [PATCH] implement vm{32,64}{x,y} operand checks --- operand/checks.go | 29 +++++++++++++++++++++++++---- operand/checks_test.go | 17 +++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/operand/checks.go b/operand/checks.go index 72e5c96..84cea20 100644 --- a/operand/checks.go +++ b/operand/checks.go @@ -172,26 +172,47 @@ func IsM256(op avo.Operand) bool { return IsM64(op) } +// IsVm32x returns true if op is a vector memory operand with 32-bit XMM index. func IsVm32x(op avo.Operand) bool { - return false + return IsVmx(op) } +// IsVm64x returns true if op is a vector memory operand with 64-bit XMM index. func IsVm64x(op avo.Operand) bool { - return false + return IsVmx(op) } +// IsVmx returns true if op is a vector memory operand with XMM index. +func IsVmx(op avo.Operand) bool { + return isvm(op, IsXmm) +} + +// IsVm32y returns true if op is a vector memory operand with 32-bit YMM index. func IsVm32y(op avo.Operand) bool { - return false + return IsVmy(op) } +// IsVm64y returns true if op is a vector memory operand with 64-bit YMM index. func IsVm64y(op avo.Operand) bool { - return false + return IsVmy(op) +} + +// IsVmy returns true if op is a vector memory operand with YMM index. +func IsVmy(op avo.Operand) bool { + return isvm(op, IsYmm) +} + +func isvm(op avo.Operand, idx func(avo.Operand) bool) bool { + m, ok := op.(Mem) + return ok && IsR64(m.Base) && idx(m.Index) } func IsRel8(op avo.Operand) bool { + // TODO(mbm): implement rel8 operand check return false } func IsRel32(op avo.Operand) bool { + // TODO(mbm): implement rel32 operand check return false } diff --git a/operand/checks_test.go b/operand/checks_test.go index b9140d8..8950aae 100644 --- a/operand/checks_test.go +++ b/operand/checks_test.go @@ -112,6 +112,23 @@ func TestChecks(t *testing.T) { {IsM256, Mem{Base: reg.RBX, Index: reg.R12, Scale: 2}, true}, {IsM256, Mem{Base: reg.R13L}, false}, + + // Vector memory operands + {IsVm32x, Mem{Base: reg.R14, Index: reg.X11}, true}, + {IsVm32x, Mem{Base: reg.R14L, Index: reg.X11}, false}, + {IsVm32x, Mem{Base: reg.R14, Index: reg.Y11}, false}, + + {IsVm64x, Mem{Base: reg.R14, Index: reg.X11}, true}, + {IsVm64x, Mem{Base: reg.R14L, Index: reg.X11}, false}, + {IsVm64x, Mem{Base: reg.R14, Index: reg.Y11}, false}, + + {IsVm32y, Mem{Base: reg.R9, Index: reg.Y11}, true}, + {IsVm32y, Mem{Base: reg.R11L, Index: reg.Y11}, false}, + {IsVm32y, Mem{Base: reg.R8, Index: reg.Z11}, false}, + + {IsVm64y, Mem{Base: reg.R9, Index: reg.Y11}, true}, + {IsVm64y, Mem{Base: reg.R11L, Index: reg.Y11}, false}, + {IsVm64y, Mem{Base: reg.R8, Index: reg.Z11}, false}, } for _, c := range cases {