Runtime error: index out of range when build with non-amd64 flags

The same as Runtime error: index out of range [20] with length 20 for ristretto

panic: runtime error: index out of range [10] with length 10

goroutine 262 [running]:
github.com/dgraph-io/ristretto/z/simd.Search(0x1418096c8, 0xa, 0x800, 0x894cba93dee136e5, 0x8000000000000004)

and then I checked the source code

it // +build !amd64
so if it’s arm64 or others , it have a bug.
The code is short. Let’s just see the case.


// Search uses the Clever search to find the correct key.
func Search(xs []uint64, k uint64) int16 {
	if len(xs) < 8 {
		return Naive(xs, k)
	}
	var twos, pk [4]uint64
	pk[0] = k
	pk[1] = k
	pk[2] = k
	pk[3] = k

       //# here comes the bug
       // # if Len(xs) mod 8 !=0 
       //# then xs[i+2] may got index out of range error
       // for it build with flags +build !amd64
       // it won's show in amd64 but will show in non-amd64 environment, such as arm64 or others

	for i := 0; i < len(xs); i += 8 {
		twos[0] = xs[i]
		twos[1] = xs[i+2]
		twos[2] = xs[i+4]
		twos[3] = xs[i+6]
		if twos[0] >= pk[0] {
			return int16(i / 2)
		}
		if twos[1] >= pk[1] {
			return int16((i + 2) / 2)
		}
		if twos[2] >= pk[2] {
			return int16((i + 4) / 2)
		}
		if twos[3] >= pk[3] {
			return int16((i + 6) / 2)
		}

	}
	return int16(len(xs) / 2)
}