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

gotypes: error with Store(xmm, ReturnIndex(0)) #145

Open
rleiwang opened this issue May 3, 2020 · 6 comments · May be fixed by #149
Open

gotypes: error with Store(xmm, ReturnIndex(0)) #145

rleiwang opened this issue May 3, 2020 · 6 comments · May be fixed by #149

Comments

@rleiwang
Copy link

rleiwang commented May 3, 2020

I am trying to implement https://github.com/lemire/streamvbyte/blob/master/src/streamvbyte_x64_decode.c#L2.

However, Using Store(xmm, ReturnIndex(0)) resulted an error in go generate asm.go:85: component is not primitive exit status 1. Instead I changed to Store(xmm, ReturnIndex(0).Index(0)) to work around it.

I also manually changed to use AVX512, VMOVDQU8. The following is Go assembler code.

	// func Shuffle(mask []byte, data []byte) [4]uint32
	// Requires: AVX, SSE2, SSSE3
	TEXT ·Shuffle(SB), NOSPLIT, $0-64
		MOVQ    data_base+24(FP), AX
		VMOVDQU8 (AX), X0
		MOVQ    mask_base+0(FP), AX
		PSHUFB  (AX), X0
		VMOVDQU8 X0, ret_0+48(FP)
		RET
@mmcloughlin
Copy link
Owner

mmcloughlin commented May 4, 2020

Would you be able to make this work if your function signature took a pointer to the output? Like:

shuffle(mask, data []byte, out *byte)

@mmcloughlin
Copy link
Owner

I may be able to extend the gotypes.Component interface to make this possible. I'd need to think about this some more.

https://pkg.go.dev/github.com/mmcloughlin/avo@v0.0.0-20200425082757-f891fe8d9749/gotypes?tab=doc#Component

@rleiwang
Copy link
Author

rleiwang commented May 5, 2020

@mmcloughlin Thanks for the quick response. For now, I would prefer use Store(xmm, ReturnIndex(0).Index(0)) if it works, since [4]uint32 is a value type.

@mmcloughlin
Copy link
Owner

@klauspost has encountered the same problem:

I am trying to generate a function in avo that has func(data [n][16]byte) signature, and I'm trying to load the [16]byte into YMM registers.
My problem is that if I use Load(Param("data").Index(i), YMM()) (and XMM) I get component is not primitive and I cannot find a way to get it back to a VecVirtual anyway. I would like to send values directly on the stack, since slices are bigger and pointers is just an extra indirection.
I also tried to resolve the address so I could just use a MOVOU myself, but couldn't make that work either.

https://gophers.slack.com/archives/C6WDZJ70S/p1589142748014600

@mmcloughlin
Copy link
Owner

mmcloughlin commented May 10, 2020

As discussed on Slack, probably the solution here is to provide an accessor method Component.Addr() for:

addr operand.Mem

The only question in my mind is what to do with errors that can occur in method chaining, like when i is too large in Param("data").Index(i).Addr(). Should the signature be:

  1. Addr() operand.Mem which panics when there is an error
  2. Addr() (operand.Mem, error)

If it returns an error, a Must function might be useful. This could possibly belong in the operand package.

@rleiwang
Copy link
Author

@mmcloughlin Thanks for the update. I did what you suggested for the time being.

func(masks, data []byte, offset int, out []uint32)

https://github.com/rleiwang/svb/blob/10f63e6855cff78e14a0371425cbf569e8456590/asm.go#L11

@mmcloughlin mmcloughlin linked a pull request May 22, 2020 that will close this issue
@mmcloughlin mmcloughlin changed the title error with Store(xmm, ReturnIndex(0)) gotypes: error with Store(xmm, ReturnIndex(0)) May 22, 2020
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

Successfully merging a pull request may close this issue.

2 participants