// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build go1.18 && amd64 && !noasm && !appengine

package kernels

import (
	
	

	
	
	
	
	
	
)

//go:noescape
func _get_take_indices_uint32_avx2(, ,  unsafe.Pointer, ,  int64)

var getTakeIndicesUint32AVX2Tables = makeGetTakeIndicesUint32AVX2Tables()

func makeGetTakeIndicesUint32AVX2Tables() ( [400]byte) {
	copy([:], filterUint32Tables[:])
	for  := 0;  < 8; ++ {
		binary.LittleEndian.PutUint32([352+*4:], uint32())
	}
	for  := 0;  < 4; ++ {
		binary.LittleEndian.PutUint32([384+*4:], 8)
	}
	return 
}

func getTakeIndicesUint32AVX2( memory.Allocator,  *exec.ArraySpan) (arrow.ArrayData, bool) {
	if !cpu.X86.HasAVX2 || .MayHaveNulls() || .Offset%8 != 0 || .Len < 64 {
		return nil, false
	}

	 := .Buffers[1].Buf
	 := .Offset / 8
	 := (.Len + 7) / 8
	if  < 0 || + > int64(len()) {
		return nil, false
	}
	 := [ : +]

	// VisitSetBitRuns is especially effective for long runs, so only use the
	// compactor when a short sample shows enough fragmented bytes to amortize
	// its setup cost.
	const (
		 = 256
		    = 4
	)
	 := 0
	for  := int64(0);  <  &&  < ; ++ {
		 := []
		if  != 0 &&  != 0xff {
			++
			if  ==  {
				break
			}
		}
	}
	if  <  {
		return nil, false
	}

	 := int64(bitutil.CountSetBits(, 0, int(.Len)))
	if  == 0 {
		return array.NewData(arrow.PrimitiveTypes.Uint32, 0, []*memory.Buffer{nil, memory.NewBufferBytes(nil)}, nil, 0, 0), true
	}

	 := memory.NewBufferWithAllocator(.Allocate(int()*4), )
	defer .Release()
	 := arrow.GetData[uint32](.Bytes())
	 := int64(0xff)
	if  := .Len & 7;  != 0 {
		 = int64((uint64(1) << uint()) - 1)
	}
	_get_take_indices_uint32_avx2(
		unsafe.Pointer(unsafe.SliceData()),
		unsafe.Pointer(unsafe.SliceData()),
		unsafe.Pointer(unsafe.SliceData(getTakeIndicesUint32AVX2Tables[:])),
		,
		,
	)
	return array.NewData(arrow.PrimitiveTypes.Uint32, int(), []*memory.Buffer{nil, }, nil, 0, 0), true
}