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

Allow user to use a Mem with a nil Base #403

Open
cocotyty opened this issue Sep 26, 2023 · 2 comments
Open

Allow user to use a Mem with a nil Base #403

cocotyty opened this issue Sep 26, 2023 · 2 comments

Comments

@cocotyty
Copy link

cocotyty commented Sep 26, 2023

It's very useful for users who want to leverage LEAQ to speed up some integer computations.

For example:

LEAQ -8(AX * 8), BX

is much efficiency than:

MOVQ $+8,BX
MULQ BX
SUBQ 8, AX
MOVQ AX,BX
@cocotyty
Copy link
Author

@mmcloughlin

func IsMSize(op Op, n uint) bool {

// IsMSize returns true if op is a memory operand using general-purpose address
// registers of the given size in bytes.
func IsMSize(op Op, n uint) bool {
	// TODO(mbm): should memory operands have a size attribute as well?
	// TODO(mbm): m8,m16,m32,m64 checks do not actually check size
	m, ok := op.(Mem)
	return ok && IsMReg(m.Base) && (m.Index == nil || IsMReg(m.Index))
}

I think it is not very hard to implement this feature.

@klauspost
Copy link
Contributor

klauspost commented Dec 19, 2023

A PR would make the change easy to add.

Meanwhile I wouldn't expect XORQ(tmp, tmp) to be a huge overhead and use that as base. For most CPUs zeroing a register is basically ignored, since they just use a virtual zero register.

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

2 participants