usearch 2.21.4 → 2.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -69
- package/binding.gyp +15 -37
- package/c/CMakeLists.txt +4 -5
- package/c/README.md +8 -8
- package/c/lib.cpp +32 -14
- package/c/test.c +124 -1
- package/c/usearch.h +24 -3
- package/cpp/CMakeLists.txt +4 -0
- package/cpp/README.md +5 -5
- package/cpp/bench.cpp +97 -116
- package/cpp/test.cpp +117 -20
- package/include/usearch/index.hpp +224 -48
- package/include/usearch/index_dense.hpp +105 -40
- package/include/usearch/index_plugins.hpp +1387 -204
- package/javascript/README.md +1 -1
- package/javascript/dist/cjs/usearch.d.ts +8 -3
- package/javascript/dist/cjs/usearch.js +12 -4
- package/javascript/dist/esm/usearch.d.ts +8 -3
- package/javascript/dist/esm/usearch.js +12 -4
- package/javascript/lib.cpp +17 -0
- package/javascript/usearch.test.js +117 -94
- package/javascript/usearch.ts +14 -6
- package/numkong/.clang-tidy +30 -0
- package/{simsimd → numkong}/.cmake-format.py +18 -0
- package/numkong/.editorconfig +12 -0
- package/numkong/.git-blame-ignore-revs +123 -0
- package/numkong/.mailmap +15 -0
- package/numkong/.spi.yml +11 -0
- package/numkong/.swift-format +14 -0
- package/numkong/CITATION.cff +81 -0
- package/numkong/CONTRIBUTING.md +500 -0
- package/numkong/Cargo.toml +54 -0
- package/numkong/MANIFEST.in +8 -0
- package/numkong/Package.swift +84 -0
- package/numkong/README.md +569 -0
- package/numkong/bench/README.md +217 -0
- package/numkong/bench/bench-browser.html +323 -0
- package/numkong/bench/bench.cpp +344 -0
- package/numkong/bench/bench.hpp +816 -0
- package/numkong/bench/bench.js +148 -0
- package/numkong/bench/bench.mjs +616 -0
- package/numkong/bench/bench_attention.cpp +113 -0
- package/numkong/bench/bench_cast.cpp +264 -0
- package/numkong/bench/bench_cross_amx.cpp +62 -0
- package/numkong/bench/bench_cross_arm.cpp +245 -0
- package/numkong/bench/bench_cross_blas.cpp +309 -0
- package/numkong/bench/bench_cross_loongarch.cpp +106 -0
- package/numkong/bench/bench_cross_power.cpp +84 -0
- package/numkong/bench/bench_cross_rvv.cpp +121 -0
- package/numkong/bench/bench_cross_serial.cpp +151 -0
- package/numkong/bench/bench_cross_sme.cpp +163 -0
- package/numkong/bench/bench_cross_wasm.cpp +142 -0
- package/numkong/bench/bench_cross_x86.cpp +455 -0
- package/numkong/bench/bench_curved.cpp +210 -0
- package/numkong/bench/bench_dot.cpp +315 -0
- package/numkong/bench/bench_each.cpp +503 -0
- package/numkong/bench/bench_geospatial.cpp +112 -0
- package/numkong/bench/bench_maxsim.cpp +154 -0
- package/numkong/bench/bench_mesh.cpp +148 -0
- package/numkong/bench/bench_probability.cpp +60 -0
- package/numkong/bench/bench_reduce.cpp +371 -0
- package/numkong/bench/bench_set.cpp +73 -0
- package/numkong/bench/bench_sparse.cpp +198 -0
- package/numkong/bench/bench_spatial.cpp +347 -0
- package/numkong/bench/bench_trigonometry.cpp +137 -0
- package/numkong/bench/swift/Bench.swift +506 -0
- package/numkong/binding.gyp +169 -0
- package/numkong/build.rs +484 -0
- package/numkong/c/dispatch.h +512 -0
- package/numkong/c/dispatch_bf16.c +447 -0
- package/numkong/c/dispatch_bf16c.c +52 -0
- package/numkong/c/dispatch_e2m3.c +296 -0
- package/numkong/c/dispatch_e3m2.c +284 -0
- package/numkong/c/dispatch_e4m3.c +318 -0
- package/numkong/c/dispatch_e5m2.c +316 -0
- package/numkong/c/dispatch_f16.c +452 -0
- package/numkong/c/dispatch_f16c.c +58 -0
- package/numkong/c/dispatch_f32.c +434 -0
- package/numkong/c/dispatch_f32c.c +99 -0
- package/numkong/c/dispatch_f64.c +348 -0
- package/numkong/c/dispatch_f64c.c +98 -0
- package/numkong/c/dispatch_i16.c +96 -0
- package/numkong/c/dispatch_i32.c +89 -0
- package/numkong/c/dispatch_i4.c +153 -0
- package/numkong/c/dispatch_i64.c +86 -0
- package/numkong/c/dispatch_i8.c +348 -0
- package/numkong/c/dispatch_other.c +348 -0
- package/numkong/c/dispatch_u1.c +193 -0
- package/numkong/c/dispatch_u16.c +124 -0
- package/numkong/c/dispatch_u32.c +118 -0
- package/numkong/c/dispatch_u4.c +153 -0
- package/numkong/c/dispatch_u64.c +102 -0
- package/numkong/c/dispatch_u8.c +364 -0
- package/numkong/c/numkong.c +940 -0
- package/numkong/cmake/nk_arm_isa_probes.cmake +61 -0
- package/numkong/cmake/nk_isa_probe.cmake +90 -0
- package/numkong/cmake/nk_loongarch_isa_probes.cmake +15 -0
- package/numkong/cmake/nk_math_lib.cmake +46 -0
- package/numkong/cmake/nk_power_isa_probes.cmake +15 -0
- package/numkong/cmake/nk_riscv_isa_probes.cmake +19 -0
- package/numkong/cmake/nk_x86_isa_probes.cmake +35 -0
- package/numkong/cmake/toolchain-aarch64-gnu.cmake +86 -0
- package/numkong/cmake/toolchain-android-arm64.cmake +25 -0
- package/numkong/cmake/toolchain-android-armv7.cmake +25 -0
- package/numkong/cmake/toolchain-loongarch64-gnu.cmake +68 -0
- package/numkong/cmake/toolchain-ppc64le-gnu.cmake +74 -0
- package/numkong/cmake/toolchain-riscv64-gnu.cmake +107 -0
- package/numkong/cmake/toolchain-riscv64-llvm.cmake +114 -0
- package/numkong/cmake/toolchain-wasi.cmake +77 -0
- package/numkong/cmake/toolchain-wasm.cmake +70 -0
- package/numkong/cmake/toolchain-wasm64.cmake +62 -0
- package/numkong/cmake/toolchain-x86_64-llvm.cmake +47 -0
- package/numkong/include/README.md +643 -0
- package/numkong/include/module.modulemap +129 -0
- package/numkong/include/numkong/attention/sapphireamx.h +1363 -0
- package/numkong/include/numkong/attention/sme.h +2075 -0
- package/numkong/include/numkong/attention.h +49 -0
- package/numkong/include/numkong/capabilities.h +930 -0
- package/numkong/include/numkong/cast/README.md +262 -0
- package/numkong/include/numkong/cast/diamond.h +64 -0
- package/numkong/include/numkong/cast/haswell.h +823 -0
- package/numkong/include/numkong/cast/icelake.h +475 -0
- package/numkong/include/numkong/cast/loongsonasx.h +252 -0
- package/numkong/include/numkong/cast/neon.h +1174 -0
- package/numkong/include/numkong/cast/powervsx.h +449 -0
- package/numkong/include/numkong/cast/rvv.h +970 -0
- package/numkong/include/numkong/cast/sapphire.h +262 -0
- package/numkong/include/numkong/cast/serial.h +2336 -0
- package/numkong/include/numkong/cast/skylake.h +915 -0
- package/numkong/include/numkong/cast/v128relaxed.h +537 -0
- package/numkong/include/numkong/cast.h +254 -0
- package/numkong/include/numkong/cast.hpp +44 -0
- package/numkong/include/numkong/curved/README.md +223 -0
- package/numkong/include/numkong/curved/genoa.h +182 -0
- package/numkong/include/numkong/curved/haswell.h +276 -0
- package/numkong/include/numkong/curved/neon.h +329 -0
- package/numkong/include/numkong/curved/neonbfdot.h +211 -0
- package/numkong/include/numkong/curved/rvv.h +305 -0
- package/numkong/include/numkong/curved/serial.h +207 -0
- package/numkong/include/numkong/curved/skylake.h +457 -0
- package/numkong/include/numkong/curved/smef64.h +530 -0
- package/numkong/include/numkong/curved.h +513 -0
- package/numkong/include/numkong/curved.hpp +144 -0
- package/numkong/include/numkong/dot/README.md +442 -0
- package/numkong/include/numkong/dot/alder.h +563 -0
- package/numkong/include/numkong/dot/diamond.h +158 -0
- package/numkong/include/numkong/dot/genoa.h +289 -0
- package/numkong/include/numkong/dot/haswell.h +1723 -0
- package/numkong/include/numkong/dot/icelake.h +997 -0
- package/numkong/include/numkong/dot/loongsonasx.h +671 -0
- package/numkong/include/numkong/dot/neon.h +869 -0
- package/numkong/include/numkong/dot/neonbfdot.h +243 -0
- package/numkong/include/numkong/dot/neonfhm.h +358 -0
- package/numkong/include/numkong/dot/neonfp8.h +323 -0
- package/numkong/include/numkong/dot/neonsdot.h +622 -0
- package/numkong/include/numkong/dot/powervsx.h +752 -0
- package/numkong/include/numkong/dot/rvv.h +722 -0
- package/numkong/include/numkong/dot/rvvbb.h +72 -0
- package/numkong/include/numkong/dot/rvvbf16.h +123 -0
- package/numkong/include/numkong/dot/rvvhalf.h +129 -0
- package/numkong/include/numkong/dot/sapphire.h +141 -0
- package/numkong/include/numkong/dot/serial.h +874 -0
- package/numkong/include/numkong/dot/sierra.h +405 -0
- package/numkong/include/numkong/dot/skylake.h +1116 -0
- package/numkong/include/numkong/dot/sve.h +420 -0
- package/numkong/include/numkong/dot/svebfdot.h +75 -0
- package/numkong/include/numkong/dot/svehalf.h +168 -0
- package/numkong/include/numkong/dot/svesdot.h +90 -0
- package/numkong/include/numkong/dot/v128relaxed.h +1293 -0
- package/numkong/include/numkong/dot.h +1136 -0
- package/numkong/include/numkong/dot.hpp +94 -0
- package/numkong/include/numkong/dots/README.md +496 -0
- package/numkong/include/numkong/dots/alder.h +117 -0
- package/numkong/include/numkong/dots/diamond.h +86 -0
- package/numkong/include/numkong/dots/genoa.h +100 -0
- package/numkong/include/numkong/dots/graniteamx.h +733 -0
- package/numkong/include/numkong/dots/haswell.h +310 -0
- package/numkong/include/numkong/dots/icelake.h +180 -0
- package/numkong/include/numkong/dots/loongsonasx.h +176 -0
- package/numkong/include/numkong/dots/neon.h +123 -0
- package/numkong/include/numkong/dots/neonbfdot.h +59 -0
- package/numkong/include/numkong/dots/neonfhm.h +96 -0
- package/numkong/include/numkong/dots/neonfp8.h +99 -0
- package/numkong/include/numkong/dots/neonsdot.h +144 -0
- package/numkong/include/numkong/dots/powervsx.h +194 -0
- package/numkong/include/numkong/dots/rvv.h +2593 -0
- package/numkong/include/numkong/dots/sapphireamx.h +4017 -0
- package/numkong/include/numkong/dots/serial.h +2867 -0
- package/numkong/include/numkong/dots/sierra.h +100 -0
- package/numkong/include/numkong/dots/skylake.h +207 -0
- package/numkong/include/numkong/dots/sme.h +5041 -0
- package/numkong/include/numkong/dots/smebi32.h +477 -0
- package/numkong/include/numkong/dots/smef64.h +1328 -0
- package/numkong/include/numkong/dots/smehalf.h +47 -0
- package/numkong/include/numkong/dots/v128relaxed.h +317 -0
- package/numkong/include/numkong/dots.h +3110 -0
- package/numkong/include/numkong/dots.hpp +641 -0
- package/numkong/include/numkong/each/README.md +465 -0
- package/numkong/include/numkong/each/haswell.h +1658 -0
- package/numkong/include/numkong/each/icelake.h +272 -0
- package/numkong/include/numkong/each/neon.h +1138 -0
- package/numkong/include/numkong/each/neonbfdot.h +211 -0
- package/numkong/include/numkong/each/neonhalf.h +318 -0
- package/numkong/include/numkong/each/rvv.h +1121 -0
- package/numkong/include/numkong/each/sapphire.h +343 -0
- package/numkong/include/numkong/each/serial.h +282 -0
- package/numkong/include/numkong/each/skylake.h +1562 -0
- package/numkong/include/numkong/each/v128relaxed.h +562 -0
- package/numkong/include/numkong/each.h +2232 -0
- package/numkong/include/numkong/each.hpp +434 -0
- package/numkong/include/numkong/geospatial/README.md +147 -0
- package/numkong/include/numkong/geospatial/haswell.h +633 -0
- package/numkong/include/numkong/geospatial/neon.h +615 -0
- package/numkong/include/numkong/geospatial/rvv.h +701 -0
- package/numkong/include/numkong/geospatial/serial.h +309 -0
- package/numkong/include/numkong/geospatial/skylake.h +613 -0
- package/numkong/include/numkong/geospatial/v128relaxed.h +652 -0
- package/numkong/include/numkong/geospatial.h +453 -0
- package/numkong/include/numkong/geospatial.hpp +235 -0
- package/numkong/include/numkong/matrix.hpp +336 -0
- package/numkong/include/numkong/maxsim/README.md +187 -0
- package/numkong/include/numkong/maxsim/alder.h +511 -0
- package/numkong/include/numkong/maxsim/genoa.h +115 -0
- package/numkong/include/numkong/maxsim/haswell.h +553 -0
- package/numkong/include/numkong/maxsim/icelake.h +480 -0
- package/numkong/include/numkong/maxsim/neonsdot.h +394 -0
- package/numkong/include/numkong/maxsim/sapphireamx.h +877 -0
- package/numkong/include/numkong/maxsim/serial.h +490 -0
- package/numkong/include/numkong/maxsim/sme.h +993 -0
- package/numkong/include/numkong/maxsim/v128relaxed.h +280 -0
- package/numkong/include/numkong/maxsim.h +571 -0
- package/numkong/include/numkong/maxsim.hpp +133 -0
- package/numkong/include/numkong/mesh/README.md +219 -0
- package/numkong/include/numkong/mesh/haswell.h +2013 -0
- package/numkong/include/numkong/mesh/neon.h +1821 -0
- package/numkong/include/numkong/mesh/neonbfdot.h +771 -0
- package/numkong/include/numkong/mesh/rvv.h +936 -0
- package/numkong/include/numkong/mesh/serial.h +721 -0
- package/numkong/include/numkong/mesh/skylake.h +2344 -0
- package/numkong/include/numkong/mesh/v128relaxed.h +1081 -0
- package/numkong/include/numkong/mesh.h +666 -0
- package/numkong/include/numkong/mesh.hpp +701 -0
- package/numkong/include/numkong/numkong.h +78 -0
- package/numkong/include/numkong/numkong.hpp +58 -0
- package/numkong/include/numkong/probability/README.md +177 -0
- package/numkong/include/numkong/probability/haswell.h +267 -0
- package/numkong/include/numkong/probability/neon.h +255 -0
- package/numkong/include/numkong/probability/rvv.h +414 -0
- package/numkong/include/numkong/probability/serial.h +181 -0
- package/numkong/include/numkong/probability/skylake.h +324 -0
- package/numkong/include/numkong/probability.h +380 -0
- package/numkong/include/numkong/probability.hpp +120 -0
- package/numkong/include/numkong/random.h +50 -0
- package/numkong/include/numkong/random.hpp +285 -0
- package/numkong/include/numkong/reduce/README.md +552 -0
- package/numkong/include/numkong/reduce/alder.h +636 -0
- package/numkong/include/numkong/reduce/genoa.h +201 -0
- package/numkong/include/numkong/reduce/haswell.h +3785 -0
- package/numkong/include/numkong/reduce/icelake.h +549 -0
- package/numkong/include/numkong/reduce/neon.h +3980 -0
- package/numkong/include/numkong/reduce/neonbfdot.h +142 -0
- package/numkong/include/numkong/reduce/neonfhm.h +293 -0
- package/numkong/include/numkong/reduce/neonsdot.h +357 -0
- package/numkong/include/numkong/reduce/rvv.h +3533 -0
- package/numkong/include/numkong/reduce/serial.h +753 -0
- package/numkong/include/numkong/reduce/sierra.h +338 -0
- package/numkong/include/numkong/reduce/skylake.h +3794 -0
- package/numkong/include/numkong/reduce/sve.h +52 -0
- package/numkong/include/numkong/reduce/v128relaxed.h +2302 -0
- package/numkong/include/numkong/reduce.h +1582 -0
- package/numkong/include/numkong/reduce.hpp +778 -0
- package/numkong/include/numkong/scalar/README.md +89 -0
- package/numkong/include/numkong/scalar/haswell.h +122 -0
- package/numkong/include/numkong/scalar/loongsonasx.h +74 -0
- package/numkong/include/numkong/scalar/neon.h +122 -0
- package/numkong/include/numkong/scalar/neonhalf.h +70 -0
- package/numkong/include/numkong/scalar/powervsx.h +96 -0
- package/numkong/include/numkong/scalar/rvv.h +211 -0
- package/numkong/include/numkong/scalar/sapphire.h +74 -0
- package/numkong/include/numkong/scalar/serial.h +332 -0
- package/numkong/include/numkong/scalar/v128relaxed.h +56 -0
- package/numkong/include/numkong/scalar.h +696 -0
- package/numkong/include/numkong/set/README.md +179 -0
- package/numkong/include/numkong/set/haswell.h +334 -0
- package/numkong/include/numkong/set/icelake.h +485 -0
- package/numkong/include/numkong/set/loongsonasx.h +181 -0
- package/numkong/include/numkong/set/neon.h +363 -0
- package/numkong/include/numkong/set/powervsx.h +326 -0
- package/numkong/include/numkong/set/rvv.h +226 -0
- package/numkong/include/numkong/set/rvvbb.h +117 -0
- package/numkong/include/numkong/set/serial.h +174 -0
- package/numkong/include/numkong/set/sve.h +187 -0
- package/numkong/include/numkong/set/v128relaxed.h +240 -0
- package/numkong/include/numkong/set.h +471 -0
- package/numkong/include/numkong/set.hpp +114 -0
- package/numkong/include/numkong/sets/README.md +149 -0
- package/numkong/include/numkong/sets/haswell.h +63 -0
- package/numkong/include/numkong/sets/icelake.h +66 -0
- package/numkong/include/numkong/sets/loongsonasx.h +52 -0
- package/numkong/include/numkong/sets/neon.h +61 -0
- package/numkong/include/numkong/sets/powervsx.h +65 -0
- package/numkong/include/numkong/sets/serial.h +43 -0
- package/numkong/include/numkong/sets/smebi32.h +1135 -0
- package/numkong/include/numkong/sets/v128relaxed.h +58 -0
- package/numkong/include/numkong/sets.h +382 -0
- package/numkong/include/numkong/sparse/README.md +156 -0
- package/numkong/include/numkong/sparse/icelake.h +463 -0
- package/numkong/include/numkong/sparse/neon.h +288 -0
- package/numkong/include/numkong/sparse/serial.h +117 -0
- package/numkong/include/numkong/sparse/sve2.h +504 -0
- package/numkong/include/numkong/sparse/turin.h +322 -0
- package/numkong/include/numkong/sparse.h +363 -0
- package/numkong/include/numkong/sparse.hpp +113 -0
- package/numkong/include/numkong/spatial/README.md +439 -0
- package/numkong/include/numkong/spatial/alder.h +604 -0
- package/numkong/include/numkong/spatial/diamond.h +240 -0
- package/numkong/include/numkong/spatial/genoa.h +222 -0
- package/numkong/include/numkong/spatial/haswell.h +979 -0
- package/numkong/include/numkong/spatial/icelake.h +1067 -0
- package/numkong/include/numkong/spatial/loongsonasx.h +483 -0
- package/numkong/include/numkong/spatial/neon.h +846 -0
- package/numkong/include/numkong/spatial/neonbfdot.h +164 -0
- package/numkong/include/numkong/spatial/neonfp8.h +258 -0
- package/numkong/include/numkong/spatial/neonsdot.h +429 -0
- package/numkong/include/numkong/spatial/powervsx.h +738 -0
- package/numkong/include/numkong/spatial/rvv.h +991 -0
- package/numkong/include/numkong/spatial/rvvbf16.h +128 -0
- package/numkong/include/numkong/spatial/rvvhalf.h +120 -0
- package/numkong/include/numkong/spatial/serial.h +347 -0
- package/numkong/include/numkong/spatial/sierra.h +516 -0
- package/numkong/include/numkong/spatial/skylake.h +605 -0
- package/numkong/include/numkong/spatial/sve.h +246 -0
- package/numkong/include/numkong/spatial/svebfdot.h +125 -0
- package/numkong/include/numkong/spatial/svehalf.h +136 -0
- package/numkong/include/numkong/spatial/svesdot.h +143 -0
- package/numkong/include/numkong/spatial/v128relaxed.h +969 -0
- package/numkong/include/numkong/spatial.h +1681 -0
- package/numkong/include/numkong/spatial.hpp +183 -0
- package/numkong/include/numkong/spatials/README.md +580 -0
- package/numkong/include/numkong/spatials/alder.h +94 -0
- package/numkong/include/numkong/spatials/diamond.h +82 -0
- package/numkong/include/numkong/spatials/genoa.h +94 -0
- package/numkong/include/numkong/spatials/graniteamx.h +173 -0
- package/numkong/include/numkong/spatials/haswell.h +219 -0
- package/numkong/include/numkong/spatials/icelake.h +113 -0
- package/numkong/include/numkong/spatials/loongsonasx.h +153 -0
- package/numkong/include/numkong/spatials/neon.h +109 -0
- package/numkong/include/numkong/spatials/neonbfdot.h +60 -0
- package/numkong/include/numkong/spatials/neonfhm.h +92 -0
- package/numkong/include/numkong/spatials/neonfp8.h +111 -0
- package/numkong/include/numkong/spatials/neonsdot.h +143 -0
- package/numkong/include/numkong/spatials/powervsx.h +153 -0
- package/numkong/include/numkong/spatials/rvv.h +1976 -0
- package/numkong/include/numkong/spatials/sapphireamx.h +1149 -0
- package/numkong/include/numkong/spatials/serial.h +248 -0
- package/numkong/include/numkong/spatials/sierra.h +96 -0
- package/numkong/include/numkong/spatials/skylake.h +184 -0
- package/numkong/include/numkong/spatials/sme.h +1927 -0
- package/numkong/include/numkong/spatials/smef64.h +483 -0
- package/numkong/include/numkong/spatials/v128relaxed.h +240 -0
- package/numkong/include/numkong/spatials.h +3374 -0
- package/numkong/include/numkong/spatials.hpp +509 -0
- package/numkong/include/numkong/tensor.hpp +1981 -0
- package/numkong/include/numkong/trigonometry/README.md +184 -0
- package/numkong/include/numkong/trigonometry/haswell.h +653 -0
- package/numkong/include/numkong/trigonometry/neon.h +638 -0
- package/numkong/include/numkong/trigonometry/rvv.h +700 -0
- package/numkong/include/numkong/trigonometry/serial.h +703 -0
- package/numkong/include/numkong/trigonometry/skylake.h +725 -0
- package/numkong/include/numkong/trigonometry/v128relaxed.h +667 -0
- package/numkong/include/numkong/trigonometry.h +467 -0
- package/numkong/include/numkong/trigonometry.hpp +166 -0
- package/numkong/include/numkong/types.h +1695 -0
- package/numkong/include/numkong/types.hpp +6027 -0
- package/numkong/include/numkong/vector.hpp +766 -0
- package/numkong/javascript/@numkong-darwin-arm64/package.json +26 -0
- package/numkong/javascript/@numkong-darwin-x64/package.json +26 -0
- package/numkong/javascript/@numkong-linux-arm64/package.json +25 -0
- package/numkong/javascript/@numkong-linux-x64/package.json +25 -0
- package/numkong/javascript/@numkong-win32-arm64/package.json +25 -0
- package/numkong/javascript/@numkong-win32-x64/package.json +25 -0
- package/numkong/javascript/README.md +254 -0
- package/numkong/javascript/node-gyp-build.d.ts +4 -0
- package/numkong/javascript/numkong-browser.ts +40 -0
- package/numkong/javascript/numkong-wasm.ts +750 -0
- package/numkong/javascript/numkong.c +712 -0
- package/numkong/javascript/numkong.ts +613 -0
- package/{simsimd → numkong}/javascript/tsconfig-base.json +6 -3
- package/numkong/javascript/tsconfig-cjs.json +13 -0
- package/{simsimd → numkong}/javascript/tsconfig-esm.json +1 -1
- package/numkong/javascript/types.ts +784 -0
- package/numkong/numkong.gypi +104 -0
- package/numkong/package.json +108 -0
- package/numkong/probes/arm_neon.c +8 -0
- package/numkong/probes/arm_neon_bfdot.c +9 -0
- package/numkong/probes/arm_neon_fhm.c +9 -0
- package/numkong/probes/arm_neon_half.c +8 -0
- package/numkong/probes/arm_neon_sdot.c +9 -0
- package/numkong/probes/arm_neonfp8.c +9 -0
- package/numkong/probes/arm_sme.c +16 -0
- package/numkong/probes/arm_sme2.c +16 -0
- package/numkong/probes/arm_sme2p1.c +16 -0
- package/numkong/probes/arm_sme_bf16.c +16 -0
- package/numkong/probes/arm_sme_bi32.c +16 -0
- package/numkong/probes/arm_sme_f64.c +16 -0
- package/numkong/probes/arm_sme_fa64.c +14 -0
- package/numkong/probes/arm_sme_half.c +16 -0
- package/numkong/probes/arm_sme_lut2.c +15 -0
- package/numkong/probes/arm_sve.c +18 -0
- package/numkong/probes/arm_sve2.c +20 -0
- package/numkong/probes/arm_sve2p1.c +18 -0
- package/numkong/probes/arm_sve_bfdot.c +20 -0
- package/numkong/probes/arm_sve_half.c +18 -0
- package/numkong/probes/arm_sve_sdot.c +21 -0
- package/numkong/probes/loongarch_lasx.c +12 -0
- package/numkong/probes/power_vsx.c +12 -0
- package/numkong/probes/probe.js +127 -0
- package/numkong/probes/riscv_rvv.c +14 -0
- package/numkong/probes/riscv_rvv_bb.c +15 -0
- package/numkong/probes/riscv_rvv_bf16.c +17 -0
- package/numkong/probes/riscv_rvv_half.c +14 -0
- package/numkong/probes/wasm_v128relaxed.c +11 -0
- package/numkong/probes/x86_alder.c +17 -0
- package/numkong/probes/x86_diamond.c +17 -0
- package/numkong/probes/x86_genoa.c +17 -0
- package/numkong/probes/x86_graniteamx.c +19 -0
- package/numkong/probes/x86_haswell.c +11 -0
- package/numkong/probes/x86_icelake.c +17 -0
- package/numkong/probes/x86_sapphire.c +16 -0
- package/numkong/probes/x86_sapphireamx.c +18 -0
- package/numkong/probes/x86_sierra.c +17 -0
- package/numkong/probes/x86_skylake.c +15 -0
- package/numkong/probes/x86_turin.c +17 -0
- package/numkong/rust/README.md +698 -0
- package/numkong/rust/capabilities.rs +96 -0
- package/numkong/rust/cast.rs +314 -0
- package/numkong/rust/curved.rs +391 -0
- package/numkong/rust/each.rs +2721 -0
- package/numkong/rust/geospatial.rs +343 -0
- package/numkong/rust/matrix.rs +5424 -0
- package/numkong/rust/maxsim.rs +540 -0
- package/numkong/rust/mesh.rs +837 -0
- package/numkong/rust/numkong.rs +409 -0
- package/numkong/rust/probability.rs +272 -0
- package/numkong/rust/reduce.rs +1249 -0
- package/numkong/rust/set.rs +194 -0
- package/numkong/rust/sparse.rs +513 -0
- package/numkong/rust/spatial.rs +1815 -0
- package/numkong/rust/tensor.rs +7565 -0
- package/numkong/rust/types.rs +3666 -0
- package/numkong/rust/vector.rs +1899 -0
- package/numkong/rustfmt.toml +2 -0
- package/numkong/swift/Matrix.swift +1388 -0
- package/numkong/swift/MaxSim.swift +151 -0
- package/numkong/swift/NumKong.swift +283 -0
- package/numkong/swift/Numerics.swift +329 -0
- package/numkong/swift/README.md +433 -0
- package/numkong/swift/Scalar.swift +741 -0
- package/numkong/swift/Tensor.swift +209 -0
- package/numkong/test/README.md +315 -0
- package/numkong/test/playwright.config.ts +16 -0
- package/numkong/test/swift/Test.swift +534 -0
- package/numkong/test/test-browser-bundle-runner.mjs +36 -0
- package/numkong/test/test-browser-bundle.html +188 -0
- package/numkong/test/test-browser-runner.mjs +43 -0
- package/numkong/test/test-browser.html +305 -0
- package/numkong/test/test-dtypes.mjs +453 -0
- package/numkong/test/test-wasm.mjs +267 -0
- package/numkong/test/test.cpp +442 -0
- package/numkong/test/test.hpp +580 -0
- package/numkong/test/test.mjs +363 -0
- package/numkong/test/test_base.py +1041 -0
- package/numkong/test/test_cast.cpp +242 -0
- package/numkong/test/test_cross.hpp +551 -0
- package/numkong/test/test_cross.py +467 -0
- package/numkong/test/test_cross_amx.cpp +50 -0
- package/numkong/test/test_cross_arm.cpp +225 -0
- package/numkong/test/test_cross_blas.cpp +354 -0
- package/numkong/test/test_cross_loongarch.cpp +90 -0
- package/numkong/test/test_cross_power.cpp +73 -0
- package/numkong/test/test_cross_rvv.cpp +109 -0
- package/numkong/test/test_cross_serial.cpp +181 -0
- package/numkong/test/test_cross_sme.cpp +148 -0
- package/numkong/test/test_cross_wasm.cpp +141 -0
- package/numkong/test/test_cross_x86.cpp +442 -0
- package/numkong/test/test_curved.cpp +182 -0
- package/numkong/test/test_curved.py +207 -0
- package/numkong/test/test_dot.cpp +353 -0
- package/numkong/test/test_dot.py +296 -0
- package/numkong/test/test_each.cpp +437 -0
- package/numkong/test/test_each.py +756 -0
- package/numkong/test/test_geospatial.cpp +155 -0
- package/numkong/test/test_geospatial.py +241 -0
- package/numkong/test/test_maxsim.cpp +138 -0
- package/numkong/test/test_maxsim.py +209 -0
- package/numkong/test/test_mesh.cpp +203 -0
- package/numkong/test/test_mesh.py +394 -0
- package/numkong/test/test_probability.cpp +136 -0
- package/numkong/test/test_probability.py +166 -0
- package/numkong/test/test_reduce.cpp +563 -0
- package/numkong/test/test_reduce.py +781 -0
- package/numkong/test/test_set.cpp +151 -0
- package/numkong/test/test_set.py +120 -0
- package/numkong/test/test_similarities.py +579 -0
- package/numkong/test/test_sparse.cpp +121 -0
- package/numkong/test/test_sparse.py +118 -0
- package/numkong/test/test_spatial.cpp +518 -0
- package/numkong/test/test_spatial.py +269 -0
- package/numkong/test/test_tensor.cpp +884 -0
- package/numkong/test/test_tensor.py +1417 -0
- package/numkong/test/test_trigonometry.cpp +156 -0
- package/numkong/test/test_trigonometry.py +180 -0
- package/package.json +7 -8
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/fp16/CMakeLists.txt +0 -176
- package/fp16/LICENSE +0 -11
- package/fp16/README.md +0 -20
- package/fp16/bench/alt-element.cc +0 -89
- package/fp16/bench/from-alt-array.cc +0 -175
- package/fp16/bench/from-ieee-array.cc +0 -399
- package/fp16/bench/ieee-element.cc +0 -272
- package/fp16/bench/to-alt-array.cc +0 -91
- package/fp16/bench/to-ieee-array.cc +0 -303
- package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
- package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
- package/fp16/cmake/DownloadPSimd.cmake +0 -15
- package/fp16/configure.py +0 -65
- package/fp16/confu.yaml +0 -8
- package/fp16/include/fp16/__init__.py +0 -0
- package/fp16/include/fp16/avx.py +0 -50
- package/fp16/include/fp16/avx2.py +0 -53
- package/fp16/include/fp16/bitcasts.h +0 -92
- package/fp16/include/fp16/fp16.h +0 -451
- package/fp16/include/fp16/psimd.h +0 -131
- package/fp16/include/fp16.h +0 -11
- package/fp16/jni/Android.mk +0 -6
- package/fp16/jni/Application.mk +0 -4
- package/fp16/test/alt-from-fp32-value.cc +0 -498
- package/fp16/test/alt-to-fp32-bits.cc +0 -263
- package/fp16/test/alt-to-fp32-psimd.cc +0 -145
- package/fp16/test/alt-to-fp32-value.cc +0 -348
- package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
- package/fp16/test/bitcasts.cc +0 -56
- package/fp16/test/ieee-from-fp32-value.cc +0 -523
- package/fp16/test/ieee-to-fp32-bits.cc +0 -333
- package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
- package/fp16/test/ieee-to-fp32-value.cc +0 -420
- package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
- package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
- package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
- package/fp16/test/peachpy/stubs.py +0 -38
- package/fp16/test/tables.cc +0 -530
- package/fp16/test/tables.h +0 -13
- package/fp16/third-party/THHalf.h +0 -92
- package/fp16/third-party/eigen-half.h +0 -170
- package/fp16/third-party/float16-compressor.h +0 -80
- package/fp16/third-party/half.hpp +0 -2916
- package/fp16/third-party/npy-halffloat.h +0 -328
- package/simsimd/.git-blame-ignore-revs +0 -2
- package/simsimd/CONTRIBUTING.md +0 -321
- package/simsimd/Cargo.toml +0 -49
- package/simsimd/MANIFEST.in +0 -4
- package/simsimd/Package.swift +0 -28
- package/simsimd/README.md +0 -1493
- package/simsimd/binding.gyp +0 -35
- package/simsimd/build.rs +0 -70
- package/simsimd/c/lib.c +0 -374
- package/simsimd/include/module.modulemap +0 -4
- package/simsimd/include/simsimd/binary.h +0 -486
- package/simsimd/include/simsimd/curved.h +0 -1541
- package/simsimd/include/simsimd/dot.h +0 -1853
- package/simsimd/include/simsimd/elementwise.h +0 -2465
- package/simsimd/include/simsimd/geospatial.h +0 -43
- package/simsimd/include/simsimd/mesh.h +0 -69
- package/simsimd/include/simsimd/probability.h +0 -606
- package/simsimd/include/simsimd/simsimd.h +0 -2567
- package/simsimd/include/simsimd/sparse.h +0 -1384
- package/simsimd/include/simsimd/spatial.h +0 -2335
- package/simsimd/include/simsimd/types.h +0 -666
- package/simsimd/javascript/fallback.ts +0 -233
- package/simsimd/javascript/lib.c +0 -125
- package/simsimd/javascript/node-gyp-build.d.ts +0 -1
- package/simsimd/javascript/simsimd.ts +0 -179
- package/simsimd/javascript/tsconfig-cjs.json +0 -8
- package/simsimd/package-lock.json +0 -1761
- package/simsimd/package.json +0 -61
- package/simsimd/rust/lib.rs +0 -1821
- package/simsimd/scripts/bench.cxx +0 -1170
- package/simsimd/scripts/bench.ipynb +0 -187
- package/simsimd/scripts/bench.js +0 -127
- package/simsimd/scripts/bench.rs +0 -876
- package/simsimd/scripts/bench_vectors.py +0 -734
- package/simsimd/scripts/bench_vectors_live.py +0 -213
- package/simsimd/scripts/test.c +0 -187
- package/simsimd/scripts/test.mjs +0 -220
- package/simsimd/scripts/test.py +0 -1505
- package/simsimd/swift/SimSIMD.swift +0 -149
- package/simsimd/swift/Test.swift +0 -128
- /package/{simsimd → numkong}/CODE_OF_CONDUCT.md +0 -0
- /package/{simsimd → numkong}/LICENSE +0 -0
- /package/{simsimd → numkong}/javascript/dist-package-cjs.json +0 -0
- /package/{simsimd → numkong}/javascript/dist-package-esm.json +0 -0
|
@@ -1,666 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file types.h
|
|
3
|
-
* @brief Shared definitions for the SimSIMD library.
|
|
4
|
-
* @author Ash Vardanian
|
|
5
|
-
* @date October 2, 2023
|
|
6
|
-
*
|
|
7
|
-
* Defines:
|
|
8
|
-
* - Sized aliases for numeric types, like: `simsimd_i32_t` and `simsimd_f64_t`.
|
|
9
|
-
* - Macros for internal compiler/hardware checks, like: `_SIMSIMD_TARGET_ARM`.
|
|
10
|
-
* - Macros for feature controls, like: `SIMSIMD_TARGET_NEON`
|
|
11
|
-
*/
|
|
12
|
-
#ifndef SIMSIMD_TYPES_H
|
|
13
|
-
#define SIMSIMD_TYPES_H
|
|
14
|
-
|
|
15
|
-
// Inferring target OS: Windows, macOS, or Linux
|
|
16
|
-
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
|
17
|
-
#define _SIMSIMD_DEFINED_WINDOWS 1
|
|
18
|
-
#elif defined(__APPLE__) && defined(__MACH__)
|
|
19
|
-
#define _SIMSIMD_DEFINED_APPLE 1
|
|
20
|
-
#elif defined(__linux__)
|
|
21
|
-
#define _SIMSIMD_DEFINED_LINUX 1
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
|
-
// Annotation for the public API symbols:
|
|
25
|
-
//
|
|
26
|
-
// - `SIMSIMD_PUBLIC` is used for functions that are part of the public API.
|
|
27
|
-
// - `SIMSIMD_INTERNAL` is used for internal helper functions with unstable APIs.
|
|
28
|
-
// - `SIMSIMD_DYNAMIC` is used for functions that are part of the public API, but are dispatched at runtime.
|
|
29
|
-
//
|
|
30
|
-
// On GCC we mark the functions as `nonnull` informing that none of the arguments can be `NULL`.
|
|
31
|
-
// Marking with `pure` and `const` isn't possible as outputting to a pointer is a "side effect".
|
|
32
|
-
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
33
|
-
#define SIMSIMD_DYNAMIC __declspec(dllexport)
|
|
34
|
-
#define SIMSIMD_PUBLIC inline static
|
|
35
|
-
#define SIMSIMD_INTERNAL inline static
|
|
36
|
-
#elif defined(__GNUC__) || defined(__clang__)
|
|
37
|
-
#define SIMSIMD_DYNAMIC __attribute__((visibility("default"))) __attribute__((nonnull))
|
|
38
|
-
#define SIMSIMD_PUBLIC __attribute__((unused, nonnull)) inline static
|
|
39
|
-
#define SIMSIMD_INTERNAL __attribute__((always_inline)) inline static
|
|
40
|
-
#else
|
|
41
|
-
#define SIMSIMD_DYNAMIC
|
|
42
|
-
#define SIMSIMD_PUBLIC inline static
|
|
43
|
-
#define SIMSIMD_INTERNAL inline static
|
|
44
|
-
#endif
|
|
45
|
-
|
|
46
|
-
// Compiling for Arm: _SIMSIMD_TARGET_ARM
|
|
47
|
-
#if !defined(_SIMSIMD_TARGET_ARM)
|
|
48
|
-
#if defined(__aarch64__) || defined(_M_ARM64)
|
|
49
|
-
#define _SIMSIMD_TARGET_ARM 1
|
|
50
|
-
#else
|
|
51
|
-
#define _SIMSIMD_TARGET_ARM 0
|
|
52
|
-
#endif // defined(__aarch64__) || defined(_M_ARM64)
|
|
53
|
-
#endif // !defined(_SIMSIMD_TARGET_ARM)
|
|
54
|
-
|
|
55
|
-
// Compiling for x86: _SIMSIMD_TARGET_X86
|
|
56
|
-
#if !defined(_SIMSIMD_TARGET_X86)
|
|
57
|
-
#if defined(__x86_64__) || defined(_M_X64)
|
|
58
|
-
#define _SIMSIMD_TARGET_X86 1
|
|
59
|
-
#else
|
|
60
|
-
#define _SIMSIMD_TARGET_X86 0
|
|
61
|
-
#endif // defined(__x86_64__) || defined(_M_X64)
|
|
62
|
-
#endif // !defined(_SIMSIMD_TARGET_X86)
|
|
63
|
-
|
|
64
|
-
// Compiling for Arm: SIMSIMD_TARGET_NEON
|
|
65
|
-
#if !defined(SIMSIMD_TARGET_NEON) || (SIMSIMD_TARGET_NEON && !_SIMSIMD_TARGET_ARM)
|
|
66
|
-
#if defined(__ARM_NEON)
|
|
67
|
-
#define SIMSIMD_TARGET_NEON _SIMSIMD_TARGET_ARM
|
|
68
|
-
#else
|
|
69
|
-
#undef SIMSIMD_TARGET_NEON
|
|
70
|
-
#define SIMSIMD_TARGET_NEON 0
|
|
71
|
-
#endif // defined(__ARM_NEON)
|
|
72
|
-
#endif // !defined(SIMSIMD_TARGET_NEON) || ...
|
|
73
|
-
|
|
74
|
-
// Compiling for Arm: SIMSIMD_TARGET_NEON_I8
|
|
75
|
-
#if !defined(SIMSIMD_TARGET_NEON_I8) || (SIMSIMD_TARGET_NEON_I8 && !_SIMSIMD_TARGET_ARM)
|
|
76
|
-
#if defined(__ARM_NEON)
|
|
77
|
-
#define SIMSIMD_TARGET_NEON_I8 _SIMSIMD_TARGET_ARM
|
|
78
|
-
#else
|
|
79
|
-
#undef SIMSIMD_TARGET_NEON_I8
|
|
80
|
-
#define SIMSIMD_TARGET_NEON_I8 0
|
|
81
|
-
#endif // defined(__ARM_NEON)
|
|
82
|
-
#endif // !defined(SIMSIMD_TARGET_NEON_I8) || ...
|
|
83
|
-
|
|
84
|
-
// Compiling for Arm: SIMSIMD_TARGET_NEON_F16
|
|
85
|
-
#if !defined(SIMSIMD_TARGET_NEON_F16) || (SIMSIMD_TARGET_NEON_F16 && !_SIMSIMD_TARGET_ARM)
|
|
86
|
-
#if defined(__ARM_NEON)
|
|
87
|
-
#define SIMSIMD_TARGET_NEON_F16 _SIMSIMD_TARGET_ARM
|
|
88
|
-
#else
|
|
89
|
-
#undef SIMSIMD_TARGET_NEON_F16
|
|
90
|
-
#define SIMSIMD_TARGET_NEON_F16 0
|
|
91
|
-
#endif // defined(__ARM_NEON)
|
|
92
|
-
#endif // !defined(SIMSIMD_TARGET_NEON_F16) || ...
|
|
93
|
-
|
|
94
|
-
// Compiling for Arm: SIMSIMD_TARGET_NEON_BF16
|
|
95
|
-
#if !defined(SIMSIMD_TARGET_NEON_BF16) || (SIMSIMD_TARGET_NEON_BF16 && !_SIMSIMD_TARGET_ARM)
|
|
96
|
-
#if defined(__ARM_NEON)
|
|
97
|
-
#define SIMSIMD_TARGET_NEON_BF16 _SIMSIMD_TARGET_ARM
|
|
98
|
-
#else
|
|
99
|
-
#undef SIMSIMD_TARGET_NEON_BF16
|
|
100
|
-
#define SIMSIMD_TARGET_NEON_BF16 0
|
|
101
|
-
#endif // defined(__ARM_NEON)
|
|
102
|
-
#endif // !defined(SIMSIMD_TARGET_NEON_BF16) || ...
|
|
103
|
-
|
|
104
|
-
// Compiling for Arm: SIMSIMD_TARGET_SVE
|
|
105
|
-
#if !defined(SIMSIMD_TARGET_SVE) || (SIMSIMD_TARGET_SVE && !_SIMSIMD_TARGET_ARM)
|
|
106
|
-
#if defined(__ARM_FEATURE_SVE)
|
|
107
|
-
#define SIMSIMD_TARGET_SVE _SIMSIMD_TARGET_ARM
|
|
108
|
-
#else
|
|
109
|
-
#undef SIMSIMD_TARGET_SVE
|
|
110
|
-
#define SIMSIMD_TARGET_SVE 0
|
|
111
|
-
#endif // defined(__ARM_FEATURE_SVE)
|
|
112
|
-
#endif // !defined(SIMSIMD_TARGET_SVE) || ...
|
|
113
|
-
|
|
114
|
-
// Compiling for Arm: SIMSIMD_TARGET_SVE_I8
|
|
115
|
-
#if !defined(SIMSIMD_TARGET_SVE_I8) || (SIMSIMD_TARGET_SVE_I8 && !_SIMSIMD_TARGET_ARM)
|
|
116
|
-
#if defined(__ARM_FEATURE_SVE)
|
|
117
|
-
#define SIMSIMD_TARGET_SVE_I8 _SIMSIMD_TARGET_ARM
|
|
118
|
-
#else
|
|
119
|
-
#undef SIMSIMD_TARGET_SVE_I8
|
|
120
|
-
#define SIMSIMD_TARGET_SVE_I8 0
|
|
121
|
-
#endif // defined(__ARM_FEATURE_SVE)
|
|
122
|
-
#endif // !defined(SIMSIMD_TARGET_SVE_I8) || ...
|
|
123
|
-
|
|
124
|
-
// Compiling for Arm: SIMSIMD_TARGET_SVE_F16
|
|
125
|
-
#if !defined(SIMSIMD_TARGET_SVE_F16) || (SIMSIMD_TARGET_SVE_F16 && !_SIMSIMD_TARGET_ARM)
|
|
126
|
-
#if defined(__ARM_FEATURE_SVE)
|
|
127
|
-
#define SIMSIMD_TARGET_SVE_F16 _SIMSIMD_TARGET_ARM
|
|
128
|
-
#else
|
|
129
|
-
#undef SIMSIMD_TARGET_SVE_F16
|
|
130
|
-
#define SIMSIMD_TARGET_SVE_F16 0
|
|
131
|
-
#endif // defined(__ARM_FEATURE_SVE)
|
|
132
|
-
#endif // !defined(SIMSIMD_TARGET_SVE_F16) || ...
|
|
133
|
-
|
|
134
|
-
// Compiling for Arm: SIMSIMD_TARGET_SVE_BF16
|
|
135
|
-
#if !defined(SIMSIMD_TARGET_SVE_BF16) || (SIMSIMD_TARGET_SVE_BF16 && !_SIMSIMD_TARGET_ARM)
|
|
136
|
-
#if defined(__ARM_FEATURE_SVE)
|
|
137
|
-
#define SIMSIMD_TARGET_SVE_BF16 _SIMSIMD_TARGET_ARM
|
|
138
|
-
#else
|
|
139
|
-
#undef SIMSIMD_TARGET_SVE_BF16
|
|
140
|
-
#define SIMSIMD_TARGET_SVE_BF16 0
|
|
141
|
-
#endif // defined(__ARM_FEATURE_SVE)
|
|
142
|
-
#endif // !defined(SIMSIMD_TARGET_SVE_BF16) || ...
|
|
143
|
-
|
|
144
|
-
// Compiling for Arm: SIMSIMD_TARGET_SVE2
|
|
145
|
-
#if !defined(SIMSIMD_TARGET_SVE2) || (SIMSIMD_TARGET_SVE2 && !_SIMSIMD_TARGET_ARM)
|
|
146
|
-
#if defined(__ARM_FEATURE_SVE)
|
|
147
|
-
#define SIMSIMD_TARGET_SVE2 _SIMSIMD_TARGET_ARM
|
|
148
|
-
#else
|
|
149
|
-
#undef SIMSIMD_TARGET_SVE2
|
|
150
|
-
#define SIMSIMD_TARGET_SVE2 0
|
|
151
|
-
#endif // defined(__ARM_FEATURE_SVE)
|
|
152
|
-
#endif // !defined(SIMSIMD_TARGET_SVE2) || ...
|
|
153
|
-
|
|
154
|
-
// Compiling for x86: SIMSIMD_TARGET_HASWELL
|
|
155
|
-
//
|
|
156
|
-
// Starting with Ivy Bridge, Intel supports the `F16C` extensions for fast half-precision
|
|
157
|
-
// to single-precision floating-point conversions. On AMD those instructions
|
|
158
|
-
// are supported on all CPUs starting with Jaguar 2009.
|
|
159
|
-
// Starting with Sandy Bridge, Intel adds basic AVX support in their CPUs and in 2013
|
|
160
|
-
// extends it with AVX2 in the Haswell generation. Moreover, Haswell adds FMA support.
|
|
161
|
-
#if !defined(SIMSIMD_TARGET_HASWELL) || (SIMSIMD_TARGET_HASWELL && !_SIMSIMD_TARGET_X86)
|
|
162
|
-
#if defined(__AVX2__) && defined(__FMA__) && defined(__F16C__)
|
|
163
|
-
#define SIMSIMD_TARGET_HASWELL 1
|
|
164
|
-
#else
|
|
165
|
-
#undef SIMSIMD_TARGET_HASWELL
|
|
166
|
-
#define SIMSIMD_TARGET_HASWELL 0
|
|
167
|
-
#endif // defined(__AVX2__)
|
|
168
|
-
#endif // !defined(SIMSIMD_TARGET_HASWELL) || ...
|
|
169
|
-
|
|
170
|
-
// Compiling for x86: SIMSIMD_TARGET_SKYLAKE, SIMSIMD_TARGET_ICE, SIMSIMD_TARGET_GENOA,
|
|
171
|
-
// SIMSIMD_TARGET_SAPPHIRE, SIMSIMD_TARGET_TURIN, SIMSIMD_TARGET_SIERRA
|
|
172
|
-
//
|
|
173
|
-
// To list all available macros for x86, take a recent compiler, like GCC 12 and run:
|
|
174
|
-
// gcc-12 -march=sapphirerapids -dM -E - < /dev/null | egrep "SSE|AVX" | sort
|
|
175
|
-
// On Arm machines you may want to check for other flags:
|
|
176
|
-
// gcc-12 -march=native -dM -E - < /dev/null | egrep "NEON|SVE|FP16|FMA" | sort
|
|
177
|
-
#if !defined(SIMSIMD_TARGET_SKYLAKE) || (SIMSIMD_TARGET_SKYLAKE && !_SIMSIMD_TARGET_X86)
|
|
178
|
-
#if defined(__AVX512F__) && defined(__AVX512CD__) && defined(__AVX512VL__) && defined(__AVX512DQ__) && \
|
|
179
|
-
defined(__AVX512BW__)
|
|
180
|
-
#define SIMSIMD_TARGET_SKYLAKE 1
|
|
181
|
-
#else
|
|
182
|
-
#undef SIMSIMD_TARGET_SKYLAKE
|
|
183
|
-
#define SIMSIMD_TARGET_SKYLAKE 0
|
|
184
|
-
#endif
|
|
185
|
-
#endif // !defined(SIMSIMD_TARGET_SKYLAKE) || ...
|
|
186
|
-
#if !defined(SIMSIMD_TARGET_ICE) || (SIMSIMD_TARGET_ICE && !_SIMSIMD_TARGET_X86)
|
|
187
|
-
#if defined(__AVX512VNNI__) && defined(__AVX512IFMA__) && defined(__AVX512BITALG__) && defined(__AVX512VBMI2__) && \
|
|
188
|
-
defined(__AVX512VPOPCNTDQ__)
|
|
189
|
-
#define SIMSIMD_TARGET_ICE 1
|
|
190
|
-
#else
|
|
191
|
-
#undef SIMSIMD_TARGET_ICE
|
|
192
|
-
#define SIMSIMD_TARGET_ICE 0
|
|
193
|
-
#endif
|
|
194
|
-
#endif // !defined(SIMSIMD_TARGET_ICE) || ...
|
|
195
|
-
#if !defined(SIMSIMD_TARGET_GENOA) || (SIMSIMD_TARGET_GENOA && !_SIMSIMD_TARGET_X86)
|
|
196
|
-
#if defined(__AVX512BF16__)
|
|
197
|
-
#define SIMSIMD_TARGET_GENOA 1
|
|
198
|
-
#else
|
|
199
|
-
#undef SIMSIMD_TARGET_GENOA
|
|
200
|
-
#define SIMSIMD_TARGET_GENOA 0
|
|
201
|
-
#endif
|
|
202
|
-
#endif // !defined(SIMSIMD_TARGET_GENOA) || ...
|
|
203
|
-
#if !defined(SIMSIMD_TARGET_SAPPHIRE) || (SIMSIMD_TARGET_SAPPHIRE && !_SIMSIMD_TARGET_X86)
|
|
204
|
-
#if defined(__AVX512FP16__)
|
|
205
|
-
#define SIMSIMD_TARGET_SAPPHIRE 1
|
|
206
|
-
#else
|
|
207
|
-
#undef SIMSIMD_TARGET_SAPPHIRE
|
|
208
|
-
#define SIMSIMD_TARGET_SAPPHIRE 0
|
|
209
|
-
#endif
|
|
210
|
-
#endif // !defined(SIMSIMD_TARGET_SAPPHIRE) || ...
|
|
211
|
-
#if !defined(SIMSIMD_TARGET_TURIN) || (SIMSIMD_TARGET_TURIN && !_SIMSIMD_TARGET_X86)
|
|
212
|
-
#if defined(__AVX512VP2INTERSECT__)
|
|
213
|
-
#define SIMSIMD_TARGET_TURIN 1
|
|
214
|
-
#else
|
|
215
|
-
#undef SIMSIMD_TARGET_TURIN
|
|
216
|
-
#define SIMSIMD_TARGET_TURIN 0
|
|
217
|
-
#endif
|
|
218
|
-
#endif // !defined(SIMSIMD_TARGET_TURIN) || ...
|
|
219
|
-
#if !defined(SIMSIMD_TARGET_SIERRA) || (SIMSIMD_TARGET_SIERRA && !_SIMSIMD_TARGET_X86)
|
|
220
|
-
#if defined(__AVX2_VNNI__)
|
|
221
|
-
#define SIMSIMD_TARGET_SIERRA 1
|
|
222
|
-
#else
|
|
223
|
-
#undef SIMSIMD_TARGET_SIERRA
|
|
224
|
-
#define SIMSIMD_TARGET_SIERRA 0
|
|
225
|
-
#endif
|
|
226
|
-
#endif // !defined(SIMSIMD_TARGET_SIERRA) || ...
|
|
227
|
-
|
|
228
|
-
#if defined(_MSC_VER)
|
|
229
|
-
#include <intrin.h>
|
|
230
|
-
#else
|
|
231
|
-
|
|
232
|
-
#if SIMSIMD_TARGET_NEON
|
|
233
|
-
#include <arm_neon.h>
|
|
234
|
-
#endif
|
|
235
|
-
|
|
236
|
-
#if SIMSIMD_TARGET_SVE || SIMSIMD_TARGET_SVE2
|
|
237
|
-
#include <arm_sve.h>
|
|
238
|
-
#endif
|
|
239
|
-
|
|
240
|
-
#if SIMSIMD_TARGET_HASWELL || SIMSIMD_TARGET_SKYLAKE || SIMSIMD_TARGET_ICE || SIMSIMD_TARGET_GENOA || \
|
|
241
|
-
SIMSIMD_TARGET_SAPPHIRE || SIMSIMD_TARGET_TURIN
|
|
242
|
-
#include <immintrin.h>
|
|
243
|
-
#endif
|
|
244
|
-
|
|
245
|
-
#endif
|
|
246
|
-
|
|
247
|
-
#if !defined(SIMSIMD_SQRT)
|
|
248
|
-
#include <math.h>
|
|
249
|
-
#define SIMSIMD_SQRT(x) (sqrt(x))
|
|
250
|
-
#endif
|
|
251
|
-
|
|
252
|
-
#if !defined(SIMSIMD_RSQRT)
|
|
253
|
-
#include <math.h>
|
|
254
|
-
#define SIMSIMD_RSQRT(x) (1 / SIMSIMD_SQRT(x))
|
|
255
|
-
#endif
|
|
256
|
-
|
|
257
|
-
#if !defined(SIMSIMD_LOG)
|
|
258
|
-
#include <math.h>
|
|
259
|
-
#define SIMSIMD_LOG(x) (log(x))
|
|
260
|
-
#endif
|
|
261
|
-
|
|
262
|
-
// Copy 16 bits (2 bytes) from source to destination
|
|
263
|
-
#if defined(__GNUC__) || defined(__clang__)
|
|
264
|
-
#define SIMSIMD_COPY16(destination_ptr, source_ptr) __builtin_memcpy((destination_ptr), (source_ptr), 2)
|
|
265
|
-
#else
|
|
266
|
-
#include <string.h> /* fallback for exotic compilers */
|
|
267
|
-
#define SIMSIMD_COPY16(destination_ptr, source_ptr) memcpy((destination_ptr), (source_ptr), 2)
|
|
268
|
-
#endif
|
|
269
|
-
|
|
270
|
-
#if !defined(SIMSIMD_F32_DIVISION_EPSILON)
|
|
271
|
-
#define SIMSIMD_F32_DIVISION_EPSILON (1e-7)
|
|
272
|
-
#endif
|
|
273
|
-
|
|
274
|
-
#if !defined(SIMSIMD_F16_DIVISION_EPSILON)
|
|
275
|
-
#define SIMSIMD_F16_DIVISION_EPSILON (1e-3)
|
|
276
|
-
#endif
|
|
277
|
-
|
|
278
|
-
#ifdef __cplusplus
|
|
279
|
-
extern "C" {
|
|
280
|
-
#endif
|
|
281
|
-
|
|
282
|
-
typedef unsigned char simsimd_b8_t;
|
|
283
|
-
typedef unsigned char simsimd_i4x2_t;
|
|
284
|
-
|
|
285
|
-
typedef signed char simsimd_i8_t;
|
|
286
|
-
typedef unsigned char simsimd_u8_t;
|
|
287
|
-
typedef signed short simsimd_i16_t;
|
|
288
|
-
typedef unsigned short simsimd_u16_t;
|
|
289
|
-
typedef signed int simsimd_i32_t;
|
|
290
|
-
typedef unsigned int simsimd_u32_t;
|
|
291
|
-
typedef signed long long simsimd_i64_t;
|
|
292
|
-
typedef unsigned long long simsimd_u64_t;
|
|
293
|
-
|
|
294
|
-
typedef float simsimd_f32_t;
|
|
295
|
-
typedef double simsimd_f64_t;
|
|
296
|
-
|
|
297
|
-
typedef simsimd_u64_t simsimd_size_t;
|
|
298
|
-
typedef simsimd_f64_t simsimd_distance_t;
|
|
299
|
-
|
|
300
|
-
/* @brief Half-precision floating-point type.
|
|
301
|
-
*
|
|
302
|
-
* - GCC or Clang on 64-bit Arm: `__fp16`, may require `-mfp16-format` option.
|
|
303
|
-
* - GCC or Clang on 64-bit x86: `_Float16`.
|
|
304
|
-
* - Default: `unsigned short`.
|
|
305
|
-
*/
|
|
306
|
-
#if !defined(SIMSIMD_NATIVE_F16) || SIMSIMD_NATIVE_F16
|
|
307
|
-
#if (defined(__GNUC__) || defined(__clang__)) && (defined(__ARM_ARCH) || defined(__aarch64__)) && \
|
|
308
|
-
(defined(__ARM_FP16_FORMAT_IEEE))
|
|
309
|
-
#undef SIMSIMD_NATIVE_F16
|
|
310
|
-
#define SIMSIMD_NATIVE_F16 1
|
|
311
|
-
typedef __fp16 simsimd_f16_t;
|
|
312
|
-
#elif ((defined(__GNUC__) || defined(__clang__)) && (defined(__x86_64__) || defined(__i386__)) && \
|
|
313
|
-
(defined(__AVX512FP16__)))
|
|
314
|
-
typedef _Float16 simsimd_f16_t;
|
|
315
|
-
#undef SIMSIMD_NATIVE_F16
|
|
316
|
-
#define SIMSIMD_NATIVE_F16 1
|
|
317
|
-
#else // Unknown compiler or architecture
|
|
318
|
-
#if defined(__GNUC__) || defined(__clang__) // Some compilers don't support warning pragmas
|
|
319
|
-
#warning "Unknown compiler or architecture for float16."
|
|
320
|
-
#endif
|
|
321
|
-
#undef SIMSIMD_NATIVE_F16
|
|
322
|
-
#define SIMSIMD_NATIVE_F16 0
|
|
323
|
-
#endif // Unknown compiler or architecture
|
|
324
|
-
#endif // !SIMSIMD_NATIVE_F16
|
|
325
|
-
|
|
326
|
-
#if !SIMSIMD_NATIVE_F16
|
|
327
|
-
typedef unsigned short simsimd_f16_t;
|
|
328
|
-
#endif
|
|
329
|
-
|
|
330
|
-
#if !defined(SIMSIMD_NATIVE_BF16) || SIMSIMD_NATIVE_BF16
|
|
331
|
-
/**
|
|
332
|
-
* @brief Half-precision brain-float type.
|
|
333
|
-
*
|
|
334
|
-
* - GCC or Clang on 64-bit Arm: `__bf16`
|
|
335
|
-
* - GCC or Clang on 64-bit x86: `_BFloat16`.
|
|
336
|
-
* - Default: `unsigned short`.
|
|
337
|
-
*
|
|
338
|
-
* The compilers have added `__bf16` support in compliance with the x86-64 psABI spec.
|
|
339
|
-
* The motivation for this new special type is summed up as:
|
|
340
|
-
*
|
|
341
|
-
* Currently `__bfloat16` is a typedef of short, which creates a problem where the
|
|
342
|
-
* compiler does not raise any alarms if it is used to add, subtract, multiply or
|
|
343
|
-
* divide, but the result of the calculation is actually meaningless.
|
|
344
|
-
* To solve this problem, a real scalar type `__Bfloat16` needs to be introduced.
|
|
345
|
-
* It is mainly used for intrinsics, not available for C standard operators.
|
|
346
|
-
* `__Bfloat16` will also be used for movement like passing parameter, load and store,
|
|
347
|
-
* vector initialization, vector shuffle, and etc. It creates a need for a
|
|
348
|
-
* corresponding psABI.
|
|
349
|
-
*
|
|
350
|
-
* @warning Apple Clang has hard time with bf16.
|
|
351
|
-
* https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms
|
|
352
|
-
* https://forums.developer.apple.com/forums/thread/726201
|
|
353
|
-
* https://www.phoronix.com/news/GCC-LLVM-bf16-BFloat16-Type
|
|
354
|
-
*/
|
|
355
|
-
#if (defined(__GNUC__) || defined(__clang__)) && (defined(__ARM_ARCH) || defined(__aarch64__)) && \
|
|
356
|
-
(defined(__ARM_BF16_FORMAT_ALTERNATIVE))
|
|
357
|
-
#undef SIMSIMD_NATIVE_BF16
|
|
358
|
-
#define SIMSIMD_NATIVE_BF16 1
|
|
359
|
-
typedef __bf16 simsimd_bf16_t;
|
|
360
|
-
#elif ((defined(__GNUC__) || defined(__clang__)) && (defined(__x86_64__) || defined(__i386__)) && \
|
|
361
|
-
(defined(__AVX512BF16__)))
|
|
362
|
-
typedef __bfloat16 simsimd_bf16_t;
|
|
363
|
-
#undef SIMSIMD_NATIVE_BF16
|
|
364
|
-
#define SIMSIMD_NATIVE_BF16 1
|
|
365
|
-
#else // Unknown compiler or architecture
|
|
366
|
-
#if defined(__GNUC__) || defined(__clang__) // Some compilers don't support warning pragmas
|
|
367
|
-
#warning "Unknown compiler or architecture for bfloat16."
|
|
368
|
-
#endif
|
|
369
|
-
#undef SIMSIMD_NATIVE_BF16
|
|
370
|
-
#define SIMSIMD_NATIVE_BF16 0
|
|
371
|
-
#endif // Unknown compiler or architecture
|
|
372
|
-
#endif // !SIMSIMD_NATIVE_BF16
|
|
373
|
-
|
|
374
|
-
#if !SIMSIMD_NATIVE_BF16
|
|
375
|
-
typedef unsigned short simsimd_bf16_t;
|
|
376
|
-
#endif
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* @brief Alias for the half-precision floating-point type on Arm.
|
|
380
|
-
*
|
|
381
|
-
* Clang and GCC bring the `float16_t` symbol when you compile for Aarch64.
|
|
382
|
-
* MSVC lacks it, and it's `vld1_f16`-like intrinsics are in reality macros,
|
|
383
|
-
* that cast to 16-bit integers internally, instead of using floats.
|
|
384
|
-
* Some of those are defined as aliases, so we use `#define` preprocessor
|
|
385
|
-
* directives instead of `typedef` to avoid errors.
|
|
386
|
-
*/
|
|
387
|
-
#if _SIMSIMD_TARGET_ARM
|
|
388
|
-
#if defined(_MSC_VER)
|
|
389
|
-
#define simsimd_f16_for_arm_simd_t simsimd_f16_t
|
|
390
|
-
#define simsimd_bf16_for_arm_simd_t simsimd_bf16_t
|
|
391
|
-
#else
|
|
392
|
-
#define simsimd_f16_for_arm_simd_t float16_t
|
|
393
|
-
#define simsimd_bf16_for_arm_simd_t bfloat16_t
|
|
394
|
-
#endif
|
|
395
|
-
#endif
|
|
396
|
-
|
|
397
|
-
/*
|
|
398
|
-
* Let's make sure the sizes of the types are as expected.
|
|
399
|
-
* In C the `_Static_assert` is only available with C11 and later.
|
|
400
|
-
*/
|
|
401
|
-
#define SIMSIMD_STATIC_ASSERT(cond, msg) typedef char static_assertion_##msg[(cond) ? 1 : -1]
|
|
402
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_b8_t) == 1, simsimd_b8_t_must_be_1_byte);
|
|
403
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_i4x2_t) == 1, simsimd_i4x2_t_must_be_1_byte);
|
|
404
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_i8_t) == 1, simsimd_i8_t_must_be_1_byte);
|
|
405
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_u8_t) == 1, simsimd_u8_t_must_be_1_byte);
|
|
406
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_i16_t) == 2, simsimd_i16_t_must_be_2_bytes);
|
|
407
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_u16_t) == 2, simsimd_u16_t_must_be_2_bytes);
|
|
408
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_i32_t) == 4, simsimd_i32_t_must_be_4_bytes);
|
|
409
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_u32_t) == 4, simsimd_u32_t_must_be_4_bytes);
|
|
410
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_i64_t) == 8, simsimd_i64_t_must_be_8_bytes);
|
|
411
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_u64_t) == 8, simsimd_u64_t_must_be_8_bytes);
|
|
412
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_f32_t) == 4, simsimd_f32_t_must_be_4_bytes);
|
|
413
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_f64_t) == 8, simsimd_f64_t_must_be_8_bytes);
|
|
414
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_f16_t) == 2, simsimd_f16_t_must_be_2_bytes);
|
|
415
|
-
SIMSIMD_STATIC_ASSERT(sizeof(simsimd_bf16_t) == 2, simsimd_bf16_t_must_be_2_bytes);
|
|
416
|
-
|
|
417
|
-
#define SIMSIMD_DEREFERENCE(x) (*(x))
|
|
418
|
-
#define SIMSIMD_EXPORT(x, y) *(y) = x
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* @brief Returns the value of the half-precision floating-point number,
|
|
422
|
-
* potentially decompressed into single-precision.
|
|
423
|
-
*/
|
|
424
|
-
#if !defined(SIMSIMD_F16_TO_F32)
|
|
425
|
-
#if SIMSIMD_NATIVE_F16
|
|
426
|
-
#define SIMSIMD_F16_TO_F32(x) (SIMSIMD_DEREFERENCE(x))
|
|
427
|
-
#define SIMSIMD_F32_TO_F16(x, y) (SIMSIMD_EXPORT(x, y))
|
|
428
|
-
#else
|
|
429
|
-
#define SIMSIMD_F16_TO_F32(x) (simsimd_f16_to_f32(x))
|
|
430
|
-
#define SIMSIMD_F32_TO_F16(x, y) (simsimd_f32_to_f16(x, y))
|
|
431
|
-
#endif
|
|
432
|
-
#endif
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* @brief Returns the value of the half-precision brain floating-point number,
|
|
436
|
-
* potentially decompressed into single-precision.
|
|
437
|
-
*/
|
|
438
|
-
#if !defined(SIMSIMD_BF16_TO_F32)
|
|
439
|
-
#if SIMSIMD_NATIVE_BF16
|
|
440
|
-
#define SIMSIMD_BF16_TO_F32(x) (SIMSIMD_DEREFERENCE(x))
|
|
441
|
-
#define SIMSIMD_F32_TO_BF16(x, y) (SIMSIMD_EXPORT(x, y))
|
|
442
|
-
#else
|
|
443
|
-
#define SIMSIMD_BF16_TO_F32(x) (simsimd_bf16_to_f32(x))
|
|
444
|
-
#define SIMSIMD_F32_TO_BF16(x, y) (simsimd_f32_to_bf16(x, y))
|
|
445
|
-
#endif
|
|
446
|
-
#endif
|
|
447
|
-
|
|
448
|
-
#if !defined(SIMSIMD_F32_TO_I8)
|
|
449
|
-
#define SIMSIMD_F32_TO_I8(x, y) \
|
|
450
|
-
*(y) = (simsimd_i8_t)((x) > 127 ? 127 : ((x) < -128 ? -128 : (int)((x) + ((x) < 0 ? -0.5f : 0.5f))))
|
|
451
|
-
#endif
|
|
452
|
-
#if !defined(SIMSIMD_F32_TO_U8)
|
|
453
|
-
#define SIMSIMD_F32_TO_U8(x, y) \
|
|
454
|
-
*(y) = (simsimd_u8_t)((x) > 255 ? 255 : ((x) < 0 ? 0 : (int)((x) + ((x) < 0 ? -0.5f : 0.5f))))
|
|
455
|
-
#endif
|
|
456
|
-
#if !defined(SIMSIMD_F64_TO_I8)
|
|
457
|
-
#define SIMSIMD_F64_TO_I8(x, y) \
|
|
458
|
-
*(y) = (simsimd_i8_t)((x) > 127 ? 127 : ((x) < -128 ? -128 : (int)((x) + ((x) < 0 ? -0.5 : 0.5))))
|
|
459
|
-
#endif
|
|
460
|
-
#if !defined(SIMSIMD_F64_TO_U8)
|
|
461
|
-
#define SIMSIMD_F64_TO_U8(x, y) \
|
|
462
|
-
*(y) = (simsimd_u8_t)((x) > 255 ? 255 : ((x) < 0 ? 0 : (int)((x) + ((x) < 0 ? -0.5 : 0.5))))
|
|
463
|
-
#endif
|
|
464
|
-
|
|
465
|
-
/** @brief Convenience type for half-precision floating-point type conversions. */
|
|
466
|
-
typedef union {
|
|
467
|
-
unsigned i;
|
|
468
|
-
float f;
|
|
469
|
-
} simsimd_f32i32_t;
|
|
470
|
-
|
|
471
|
-
/** @brief Convenience type addressing the real and imaginary parts of a half-precision complex number. */
|
|
472
|
-
typedef struct {
|
|
473
|
-
simsimd_f16_t real;
|
|
474
|
-
simsimd_f16_t imag;
|
|
475
|
-
} simsimd_f16c_t;
|
|
476
|
-
|
|
477
|
-
/** @brief Convenience type addressing the real and imaginary parts of a half-precision brain-float complex number. */
|
|
478
|
-
typedef struct {
|
|
479
|
-
simsimd_bf16_t real;
|
|
480
|
-
simsimd_bf16_t imag;
|
|
481
|
-
} simsimd_bf16c_t;
|
|
482
|
-
|
|
483
|
-
/** @brief Convenience type addressing the real and imaginary parts of a single-precision complex number. */
|
|
484
|
-
typedef struct {
|
|
485
|
-
simsimd_f32_t real;
|
|
486
|
-
simsimd_f32_t imag;
|
|
487
|
-
} simsimd_f32c_t;
|
|
488
|
-
|
|
489
|
-
/** @brief Convenience type addressing the real and imaginary parts of a double-precision complex number. */
|
|
490
|
-
typedef struct {
|
|
491
|
-
simsimd_f64_t real;
|
|
492
|
-
simsimd_f64_t imag;
|
|
493
|
-
} simsimd_f64c_t;
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* @brief Computes `1/sqrt(x)` using the trick from Quake 3,
|
|
497
|
-
* replacing the magic numbers with the ones suggested by Jan Kadlec.
|
|
498
|
-
*
|
|
499
|
-
* Subsequent additions by hardware manufacturers have made this algorithm redundant for the most part.
|
|
500
|
-
* For example, on x86, Intel introduced the SSE instruction `rsqrtss` in 1999. In a 2009 benchmark on
|
|
501
|
-
* the Intel Core 2, this instruction took 0.85ns per float compared to 3.54ns for the fast inverse
|
|
502
|
-
* square root algorithm, and had less error. Carmack's Magic Number `rsqrt` had an average error
|
|
503
|
-
* of 0.0990%, while SSE `rsqrtss` had 0.0094%, a 10x improvement.
|
|
504
|
-
*
|
|
505
|
-
* https://web.archive.org/web/20210208132927/http://assemblyrequired.crashworks.org/timing-square-root/
|
|
506
|
-
* https://stackoverflow.com/a/41460625/2766161
|
|
507
|
-
*/
|
|
508
|
-
SIMSIMD_INTERNAL simsimd_f32_t simsimd_approximate_inverse_square_root(simsimd_f32_t number) {
|
|
509
|
-
simsimd_f32i32_t conv;
|
|
510
|
-
conv.f = number;
|
|
511
|
-
conv.i = 0x5F1FFFF9 - (conv.i >> 1);
|
|
512
|
-
// Refine using a Newton-Raphson step for better accuracy
|
|
513
|
-
conv.f *= 0.703952253f * (2.38924456f - number * conv.f * conv.f);
|
|
514
|
-
return conv.f;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* @brief Approximates `sqrt(x)` using the fast inverse square root trick
|
|
519
|
-
* with adjustments for direct square root approximation.
|
|
520
|
-
*
|
|
521
|
-
* Similar to `rsqrt` approximation but multiplies by `number` to get `sqrt`.
|
|
522
|
-
* This technique is useful where `sqrt` approximation is needed in performance-critical code,
|
|
523
|
-
* though modern hardware provides optimized alternatives.
|
|
524
|
-
*/
|
|
525
|
-
SIMSIMD_INTERNAL simsimd_f32_t simsimd_approximate_square_root(simsimd_f32_t number) {
|
|
526
|
-
return number * simsimd_approximate_inverse_square_root(number);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* @brief Computes `log(x)` using the Mercator series.
|
|
531
|
-
* The series converges to the natural logarithm for args between -1 and 1.
|
|
532
|
-
* Published in 1668 in "Logarithmotechnia".
|
|
533
|
-
*/
|
|
534
|
-
SIMSIMD_INTERNAL simsimd_f32_t simsimd_approximate_log(simsimd_f32_t number) {
|
|
535
|
-
simsimd_f32_t x = number - 1;
|
|
536
|
-
simsimd_f32_t x2 = x * x;
|
|
537
|
-
simsimd_f32_t x3 = x * x * x;
|
|
538
|
-
return x - x2 / 2 + x3 / 3;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* @brief For compilers that don't natively support the `_Float16` type,
|
|
543
|
-
* upcasts contents into a more conventional `float`.
|
|
544
|
-
*
|
|
545
|
-
* @warning This function won't handle boundary conditions well.
|
|
546
|
-
*
|
|
547
|
-
* https://stackoverflow.com/a/60047308
|
|
548
|
-
* https://gist.github.com/milhidaka/95863906fe828198f47991c813dbe233
|
|
549
|
-
* https://github.com/OpenCyphal/libcanard/blob/636795f4bc395f56af8d2c61d3757b5e762bb9e5/canard.c#L811-L834
|
|
550
|
-
*/
|
|
551
|
-
SIMSIMD_INTERNAL simsimd_f32_t simsimd_f16_to_f32_implementation(simsimd_f16_t const *x_ptr) {
|
|
552
|
-
unsigned short x;
|
|
553
|
-
SIMSIMD_COPY16(&x, x_ptr);
|
|
554
|
-
unsigned int exponent = (x & 0x7C00) >> 10;
|
|
555
|
-
unsigned int mantissa = (x & 0x03FF) << 13;
|
|
556
|
-
simsimd_f32i32_t mantissa_conv;
|
|
557
|
-
mantissa_conv.f = (float)mantissa;
|
|
558
|
-
unsigned int v = (mantissa_conv.i) >> 23;
|
|
559
|
-
simsimd_f32i32_t conv;
|
|
560
|
-
conv.i = (x & 0x8000) << 16 | (exponent != 0) * ((exponent + 112) << 23 | mantissa) |
|
|
561
|
-
((exponent == 0) & (mantissa != 0)) * ((v - 37) << 23 | ((mantissa << (150 - v)) & 0x007FE000));
|
|
562
|
-
return conv.f;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* @brief Compresses a `float` to an `f16` representation (IEEE-754 16-bit floating-point format).
|
|
567
|
-
*
|
|
568
|
-
* @warning This function won't handle boundary conditions well.
|
|
569
|
-
*
|
|
570
|
-
* https://stackoverflow.com/a/60047308
|
|
571
|
-
* https://gist.github.com/milhidaka/95863906fe828198f47991c813dbe233
|
|
572
|
-
* https://github.com/OpenCyphal/libcanard/blob/636795f4bc395f56af8d2c61d3757b5e762bb9e5/canard.c#L811-L834
|
|
573
|
-
*/
|
|
574
|
-
SIMSIMD_INTERNAL void simsimd_f32_to_f16_implementation(simsimd_f32_t x, simsimd_f16_t *result_ptr) {
|
|
575
|
-
simsimd_f32i32_t conv;
|
|
576
|
-
conv.f = x;
|
|
577
|
-
unsigned int b = conv.i + 0x00001000;
|
|
578
|
-
unsigned int e = (b & 0x7F800000) >> 23;
|
|
579
|
-
unsigned int m = b & 0x007FFFFF;
|
|
580
|
-
unsigned short result = ((b & 0x80000000) >> 16) | (e > 112) * ((((e - 112) << 10) & 0x7C00) | (m >> 13)) |
|
|
581
|
-
((e < 113) & (e > 101)) * ((((0x007FF000 + m) >> (125 - e)) + 1) >> 1) |
|
|
582
|
-
((e > 143) * 0x7FFF);
|
|
583
|
-
SIMSIMD_COPY16(result_ptr, &result);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* @brief For compilers that don't natively support the `__bf16` type,
|
|
588
|
-
* upcasts contents into a more conventional `float`.
|
|
589
|
-
*
|
|
590
|
-
* https://stackoverflow.com/questions/55253233/convert-fp32-to-bfloat16-in-c/55254307#55254307
|
|
591
|
-
* https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus
|
|
592
|
-
*/
|
|
593
|
-
SIMSIMD_INTERNAL simsimd_f32_t simsimd_bf16_to_f32_implementation(simsimd_bf16_t const *x_ptr) {
|
|
594
|
-
unsigned short x;
|
|
595
|
-
SIMSIMD_COPY16(&x, x_ptr);
|
|
596
|
-
simsimd_f32i32_t conv;
|
|
597
|
-
conv.i = x << 16; // Zero extends the mantissa
|
|
598
|
-
return conv.f;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* @brief Compresses a `float` to a `bf16` representation.
|
|
603
|
-
*
|
|
604
|
-
* https://stackoverflow.com/questions/55253233/convert-fp32-to-bfloat16-in-c/55254307#55254307
|
|
605
|
-
* https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus
|
|
606
|
-
*/
|
|
607
|
-
SIMSIMD_INTERNAL void simsimd_f32_to_bf16_implementation(simsimd_f32_t x, simsimd_bf16_t *result_ptr) {
|
|
608
|
-
simsimd_f32i32_t conv;
|
|
609
|
-
conv.f = x;
|
|
610
|
-
conv.i += 0x8000; // Rounding is optional
|
|
611
|
-
conv.i >>= 16;
|
|
612
|
-
// The top 16 bits will be zeroed out anyways
|
|
613
|
-
// conv.i &= 0xFFFF;
|
|
614
|
-
SIMSIMD_COPY16(result_ptr, &conv.i);
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
SIMSIMD_INTERNAL simsimd_u32_t simsimd_u32_rol(simsimd_u32_t x, int n) { return (x << n) | (x >> (32 - n)); }
|
|
618
|
-
SIMSIMD_INTERNAL simsimd_u16_t simsimd_u16_rol(simsimd_u16_t x, int n) { return (x << n) | (x >> (16 - n)); }
|
|
619
|
-
SIMSIMD_INTERNAL simsimd_u8_t simsimd_u8_rol(simsimd_u8_t x, int n) { return (x << n) | (x >> (8 - n)); }
|
|
620
|
-
SIMSIMD_INTERNAL simsimd_u32_t simsimd_u32_ror(simsimd_u32_t x, int n) { return (x >> n) | (x << (32 - n)); }
|
|
621
|
-
SIMSIMD_INTERNAL simsimd_u16_t simsimd_u16_ror(simsimd_u16_t x, int n) { return (x >> n) | (x << (16 - n)); }
|
|
622
|
-
SIMSIMD_INTERNAL simsimd_u8_t simsimd_u8_ror(simsimd_u8_t x, int n) { return (x >> n) | (x << (8 - n)); }
|
|
623
|
-
|
|
624
|
-
#if SIMSIMD_DYNAMIC_DISPATCH
|
|
625
|
-
|
|
626
|
-
/** @copydoc simsimd_f16_to_f32_implementation */
|
|
627
|
-
SIMSIMD_DYNAMIC simsimd_f32_t simsimd_f16_to_f32(simsimd_f16_t const *x_ptr);
|
|
628
|
-
|
|
629
|
-
/** @copydoc simsimd_f32_to_f16_implementation */
|
|
630
|
-
SIMSIMD_DYNAMIC void simsimd_f32_to_f16(simsimd_f32_t x, simsimd_f16_t *result_ptr);
|
|
631
|
-
|
|
632
|
-
/** @copydoc simsimd_bf16_to_f32_implementation */
|
|
633
|
-
SIMSIMD_DYNAMIC simsimd_f32_t simsimd_bf16_to_f32(simsimd_bf16_t const *x_ptr);
|
|
634
|
-
|
|
635
|
-
/** @copydoc simsimd_f32_to_bf16_implementation */
|
|
636
|
-
SIMSIMD_DYNAMIC void simsimd_f32_to_bf16(simsimd_f32_t x, simsimd_bf16_t *result_ptr);
|
|
637
|
-
|
|
638
|
-
#else // SIMSIMD_DYNAMIC_DISPATCH
|
|
639
|
-
|
|
640
|
-
/** @copydoc simsimd_f16_to_f32_implementation */
|
|
641
|
-
SIMSIMD_PUBLIC simsimd_f32_t simsimd_f16_to_f32(simsimd_f16_t const *x_ptr) {
|
|
642
|
-
return simsimd_f16_to_f32_implementation(x_ptr);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/** @copydoc simsimd_f32_to_f16_implementation */
|
|
646
|
-
SIMSIMD_PUBLIC void simsimd_f32_to_f16(simsimd_f32_t x, simsimd_f16_t *result_ptr) {
|
|
647
|
-
simsimd_f32_to_f16_implementation(x, result_ptr);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/** @copydoc simsimd_bf16_to_f32_implementation */
|
|
651
|
-
SIMSIMD_PUBLIC simsimd_f32_t simsimd_bf16_to_f32(simsimd_bf16_t const *x_ptr) {
|
|
652
|
-
return simsimd_bf16_to_f32_implementation(x_ptr);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/** @copydoc simsimd_f32_to_bf16_implementation */
|
|
656
|
-
SIMSIMD_PUBLIC void simsimd_f32_to_bf16(simsimd_f32_t x, simsimd_bf16_t *result_ptr) {
|
|
657
|
-
simsimd_f32_to_bf16_implementation(x, result_ptr);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
#endif // SIMSIMD_DYNAMIC_DISPATCH
|
|
661
|
-
|
|
662
|
-
#ifdef __cplusplus
|
|
663
|
-
} // extern "C"
|
|
664
|
-
#endif
|
|
665
|
-
|
|
666
|
-
#endif
|