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

//go:build (darwin && amd64) || (darwin && arm64) || (freebsd && amd64) || (linux && amd64) || (linux && arm64) || (linux && loong64) || (linux && ppc64le) || (linux && riscv64) || (linux && s390x) || (netbsd && amd64) || (openbsd && amd64) || (openbsd && arm64) || (windows && (amd64 || arm64))

package vec

import (
	"modernc.org/libc"
)

func _distance_cosine_float(tls *libc.TLS, pVect1v uintptr, pVect2v uintptr, qty_ptr uintptr) (r Tf32) {
	var aMag, bMag, dot Tf32
	var i, qty Tsize_t
	var pVect1, pVect2 uintptr
	_, _, _, _, _, _, _ = aMag, bMag, dot, i, pVect1, pVect2, qty
	pVect1 = pVect1v
	pVect2 = pVect2v
	qty = **(**Tsize_t)(__ccgo_up(qty_ptr))
	dot = libc.Float32FromInt32(0)
	aMag = libc.Float32FromInt32(0)
	bMag = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < qty) {
			break
		}
		dot = dot + Tf32(**(**Tf32)(__ccgo_up(pVect1))***(**Tf32)(__ccgo_up(pVect2)))
		aMag = aMag + Tf32(**(**Tf32)(__ccgo_up(pVect1))***(**Tf32)(__ccgo_up(pVect1)))
		bMag = bMag + Tf32(**(**Tf32)(__ccgo_up(pVect2))***(**Tf32)(__ccgo_up(pVect2)))
		pVect1 += 4
		pVect2 += 4
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Float64FromInt32(1) - float64(dot)/float64(libc.Xsqrt(tls, float64(aMag))*libc.Xsqrt(tls, float64(bMag))))
}

func _distance_cosine_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Tf32) {
	var a, b uintptr
	var aMag, bMag, dot Tf32
	var d, i Tsize_t
	_, _, _, _, _, _, _ = a, aMag, b, bMag, d, dot, i
	a = pA
	b = pB
	d = **(**Tsize_t)(__ccgo_up(pD))
	dot = libc.Float32FromInt32(0)
	aMag = libc.Float32FromInt32(0)
	bMag = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < d) {
			break
		}
		dot = dot + Tf32(int32(**(**Ti8)(__ccgo_up(a)))*int32(**(**Ti8)(__ccgo_up(b))))
		aMag = aMag + Tf32(int32(**(**Ti8)(__ccgo_up(a)))*int32(**(**Ti8)(__ccgo_up(a))))
		bMag = bMag + Tf32(int32(**(**Ti8)(__ccgo_up(b)))*int32(**(**Ti8)(__ccgo_up(b))))
		a = a + 1
		b = b + 1
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Float64FromInt32(1) - float64(dot)/float64(libc.Xsqrt(tls, float64(aMag))*libc.Xsqrt(tls, float64(bMag))))
}

func _l2_sqr_float(tls *libc.TLS, pVect1v uintptr, pVect2v uintptr, qty_ptr uintptr) (r Tf32) {
	var i, qty Tsize_t
	var pVect1, pVect2 uintptr
	var res, t Tf32
	_, _, _, _, _, _ = i, pVect1, pVect2, qty, res, t
	pVect1 = pVect1v
	pVect2 = pVect2v
	qty = **(**Tsize_t)(__ccgo_up(qty_ptr))
	res = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < qty) {
			break
		}
		t = **(**Tf32)(__ccgo_up(pVect1)) - **(**Tf32)(__ccgo_up(pVect2))
		pVect1 += 4
		pVect2 += 4
		res = res + Tf32(t*t)
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Xsqrt(tls, float64(res)))
}

func _l2_sqr_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Tf32) {
	var a, b uintptr
	var d, i Tsize_t
	var res, t Tf32
	_, _, _, _, _, _ = a, b, d, i, res, t
	a = pA
	b = pB
	d = **(**Tsize_t)(__ccgo_up(pD))
	res = libc.Float32FromInt32(0)
	i = uint64(0)
	for {
		if !(i < d) {
			break
		}
		t = float32(int32(**(**Ti8)(__ccgo_up(a))) - int32(**(**Ti8)(__ccgo_up(b))))
		a = a + 1
		b = b + 1
		res = res + Tf32(t*t)
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Xsqrt(tls, float64(res)))
}
