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

why the result is reversed ? #399

Open
lysShub opened this issue Aug 4, 2023 · 1 comment
Open

why the result is reversed ? #399

lysShub opened this issue Aug 4, 2023 · 1 comment

Comments

@lysShub
Copy link

lysShub commented Aug 4, 2023

gen code:

const MM_CMPINT_NLT = operand.U8(5)

//go:generate go run gen.go -pkg main -out ../ge_amd64.s -stubs ../ge_amd64.go
func main() {
	TEXT("ge", NOSPLIT, "func(a,b []uint64, r *uint8)")
	Doc("r_bits[i] = a[i] >= b[i], a,b must have 8 elements")

	aPtr := operand.Mem{Base: Load(Param("a").Base(), GP64())}
	bPtr := operand.Mem{Base: Load(Param("b").Base(), GP64())}
	rPtr := operand.Mem{Base: Load(Param("r"), GP64())}

	k := K()
	zmm := ZMM()
	VMOVDQU64(bPtr, zmm)
	VPCMPUQ(MM_CMPINT_NLT, aPtr, zmm, k)
	KMOVB(k, rPtr)

	RET()

	Generate()
}

expect r_bits[i] = a[i] >= b[i],but all bits is reversed:

var r uint8
var a = []uint64{1, 2, 3, 4, 0, 0, 0, 0}
var b = []uint64{0, 3, 0, 0, 1, 1, 1, 1}

ge(a, b, &r)

fmt.Printf("%.8b \n", r)
// exp: 00001101
// act: 11110010

source code:
ge.zip

@klauspost
Copy link
Contributor

Because you are swapping inputs? Remember that compared to Intel syntax all parameters are swapped.

VPCMPUQ(imm8, zmm3, zmm2, k1)

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