//go:build !purego

package sparse

import (
	
)

func gatherBits( []byte,  Uint8Array) int {
	 := min(len()*8, .Len())
	 := 0

	if  >= 8 {
		 = ( / 8) * 8
		// Make sure `offset` is at least 4 bytes, otherwise VPGATHERDD may read
		// data beyond the end of the program memory and trigger a fault.
		//
		// If the boolean values do not have enough padding we must fallback to
		// the scalar algorithm to be able to load single bytes from memory.
		if .off >= 4 && cpu.X86.HasAVX2 {
			gatherBitsAVX2(, .Slice(0, ))
		} else {
			gatherBitsDefault(, .Slice(0, ))
		}
	}

	for  <  {
		 :=  / 8
		 :=  % 8
		 := .Index()
		[] = (( & 1) << ) | ([] & ^(1 << ))
		++
	}

	return 
}

func gather32( []uint32,  Uint32Array) int {
	 := min(len(), .Len())
	 := 0

	if  >= 16 && cpu.X86.HasAVX2 {
		 = ( / 8) * 8
		gather32AVX2([::], )
	}

	for  <  {
		[] = .Index()
		++
	}

	return 
}

func gather64( []uint64,  Uint64Array) int {
	 := min(len(), .Len())
	 := 0

	if  >= 8 && cpu.X86.HasAVX2 {
		 = ( / 4) * 4
		gather64AVX2([::], )
	}

	for  <  {
		[] = .Index()
		++
	}

	return 
}

//go:noescape
func gatherBitsAVX2( []byte,  Uint8Array)

//go:noescape
func gatherBitsDefault( []byte,  Uint8Array)

//go:noescape
func gather32AVX2( []uint32,  Uint32Array)

//go:noescape
func gather64AVX2( []uint64,  Uint64Array)

//go:noescape
func gather128( [][16]byte,  Uint128Array) int