// Code generated by modernc.org/undup from the per-target vec_*.go files; DO NOT EDIT.

//go:build (freebsd && arm) || (linux && arm) || (windows && 386)

package vec

import (
	"unsafe"

	"modernc.org/libc"
	libsqlite3 "modernc.org/sqlite/lib"
)

type Timaxdiv_t = struct {
	F__ccgo_align [0]uint32
	Fquot         Tintmax_t
	Frem          Tintmax_t
}

type Tlldiv_t = struct {
	F__ccgo_align [0]uint32
	Fquot         int64
	Frem          int64
}

type Tsbe_query_knn_data = struct {
	F__ccgo_align [0]uint32
	Fk            Ti64
	Fk_used       Ti64
	Frowids       uintptr
	Fdistances    uintptr
	Fcurrent_idx  Ti64
}

type Tsqlite3_index_info = struct {
	F__ccgo_align     [0]uint32
	FnConstraint      int32
	FaConstraint      uintptr
	FnOrderBy         int32
	FaOrderBy         uintptr
	FaConstraintUsage uintptr
	FidxNum           int32
	FidxStr           uintptr
	FneedToFreeIdxStr int32
	ForderByConsumed  int32
	F__ccgo_align9    [4]byte
	FestimatedCost    float64
	FestimatedRows    Tsqlite3_int64
	FidxFlags         int32
	F__ccgo_align12   [4]byte
	FcolUsed          Tsqlite3_uint64
}

type Tsqlite3_rtree_query_info = struct {
	F__ccgo_align  [0]uint32
	FpContext      uintptr
	FnParam        int32
	FaParam        uintptr
	FpUser         uintptr
	FxDelUser      uintptr
	FaCoord        uintptr
	FanQueue       uintptr
	FnCoord        int32
	FiLevel        int32
	FmxLevel       int32
	FiRowid        Tsqlite3_int64
	FrParentScore  Tsqlite3_rtree_dbl
	FeParentWithin int32
	FeWithin       int32
	FrScore        Tsqlite3_rtree_dbl
	FapSqlParam    uintptr
	F__ccgo_pad16  [4]byte
}

type Tvec0_query_knn_data = struct {
	F__ccgo_align [0]uint32
	Fk            Ti64
	Fk_used       Ti64
	Frowids       uintptr
	Fdistances    uintptr
	Fcurrent_idx  Ti64
}

type Tvec0_query_point_data = struct {
	F__ccgo_align [0]uint32
	Frowid        Ti64
	Fvectors      [16]uintptr
	Fdone         int32
	F__ccgo_pad3  [4]byte
}

type Tvec_each_cursor = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab_cursor
	F__ccgo_align1 [4]byte
	FiRowid        Ti64
	Fvector_type   _VectorElementType
	Fvector        uintptr
	Fdimensions    Tsize_t
	Fcleanup       Tvector_cleanup
}

type Tvec_npy_each_cursor = struct {
	F__ccgo_align      [0]uint32
	Fbase              Tsqlite3_vtab_cursor
	F__ccgo_align1     [4]byte
	FiRowid            Ti64
	FelementType       _VectorElementType
	FnElements         Tsize_t
	FnDimensions       Tsize_t
	Finput_type        Tvec_npy_each_input_type
	Fvector            uintptr
	Ffile              uintptr
	FchunksBuffer      uintptr
	FchunksBufferSize  Tsize_t
	FmaxChunks         Tsize_t
	FcurrentChunkIndex Tsize_t
	FcurrentChunkSize  Tsize_t
	Feof               int32
}

type Tvec_static_blob_entries_cursor = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab_cursor
	F__ccgo_align1 [4]byte
	FiRowid        Tsqlite3_int64
	Fquery_plan    Tvec_sbe_query_plan
	Fknn_data      uintptr
}

type Tvec_static_blobs_cursor = struct {
	F__ccgo_align  [0]uint32
	Fbase          Tsqlite3_vtab_cursor
	F__ccgo_align1 [4]byte
	FiRowid        Tsqlite3_int64
}

func Xvec0Filter_point(tls *libc.TLS, pCur uintptr, p uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, rc int32
	var point_data uintptr
	var _ /* rowid at bp+0 */ Ti64
	_, _, _ = i, point_data, rc
	point_data = libc.UintptrFromInt32(0)
	point_data = libsqlite3.Xsqlite3_malloc(tls, int32(80))
	if !(point_data != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto error
	}
	libc.Xmemset(tls, point_data, 0, uint32(80))
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
		rc = Xvec0_rowid_from_id(tls, p, **(**uintptr)(__ccgo_up(argv)), bp)
		if rc == int32(m_SQLITE_EMPTY) {
			goto eof
		}
		if rc != m_SQLITE_OK {
			goto error
		}
	} else {
		**(**Ti64)(__ccgo_up(bp)) = libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
	}
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		rc = Xvec0_get_vector_data(tls, p, **(**Ti64)(__ccgo_up(bp)), i, point_data+8+uintptr(i)*4, libc.UintptrFromInt32(0))
		if rc == int32(m_SQLITE_EMPTY) {
			goto eof
		}
		if rc != m_SQLITE_OK {
			goto error
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Frowid = **(**Ti64)(__ccgo_up(bp))
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Fdone = 0
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data = point_data
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_POINT)
	return m_SQLITE_OK
	goto eof
eof:
	;
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Frowid = **(**Ti64)(__ccgo_up(bp))
	(*Tvec0_query_point_data)(unsafe.Pointer(point_data)).Fdone = int32(1)
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data = point_data
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_POINT)
	return m_SQLITE_OK
	goto error
error:
	;
	Xvec0_query_point_data_clear(tls, point_data)
	libsqlite3.Xsqlite3_free(tls, point_data)
	return rc
}

func _vec_eachFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCur uintptr
	var rc int32
	var _ /* pzErrMsg at bp+0 */ uintptr
	_, _ = pCur, rc
	_ = idxNum
	_ = idxStr
	pCur = pVtabCursor
	if (*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fcleanup})))(tls, (*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector)
		(*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fvector = libc.UintptrFromInt32(0)
	}
	rc = Xvector_from_value(tls, **(**uintptr)(__ccgo_up(argv)), pCur+20, pCur+24, pCur+16, pCur+28, bp)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
		return int32(m_SQLITE_ERROR)
	}
	(*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	return m_SQLITE_OK
}

func _vec_eachOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(32))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint32(32))
	**(**uintptr)(__ccgo_up(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_npy_eachOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(64))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint32(64))
	**(**uintptr)(__ccgo_up(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_static_blob_entriesOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(24))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint32(24))
	**(**uintptr)(__ccgo_up(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec_static_blobsOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(16))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint32(16))
	**(**uintptr)(__ccgo_up(ppCursor)) = pCur
	return m_SQLITE_OK
}
