Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCATTER/GATHER Vector memory operand validation is too strict #193

Open
vsivsi opened this issue May 26, 2021 · 0 comments
Open

SCATTER/GATHER Vector memory operand validation is too strict #193

vsivsi opened this issue May 26, 2021 · 0 comments

Comments

@vsivsi
Copy link
Contributor

vsivsi commented May 26, 2021

E.g. The following instruction is perfectly valid AVX-512: VPSCATTERQQ Z7, K1, (Z8*1)

Avo currently enforces that all memory operands have a non-nil GP64 base register.

However for the VM(64/32)(x/y/z) memory operands used by the scatter/gather instructions, these checks are too strict, because as the above instruction shows, the Base register is optional for VM* memory operands.

I've tentatively modified the functions isvm() and VerifyMemOperands(...) to:

func isvm(op Op, idx func(Op) bool) bool {
	m, ok := op.(Mem)
	// return ok && IsR64(m.Base) && idx(m.Index)
	return ok && (m.Base == nil || IsR64(m.Base)) && idx(m.Index)
}

And:

// VerifyMemOperands checks the instruction's memory operands.
func VerifyMemOperands(i *ir.Instruction) error {
	for _, op := range i.Operands {
		m, ok := op.(operand.Mem)
		if !ok {
			continue
		}

		// if m.Base == nil {
		if m.Base == nil && !(operand.IsVmx(m) || operand.IsVmy(m) || operand.IsVmz(m)) {
			return errors.New("bad memory operand: missing base register")
		}

		if m.Index != nil && m.Scale == 0 {
			return errors.New("bad memory operand: index register with scale 0")
		}
	}
	return nil
}

This seems to do the trick. I keep meaning to put together a PR with the AVX512_BITALG new instructions: VPOPCNTB/W and VPSHUFBITQMB. If the above fixes look okay, I'll fold them in as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant