2 Star 2 Fork 9

王布衣/gox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
distance.go 23.67 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-06-03 06:07 . 调整vek目录为num
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
. "github.com/mmcloughlin/avo/reg"
)
func genDot_F64() {
TEXT("Dot_AVX2_F64", NOSPLIT, "func(x, y []float64) float64")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB0_1"))
CMPQ(RDX, Imm(16))
JAE(LabelRef("LBB0_4"))
VXORPD(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB0_7"))
Label("LBB0_1")
{
VXORPS(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB0_4")
{
MOVQ(RDX, RAX)
ANDQ(I32(-16), RAX)
VXORPD(X0, X0, X0)
XORL(ECX, ECX)
VXORPD(X1, X1, X1)
VXORPD(X2, X2, X2)
VXORPD(X3, X3, X3)
}
Label("LBB0_5")
{
VMOVUPD(Mem{Base: RSI}.Idx(RCX, 8), Y4)
VMOVUPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(32), Y5)
VMOVUPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(64), Y6)
VMOVUPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(96), Y7)
VFMADD231PD(Mem{Base: RDI}.Idx(RCX, 8), Y4, Y0)
VFMADD231PD(Mem{Base: RDI}.Idx(RCX, 8).Offset(32), Y5, Y1)
VFMADD231PD(Mem{Base: RDI}.Idx(RCX, 8).Offset(64), Y6, Y2)
VFMADD231PD(Mem{Base: RDI}.Idx(RCX, 8).Offset(96), Y7, Y3)
ADDQ(Imm(16), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB0_5"))
VADDPD(Y0, Y1, Y0)
VADDPD(Y0, Y2, Y0)
VADDPD(Y0, Y3, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPD(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDSD(X1, X0, X0)
CMPQ(RAX, RDX)
JE(LabelRef("LBB0_8"))
}
Label("LBB0_7")
{
VMOVSD(Mem{Base: RSI}.Idx(RAX, 8), X1)
VFMADD231SD(Mem{Base: RDI}.Idx(RAX, 8), X1, X0)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB0_7"))
}
Label("LBB0_8")
{
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genDot_F32() {
TEXT("Dot_AVX2_F32", NOSPLIT, "func(x, y []float32) float32")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB1_1"))
CMPQ(RDX, Imm(32))
JAE(LabelRef("LBB1_4"))
VXORPS(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB1_7"))
Label("LBB1_1")
{
VXORPS(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB1_4")
{
MOVQ(RDX, RAX)
ANDQ(I32(-32), RAX)
VXORPS(X0, X0, X0)
XORL(ECX, ECX)
VXORPS(X1, X1, X1)
VXORPS(X2, X2, X2)
VXORPS(X3, X3, X3)
}
Label("LBB1_5")
{
VMOVUPS(Mem{Base: RSI}.Idx(RCX, 4), Y4)
VMOVUPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(32), Y5)
VMOVUPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(64), Y6)
VMOVUPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(96), Y7)
VFMADD231PS(Mem{Base: RDI}.Idx(RCX, 4), Y4, Y0)
VFMADD231PS(Mem{Base: RDI}.Idx(RCX, 4).Offset(32), Y5, Y1)
VFMADD231PS(Mem{Base: RDI}.Idx(RCX, 4).Offset(64), Y6, Y2)
VFMADD231PS(Mem{Base: RDI}.Idx(RCX, 4).Offset(96), Y7, Y3)
ADDQ(Imm(32), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB1_5"))
VADDPS(Y0, Y1, Y0)
VADDPS(Y0, Y2, Y0)
VADDPS(Y0, Y3, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPS(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDPS(X1, X0, X0)
VMOVSHDUP(X0, X1)
VADDSS(X1, X0, X0)
CMPQ(RAX, RDX)
JE(LabelRef("LBB1_8"))
}
Label("LBB1_7")
{
VMOVSS(Mem{Base: RSI}.Idx(RAX, 4), X1)
VFMADD231SS(Mem{Base: RDI}.Idx(RAX, 4), X1, X0)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB1_7"))
}
Label("LBB1_8")
{
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genNorm_F64() {
TEXT("Norm_AVX2_F64", NOSPLIT, "func(x []float64) float64")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("x").Len(), RSI)
TESTQ(RSI, RSI)
JE(LabelRef("LBB2_1"))
CMPQ(RSI, Imm(16))
JAE(LabelRef("LBB2_4"))
VXORPD(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB2_11"))
Label("LBB2_1")
{
VXORPD(X0, X0, X0)
VSQRTSD(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB2_4")
{
MOVQ(RSI, RAX)
ANDQ(I32(-16), RAX)
LEAQ(Mem{Base: RAX}.Offset(-16), RCX)
MOVQ(RCX, R8)
SHRQ(Imm(4), R8)
ADDQ(Imm(1), R8)
TESTQ(RCX, RCX)
JE(LabelRef("LBB2_5"))
MOVQ(R8, RCX)
ANDQ(I32(-2), RCX)
VXORPD(X0, X0, X0)
XORL(EDX, EDX)
VXORPD(X1, X1, X1)
VXORPD(X2, X2, X2)
VXORPD(X3, X3, X3)
}
Label("LBB2_7")
{
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8), Y4)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(32), Y5)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(64), Y6)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(96), Y7)
VFMADD213PD(Y0, Y4, Y4)
VFMADD213PD(Y1, Y5, Y5)
VFMADD213PD(Y2, Y6, Y6)
VFMADD213PD(Y3, Y7, Y7)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(128), Y0)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(160), Y1)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(192), Y2)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(224), Y3)
VFMADD213PD(Y4, Y0, Y0)
VFMADD213PD(Y5, Y1, Y1)
VFMADD213PD(Y6, Y2, Y2)
VFMADD213PD(Y7, Y3, Y3)
ADDQ(Imm(32), RDX)
ADDQ(I32(-2), RCX)
JNE(LabelRef("LBB2_7"))
TESTB(Imm(1), R8B)
JE(LabelRef("LBB2_10"))
}
Label("LBB2_9")
{
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8), Y4)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(32), Y5)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(64), Y6)
VMOVUPD(Mem{Base: RDI}.Idx(RDX, 8).Offset(96), Y7)
VFMADD231PD(Y4, Y4, Y0)
VFMADD231PD(Y5, Y5, Y1)
VFMADD231PD(Y6, Y6, Y2)
VFMADD231PD(Y7, Y7, Y3)
}
Label("LBB2_10")
{
VADDPD(Y3, Y1, Y1)
VADDPD(Y2, Y0, Y0)
VADDPD(Y1, Y0, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPD(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDSD(X1, X0, X0)
CMPQ(RAX, RSI)
JE(LabelRef("LBB2_12"))
}
Label("LBB2_11")
{
VMOVSD(Mem{Base: RDI}.Idx(RAX, 8), X1)
VFMADD231SD(X1, X1, X0)
ADDQ(Imm(1), RAX)
CMPQ(RSI, RAX)
JNE(LabelRef("LBB2_11"))
}
Label("LBB2_12")
{
VSQRTSD(X0, X0, X0)
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB2_5")
{
VXORPD(X0, X0, X0)
XORL(EDX, EDX)
VXORPD(X1, X1, X1)
VXORPD(X2, X2, X2)
VXORPD(X3, X3, X3)
TESTB(Imm(1), R8B)
JNE(LabelRef("LBB2_9"))
JMP(LabelRef("LBB2_10"))
}
}
func genNorm_F32() {
data := GLOBL("dataNormF32", RODATA|NOPTR)
DATA(0, U32(0xc0400000))
DATA(4, U32(0xbf000000))
DATA(8, U32(0x7fffffff))
DATA(12, U32(0x00800000))
TEXT("Norm_AVX2_F32", NOSPLIT, "func(x []float32) float32")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("x").Len(), RSI)
TESTQ(RSI, RSI)
JE(LabelRef("LBB3_1"))
CMPQ(RSI, Imm(32))
JAE(LabelRef("LBB3_4"))
VXORPS(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB3_11"))
Label("LBB3_1")
{
VXORPS(X0, X0, X0)
JMP(LabelRef("LBB3_12"))
}
Label("LBB3_4")
{
MOVQ(RSI, RAX)
ANDQ(I32(-32), RAX)
LEAQ(Mem{Base: RAX}.Offset(-32), RCX)
MOVQ(RCX, R8)
SHRQ(Imm(5), R8)
ADDQ(Imm(1), R8)
TESTQ(RCX, RCX)
JE(LabelRef("LBB3_5"))
MOVQ(R8, RCX)
ANDQ(I32(-2), RCX)
VXORPS(X0, X0, X0)
XORL(EDX, EDX)
VXORPS(X1, X1, X1)
VXORPS(X2, X2, X2)
VXORPS(X3, X3, X3)
}
Label("LBB3_7")
{
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4), Y4)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(32), Y5)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(64), Y6)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(96), Y7)
VFMADD213PS(Y0, Y4, Y4)
VFMADD213PS(Y1, Y5, Y5)
VFMADD213PS(Y2, Y6, Y6)
VFMADD213PS(Y3, Y7, Y7)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(128), Y0)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(160), Y1)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(192), Y2)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(224), Y3)
VFMADD213PS(Y4, Y0, Y0)
VFMADD213PS(Y5, Y1, Y1)
VFMADD213PS(Y6, Y2, Y2)
VFMADD213PS(Y7, Y3, Y3)
ADDQ(Imm(64), RDX)
ADDQ(I32(-2), RCX)
JNE(LabelRef("LBB3_7"))
TESTB(Imm(1), R8B)
JE(LabelRef("LBB3_10"))
}
Label("LBB3_9")
{
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4), Y4)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(32), Y5)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(64), Y6)
VMOVUPS(Mem{Base: RDI}.Idx(RDX, 4).Offset(96), Y7)
VFMADD231PS(Y4, Y4, Y0)
VFMADD231PS(Y5, Y5, Y1)
VFMADD231PS(Y6, Y6, Y2)
VFMADD231PS(Y7, Y7, Y3)
}
Label("LBB3_10")
{
VADDPS(Y3, Y1, Y1)
VADDPS(Y2, Y0, Y0)
VADDPS(Y1, Y0, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPS(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDPS(X1, X0, X0)
VMOVSHDUP(X0, X1)
VADDSS(X1, X0, X0)
CMPQ(RAX, RSI)
JE(LabelRef("LBB3_12"))
}
Label("LBB3_11")
{
VMOVSS(Mem{Base: RDI}.Idx(RAX, 4), X1)
VFMADD231SS(X1, X1, X0)
ADDQ(Imm(1), RAX)
CMPQ(RSI, RAX)
JNE(LabelRef("LBB3_11"))
}
Label("LBB3_12")
{
VRSQRTSS(X0, X0, X1)
VMULSS(X1, X0, X2)
VFMADD213SS(data.Offset(0), X2, X1)
VMULSS(data.Offset(4), X2, X2)
VMULSS(X1, X2, X1)
VBROADCASTSS(data.Offset(8), X2)
VANDPS(X2, X0, X0)
VCMPSS(Imm(1), data.Offset(12), X0, X0)
VANDNPS(X1, X0, X0)
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB3_5")
{
VXORPS(X0, X0, X0)
XORL(EDX, EDX)
VXORPS(X1, X1, X1)
VXORPS(X2, X2, X2)
VXORPS(X3, X3, X3)
TESTB(Imm(1), R8B)
JNE(LabelRef("LBB3_9"))
JMP(LabelRef("LBB3_10"))
}
}
func genDistance_F64() {
TEXT("Distance_AVX2_F64", NOSPLIT, "func(x, y []float64) float64")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB4_1"))
CMPQ(RDX, Imm(16))
JAE(LabelRef("LBB4_4"))
VXORPD(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB4_7"))
Label("LBB4_1")
{
VXORPD(X0, X0, X0)
VSQRTSD(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB4_4")
{
MOVQ(RDX, RAX)
ANDQ(I32(-16), RAX)
VXORPD(X0, X0, X0)
XORL(ECX, ECX)
VXORPD(X1, X1, X1)
VXORPD(X2, X2, X2)
VXORPD(X3, X3, X3)
}
Label("LBB4_5")
{
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8), Y4)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(32), Y5)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(64), Y6)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(96), Y7)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8), Y4, Y4)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(32), Y5, Y5)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(64), Y6, Y6)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(96), Y7, Y7)
VFMADD231PD(Y4, Y4, Y0)
VFMADD231PD(Y5, Y5, Y1)
VFMADD231PD(Y6, Y6, Y2)
VFMADD231PD(Y7, Y7, Y3)
ADDQ(Imm(16), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB4_5"))
VADDPD(Y0, Y1, Y0)
VADDPD(Y0, Y2, Y0)
VADDPD(Y0, Y3, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPD(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDSD(X1, X0, X0)
CMPQ(RAX, RDX)
JE(LabelRef("LBB4_8"))
}
Label("LBB4_7")
{
VMOVSD(Mem{Base: RDI}.Idx(RAX, 8), X1)
VSUBSD(Mem{Base: RSI}.Idx(RAX, 8), X1, X1)
VFMADD231SD(X1, X1, X0)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB4_7"))
}
Label("LBB4_8")
{
VSQRTSD(X0, X0, X0)
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genDistance_F32() {
data := GLOBL("dataDistanceF32", RODATA|NOPTR)
DATA(0, U32(0xc0400000))
DATA(4, U32(0xbf000000))
DATA(8, U32(0x7fffffff))
DATA(12, U32(0x00800000))
TEXT("Distance_AVX2_F32", NOSPLIT, "func(x, y []float32) float32")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB5_1"))
CMPQ(RDX, Imm(32))
JAE(LabelRef("LBB5_4"))
VXORPS(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB5_7"))
Label("LBB5_1")
{
VXORPS(X0, X0, X0)
JMP(LabelRef("LBB5_8"))
}
Label("LBB5_4")
{
MOVQ(RDX, RAX)
ANDQ(I32(-32), RAX)
VXORPS(X0, X0, X0)
XORL(ECX, ECX)
VXORPS(X1, X1, X1)
VXORPS(X2, X2, X2)
VXORPS(X3, X3, X3)
}
Label("LBB5_5")
{
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4), Y4)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(32), Y5)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(64), Y6)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(96), Y7)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4), Y4, Y4)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(32), Y5, Y5)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(64), Y6, Y6)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(96), Y7, Y7)
VFMADD231PS(Y4, Y4, Y0)
VFMADD231PS(Y5, Y5, Y1)
VFMADD231PS(Y6, Y6, Y2)
VFMADD231PS(Y7, Y7, Y3)
ADDQ(Imm(32), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB5_5"))
VADDPS(Y0, Y1, Y0)
VADDPS(Y0, Y2, Y0)
VADDPS(Y0, Y3, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPS(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDPS(X1, X0, X0)
VMOVSHDUP(X0, X1)
VADDSS(X1, X0, X0)
CMPQ(RAX, RDX)
JE(LabelRef("LBB5_8"))
}
Label("LBB5_7")
{
VMOVSS(Mem{Base: RDI}.Idx(RAX, 4), X1)
VSUBSS(Mem{Base: RSI}.Idx(RAX, 4), X1, X1)
VFMADD231SS(X1, X1, X0)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB5_7"))
}
Label("LBB5_8")
{
VRSQRTSS(X0, X0, X1)
VMULSS(X1, X0, X2)
VFMADD213SS(data.Offset(0), X2, X1)
VMULSS(data.Offset(4), X2, X2)
VMULSS(X1, X2, X1)
VBROADCASTSS(data.Offset(8), X2)
VANDPS(X2, X0, X0)
VCMPSS(Imm(1), data.Offset(12), X0, X0)
VANDNPS(X1, X0, X0)
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genManhattanNorm_F64() {
data := GLOBL("dataManhattanNormF64", RODATA|NOPTR)
DATA(0, U64(0x7fffffffffffffff))
DATA(8, U64(0x7fffffffffffffff))
DATA(16, U64(0x7fffffffffffffff))
TEXT("ManhattanNorm_AVX2_F64", NOSPLIT, "func(x []float64) float64")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("x").Len(), RSI)
TESTQ(RSI, RSI)
JE(LabelRef("LBB6_1"))
CMPQ(RSI, Imm(16))
JAE(LabelRef("LBB6_4"))
VXORPD(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB6_7"))
Label("LBB6_1")
{
VXORPS(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB6_4")
{
MOVQ(RSI, RAX)
ANDQ(I32(-16), RAX)
VXORPD(X0, X0, X0)
VBROADCASTSD(data.Offset(0), Y1)
XORL(ECX, ECX)
VXORPD(X2, X2, X2)
VXORPD(X3, X3, X3)
VXORPD(X4, X4, X4)
}
Label("LBB6_5")
{
VANDPD(Mem{Base: RDI}.Idx(RCX, 8), Y1, Y5)
VADDPD(Y0, Y5, Y0)
VANDPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(32), Y1, Y5)
VADDPD(Y2, Y5, Y2)
VANDPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(64), Y1, Y5)
VANDPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(96), Y1, Y6)
VADDPD(Y3, Y5, Y3)
VADDPD(Y4, Y6, Y4)
ADDQ(Imm(16), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB6_5"))
VADDPD(Y0, Y2, Y0)
VADDPD(Y0, Y3, Y0)
VADDPD(Y0, Y4, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPD(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDSD(X1, X0, X0)
CMPQ(RAX, RSI)
JE(LabelRef("LBB6_9"))
}
Label("LBB6_7")
{
VMOVUPD(data.Offset(8), X1)
}
Label("LBB6_8")
{
VMOVSD(Mem{Base: RDI}.Idx(RAX, 8), X2)
VANDPD(X1, X2, X2)
VADDSD(X0, X2, X0)
ADDQ(Imm(1), RAX)
CMPQ(RSI, RAX)
JNE(LabelRef("LBB6_8"))
}
Label("LBB6_9")
{
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genManhattanNorm_F32() {
data := GLOBL("dataManhattanNormF32", RODATA|NOPTR)
DATA(0, U32(0x7fffffff))
TEXT("ManhattanNorm_AVX2_F32", NOSPLIT, "func(x []float32) float32")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("x").Len(), RSI)
TESTQ(RSI, RSI)
JE(LabelRef("LBB7_1"))
CMPQ(RSI, Imm(32))
JAE(LabelRef("LBB7_4"))
VXORPS(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB7_7"))
Label("LBB7_1")
{
VXORPS(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB7_4")
{
MOVQ(RSI, RAX)
ANDQ(I32(-32), RAX)
VXORPS(X0, X0, X0)
VBROADCASTSS(data.Offset(0), Y1)
XORL(ECX, ECX)
VXORPS(X2, X2, X2)
VXORPS(X3, X3, X3)
VXORPS(X4, X4, X4)
}
Label("LBB7_5")
{
VANDPS(Mem{Base: RDI}.Idx(RCX, 4), Y1, Y5)
VADDPS(Y0, Y5, Y0)
VANDPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(32), Y1, Y5)
VADDPS(Y2, Y5, Y2)
VANDPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(64), Y1, Y5)
VANDPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(96), Y1, Y6)
VADDPS(Y3, Y5, Y3)
VADDPS(Y4, Y6, Y4)
ADDQ(Imm(32), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB7_5"))
VADDPS(Y0, Y2, Y0)
VADDPS(Y0, Y3, Y0)
VADDPS(Y0, Y4, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPS(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDPS(X1, X0, X0)
VMOVSHDUP(X0, X1)
VADDSS(X1, X0, X0)
CMPQ(RAX, RSI)
JE(LabelRef("LBB7_9"))
}
Label("LBB7_7")
{
VBROADCASTSS(data.Offset(0), X1)
}
Label("LBB7_8")
{
VMOVSS(Mem{Base: RDI}.Idx(RAX, 4), X2)
VANDPS(X1, X2, X2)
VADDSS(X0, X2, X0)
ADDQ(Imm(1), RAX)
CMPQ(RSI, RAX)
JNE(LabelRef("LBB7_8"))
}
Label("LBB7_9")
{
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genManhattanDistance_F64() {
data := GLOBL("dataManhattanDistanceF64", RODATA|NOPTR)
DATA(0, U64(0x7fffffffffffffff))
DATA(8, U64(0x7fffffffffffffff))
DATA(16, U64(0x7fffffffffffffff))
TEXT("ManhattanDistance_AVX2_F64", NOSPLIT, "func(x, y []float64) float64")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB8_1"))
CMPQ(RDX, Imm(16))
JAE(LabelRef("LBB8_4"))
VXORPD(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB8_7"))
Label("LBB8_1")
{
VXORPS(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB8_4")
{
MOVQ(RDX, RAX)
ANDQ(I32(-16), RAX)
VXORPD(X0, X0, X0)
VBROADCASTSD(data.Offset(0), Y1)
XORL(ECX, ECX)
VXORPD(X2, X2, X2)
VXORPD(X3, X3, X3)
VXORPD(X4, X4, X4)
}
Label("LBB8_5")
{
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8), Y5)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(32), Y6)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(64), Y7)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(96), Y8)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8), Y5, Y5)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(32), Y6, Y6)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(64), Y7, Y7)
VSUBPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(96), Y8, Y8)
VANDPD(Y1, Y5, Y5)
VADDPD(Y0, Y5, Y0)
VANDPD(Y1, Y6, Y5)
VADDPD(Y2, Y5, Y2)
VANDPD(Y1, Y7, Y5)
VADDPD(Y3, Y5, Y3)
VANDPD(Y1, Y8, Y5)
VADDPD(Y4, Y5, Y4)
ADDQ(Imm(16), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB8_5"))
VADDPD(Y0, Y2, Y0)
VADDPD(Y0, Y3, Y0)
VADDPD(Y0, Y4, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPD(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDSD(X1, X0, X0)
CMPQ(RAX, RDX)
JE(LabelRef("LBB8_9"))
}
Label("LBB8_7")
{
VMOVUPD(data.Offset(8), X1)
}
Label("LBB8_8")
{
VMOVSD(Mem{Base: RDI}.Idx(RAX, 8), X2)
VSUBSD(Mem{Base: RSI}.Idx(RAX, 8), X2, X2)
VANDPD(X1, X2, X2)
VADDSD(X0, X2, X0)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB8_8"))
}
Label("LBB8_9")
{
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genManhattanDistance_F32() {
data := GLOBL("dataManhattanDistanceF32", RODATA|NOPTR)
DATA(0, U32(0x7fffffff))
TEXT("ManhattanDistance_AVX2_F32", NOSPLIT, "func(x, y []float32) float32")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB9_1"))
CMPQ(RDX, Imm(32))
JAE(LabelRef("LBB9_4"))
VXORPS(X0, X0, X0)
XORL(EAX, EAX)
JMP(LabelRef("LBB9_7"))
Label("LBB9_1")
{
VXORPS(X0, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB9_4")
{
MOVQ(RDX, RAX)
ANDQ(I32(-32), RAX)
VXORPS(X0, X0, X0)
VBROADCASTSS(data.Offset(0), Y1)
XORL(ECX, ECX)
VXORPS(X2, X2, X2)
VXORPS(X3, X3, X3)
VXORPS(X4, X4, X4)
}
Label("LBB9_5")
{
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4), Y5)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(32), Y6)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(64), Y7)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(96), Y8)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4), Y5, Y5)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(32), Y6, Y6)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(64), Y7, Y7)
VSUBPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(96), Y8, Y8)
VANDPS(Y1, Y5, Y5)
VADDPS(Y0, Y5, Y0)
VANDPS(Y1, Y6, Y5)
VADDPS(Y2, Y5, Y2)
VANDPS(Y1, Y7, Y5)
VADDPS(Y3, Y5, Y3)
VANDPS(Y1, Y8, Y5)
VADDPS(Y4, Y5, Y4)
ADDQ(Imm(32), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB9_5"))
VADDPS(Y0, Y2, Y0)
VADDPS(Y0, Y3, Y0)
VADDPS(Y0, Y4, Y0)
VEXTRACTF128(Imm(1), Y0, X1)
VADDPS(X1, X0, X0)
VPERMILPD(Imm(1), X0, X1)
VADDPS(X1, X0, X0)
VMOVSHDUP(X0, X1)
VADDSS(X1, X0, X0)
CMPQ(RAX, RDX)
JE(LabelRef("LBB9_9"))
}
Label("LBB9_7")
{
VBROADCASTSS(data.Offset(0), X1)
}
Label("LBB9_8")
{
VMOVSS(Mem{Base: RDI}.Idx(RAX, 4), X2)
VSUBSS(Mem{Base: RSI}.Idx(RAX, 4), X2, X2)
VANDPS(X1, X2, X2)
VADDSS(X0, X2, X0)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB9_8"))
}
Label("LBB9_9")
{
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genCosineSimilarity_F64() {
TEXT("CosineSimilarity_AVX2_F64", NOSPLIT, "func(x, y []float64) float64")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB2_1"))
CMPQ(RDX, Imm(8))
JAE(LabelRef("LBB2_5"))
VXORPD(X1, X1, X1)
XORL(EAX, EAX)
VXORPD(X2, X2, X2)
VXORPD(X0, X0, X0)
JMP(LabelRef("LBB2_4"))
Label("LBB2_1")
{
VXORPD(X0, X0, X0)
VXORPD(X1, X1, X1)
VSQRTSD(X1, X1, X1)
VDIVSD(X1, X0, X0)
Store(X0, ReturnIndex(0))
RET()
}
Label("LBB2_5")
{
MOVQ(RDX, RAX)
ANDQ(I32(-8), RAX)
VXORPD(X1, X1, X1)
XORL(ECX, ECX)
VXORPD(X3, X3, X3)
VXORPD(X2, X2, X2)
VXORPD(X4, X4, X4)
VXORPD(X0, X0, X0)
VXORPD(X5, X5, X5)
}
Label("LBB2_6")
{
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8), Y6)
VMOVUPD(Mem{Base: RDI}.Idx(RCX, 8).Offset(32), Y7)
VMOVUPD(Mem{Base: RSI}.Idx(RCX, 8), Y8)
VMOVUPD(Mem{Base: RSI}.Idx(RCX, 8).Offset(32), Y9)
VFMADD231PD(Y6, Y8, Y0)
VFMADD231PD(Y7, Y9, Y5)
VFMADD231PD(Y6, Y6, Y2)
VFMADD231PD(Y7, Y7, Y4)
VFMADD231PD(Y8, Y8, Y1)
VFMADD231PD(Y9, Y9, Y3)
ADDQ(Imm(8), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB2_6"))
VADDPD(Y0, Y5, Y0)
VEXTRACTF128(Imm(1), Y0, X5)
VADDPD(X5, X0, X0)
VPERMILPD(Imm(1), X0, X5)
VADDSD(X5, X0, X0)
VADDPD(Y2, Y4, Y2)
VEXTRACTF128(Imm(1), Y2, X4)
VADDPD(X4, X2, X2)
VPERMILPD(Imm(1), X2, X4)
VADDSD(X4, X2, X2)
VADDPD(Y1, Y3, Y1)
VEXTRACTF128(Imm(1), Y1, X3)
VADDPD(X3, X1, X1)
VPERMILPD(Imm(1), X1, X3)
VADDSD(X3, X1, X1)
CMPQ(RAX, RDX)
JE(LabelRef("LBB2_8"))
}
Label("LBB2_4")
{
VMOVSD(Mem{Base: RDI}.Idx(RAX, 8), X3)
VMOVSD(Mem{Base: RSI}.Idx(RAX, 8), X4)
VFMADD231SD(X3, X4, X0)
VFMADD231SD(X3, X3, X2)
VFMADD231SD(X4, X4, X1)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB2_4"))
}
Label("LBB2_8")
{
VMULSD(X2, X1, X1)
VSQRTSD(X1, X1, X1)
VDIVSD(X1, X0, X0)
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
func genCosineSimilarity_F32() {
data := GLOBL("dataCosineSimilarityF32", RODATA|NOPTR)
DATA(0, U32(0xc0400000))
DATA(4, U32(0xbf000000))
TEXT("CosineSimilarity_AVX2_F32", NOSPLIT, "func(x, y []float32) float32")
Pragma("noescape")
Load(Param("x").Base(), RDI)
Load(Param("y").Base(), RSI)
Load(Param("x").Len(), RDX)
TESTQ(RDX, RDX)
JE(LabelRef("LBB3_1"))
CMPQ(RDX, Imm(16))
JAE(LabelRef("LBB3_5"))
VXORPS(X1, X1, X1)
XORL(EAX, EAX)
VXORPS(X2, X2, X2)
VXORPS(X0, X0, X0)
JMP(LabelRef("LBB3_4"))
Label("LBB3_1")
{
VXORPS(X0, X0, X0)
VXORPS(X1, X1, X1)
JMP(LabelRef("LBB3_9"))
}
Label("LBB3_5")
{
MOVQ(RDX, RAX)
ANDQ(I32(-16), RAX)
VXORPS(X1, X1, X1)
XORL(ECX, ECX)
VXORPS(X3, X3, X3)
VXORPS(X2, X2, X2)
VXORPS(X4, X4, X4)
VXORPS(X0, X0, X0)
VXORPS(X5, X5, X5)
}
Label("LBB3_6")
{
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4), Y6)
VMOVUPS(Mem{Base: RDI}.Idx(RCX, 4).Offset(32), Y7)
VMOVUPS(Mem{Base: RSI}.Idx(RCX, 4), Y8)
VMOVUPS(Mem{Base: RSI}.Idx(RCX, 4).Offset(32), Y9)
VFMADD231PS(Y6, Y8, Y0)
VFMADD231PS(Y7, Y9, Y5)
VFMADD231PS(Y6, Y6, Y2)
VFMADD231PS(Y7, Y7, Y4)
VFMADD231PS(Y8, Y8, Y1)
VFMADD231PS(Y9, Y9, Y3)
ADDQ(Imm(16), RCX)
CMPQ(RAX, RCX)
JNE(LabelRef("LBB3_6"))
VADDPS(Y0, Y5, Y0)
VEXTRACTF128(Imm(1), Y0, X5)
VADDPS(X5, X0, X0)
VPERMILPD(Imm(1), X0, X5)
VADDPS(X5, X0, X0)
VMOVSHDUP(X0, X5)
VADDSS(X5, X0, X0)
VADDPS(Y2, Y4, Y2)
VEXTRACTF128(Imm(1), Y2, X4)
VADDPS(X4, X2, X2)
VPERMILPD(Imm(1), X2, X4)
VADDPS(X4, X2, X2)
VMOVSHDUP(X2, X4)
VADDSS(X4, X2, X2)
VADDPS(Y1, Y3, Y1)
VEXTRACTF128(Imm(1), Y1, X3)
VADDPS(X3, X1, X1)
VPERMILPD(Imm(1), X1, X3)
VADDPS(X3, X1, X1)
VMOVSHDUP(X1, X3)
VADDSS(X3, X1, X1)
CMPQ(RAX, RDX)
JE(LabelRef("LBB3_8"))
}
Label("LBB3_4")
{
VMOVSS(Mem{Base: RDI}.Idx(RAX, 4), X3)
VMOVSS(Mem{Base: RSI}.Idx(RAX, 4), X4)
VFMADD231SS(X3, X4, X0)
VFMADD231SS(X3, X3, X2)
VFMADD231SS(X4, X4, X1)
ADDQ(Imm(1), RAX)
CMPQ(RDX, RAX)
JNE(LabelRef("LBB3_4"))
}
Label("LBB3_8")
{
VMULSS(X2, X1, X1)
}
Label("LBB3_9")
{
VRSQRTSS(X1, X1, X2)
VMULSS(X2, X1, X1)
VFMADD213SS(data.Offset(0), X2, X1)
VMULSS(data.Offset(4), X2, X2)
VMULSS(X0, X2, X0)
VMULSS(X0, X1, X0)
VZEROUPPER()
Store(X0, ReturnIndex(0))
RET()
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/gox.git
git@gitee.com:quant1x/gox.git
quant1x
gox
gox
v1.10.8

搜索帮助