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
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief SIMD-accelerated Geospatial Distances for WASM.
|
|
3
|
+
* @file include/numkong/geospatial/v128relaxed.h
|
|
4
|
+
* @author Ash Vardanian
|
|
5
|
+
* @date February 6, 2026
|
|
6
|
+
*
|
|
7
|
+
* @sa include/numkong/geospatial.h
|
|
8
|
+
*
|
|
9
|
+
* Implements Haversine and Vincenty great-circle distances for f32x4 and f64x2.
|
|
10
|
+
* Haversine uses sin/cos/atan2 with min/max clamping to keep the atan2 argument in [0,1].
|
|
11
|
+
* Vincenty iterates sin/cos/atan2 until convergence, using `i8x16_all_true` to test whether
|
|
12
|
+
* all SIMD lanes have converged without per-lane extraction.
|
|
13
|
+
*
|
|
14
|
+
* @section geospatial_wasm_instructions Key WASM SIMD Instructions (beyond trig)
|
|
15
|
+
*
|
|
16
|
+
* Intrinsic Operation
|
|
17
|
+
* wasm_f32x4_sqrt(a) Square root (4-way f32)
|
|
18
|
+
* wasm_f64x2_sqrt(a) Square root (2-way f64)
|
|
19
|
+
* wasm_f32x4_div(a, b) Division (4-way f32)
|
|
20
|
+
* wasm_f64x2_div(a, b) Division (2-way f64)
|
|
21
|
+
* wasm_f32x4_min/max(a, b) Clamping for Haversine
|
|
22
|
+
* wasm_f64x2_min/max(a, b) Clamping for Haversine
|
|
23
|
+
* wasm_f32x4_relaxed_min/max(a, b) Min/max without NaN fixup (1 vs 6-9 on x86)
|
|
24
|
+
* wasm_f64x2_relaxed_min/max(a, b) Min/max without NaN fixup (1 vs 6-9 on x86)
|
|
25
|
+
* wasm_i32x4_relaxed_laneselect(a, b, m) Lane select (1 instr vs 3 on x86)
|
|
26
|
+
* wasm_i64x2_relaxed_laneselect(a, b, m) Lane select for f64 masks
|
|
27
|
+
* wasm_i8x16_all_true(a) Vincenty convergence check (all lanes at once)
|
|
28
|
+
*/
|
|
29
|
+
#ifndef NK_GEOSPATIAL_V128RELAXED_H
|
|
30
|
+
#define NK_GEOSPATIAL_V128RELAXED_H
|
|
31
|
+
|
|
32
|
+
#if NK_TARGET_V128RELAXED
|
|
33
|
+
|
|
34
|
+
#include "numkong/types.h"
|
|
35
|
+
#include "numkong/trigonometry/v128relaxed.h"
|
|
36
|
+
|
|
37
|
+
#if defined(__cplusplus)
|
|
38
|
+
extern "C" {
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#if defined(__clang__)
|
|
42
|
+
#pragma clang attribute push(__attribute__((target("relaxed-simd"))), apply_to = function)
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
/* WASM Relaxed SIMD implementations using 2-wide f64 and 4-wide f32 SIMD.
|
|
46
|
+
* These require WASM trigonometric kernels from trigonometry/v128relaxed.h.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
NK_INTERNAL v128_t nk_haversine_f64x2_v128relaxed_( //
|
|
50
|
+
v128_t first_latitudes_f64x2, v128_t first_longitudes_f64x2, //
|
|
51
|
+
v128_t second_latitudes_f64x2, v128_t second_longitudes_f64x2) {
|
|
52
|
+
|
|
53
|
+
v128_t const earth_radius_f64x2 = wasm_f64x2_splat(NK_EARTH_MEDIATORIAL_RADIUS);
|
|
54
|
+
v128_t const half_f64x2 = wasm_f64x2_splat(0.5);
|
|
55
|
+
v128_t const one_f64x2 = wasm_f64x2_splat(1.0);
|
|
56
|
+
v128_t const two_f64x2 = wasm_f64x2_splat(2.0);
|
|
57
|
+
|
|
58
|
+
v128_t latitude_delta_f64x2 = wasm_f64x2_sub(second_latitudes_f64x2, first_latitudes_f64x2);
|
|
59
|
+
v128_t longitude_delta_f64x2 = wasm_f64x2_sub(second_longitudes_f64x2, first_longitudes_f64x2);
|
|
60
|
+
|
|
61
|
+
// Haversine terms: sin^2(delta/2)
|
|
62
|
+
v128_t latitude_delta_half_f64x2 = wasm_f64x2_mul(latitude_delta_f64x2, half_f64x2);
|
|
63
|
+
v128_t longitude_delta_half_f64x2 = wasm_f64x2_mul(longitude_delta_f64x2, half_f64x2);
|
|
64
|
+
v128_t sin_latitude_delta_half_f64x2 = nk_f64x2_sin_v128relaxed_(latitude_delta_half_f64x2);
|
|
65
|
+
v128_t sin_longitude_delta_half_f64x2 = nk_f64x2_sin_v128relaxed_(longitude_delta_half_f64x2);
|
|
66
|
+
v128_t sin_squared_latitude_delta_half_f64x2 = wasm_f64x2_mul(sin_latitude_delta_half_f64x2,
|
|
67
|
+
sin_latitude_delta_half_f64x2);
|
|
68
|
+
v128_t sin_squared_longitude_delta_half_f64x2 = wasm_f64x2_mul(sin_longitude_delta_half_f64x2,
|
|
69
|
+
sin_longitude_delta_half_f64x2);
|
|
70
|
+
|
|
71
|
+
// Latitude cosine product
|
|
72
|
+
v128_t cos_first_latitude_f64x2 = nk_f64x2_cos_v128relaxed_(first_latitudes_f64x2);
|
|
73
|
+
v128_t cos_second_latitude_f64x2 = nk_f64x2_cos_v128relaxed_(second_latitudes_f64x2);
|
|
74
|
+
v128_t cos_latitude_product_f64x2 = wasm_f64x2_mul(cos_first_latitude_f64x2, cos_second_latitude_f64x2);
|
|
75
|
+
|
|
76
|
+
// a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlon/2)
|
|
77
|
+
v128_t haversine_term_f64x2 = wasm_f64x2_add(
|
|
78
|
+
sin_squared_latitude_delta_half_f64x2,
|
|
79
|
+
wasm_f64x2_mul(cos_latitude_product_f64x2, sin_squared_longitude_delta_half_f64x2));
|
|
80
|
+
// Clamp haversine_term_f64x2 to [0, 1] to prevent NaN from sqrt of negative values
|
|
81
|
+
// relaxed_min/max: 1 instruction (minpd/maxpd) vs 6-9 (with NaN/signed-zero_f64x2 fixup) on x86.
|
|
82
|
+
// Safe because haversine_term_f64x2 is a product of finite sin/cos values — NaN is impossible.
|
|
83
|
+
v128_t zero_f64x2 = wasm_f64x2_splat(0.0);
|
|
84
|
+
haversine_term_f64x2 = wasm_f64x2_relaxed_max(zero_f64x2, wasm_f64x2_relaxed_min(one_f64x2, haversine_term_f64x2));
|
|
85
|
+
|
|
86
|
+
// Central angle: c = 2 * atan2(sqrt(a), sqrt(1-a))
|
|
87
|
+
v128_t sqrt_haversine_f64x2 = wasm_f64x2_sqrt(haversine_term_f64x2);
|
|
88
|
+
v128_t sqrt_complement_f64x2 = wasm_f64x2_sqrt(wasm_f64x2_sub(one_f64x2, haversine_term_f64x2));
|
|
89
|
+
v128_t central_angle_f64x2 = wasm_f64x2_mul(
|
|
90
|
+
two_f64x2, nk_f64x2_atan2_v128relaxed_(sqrt_haversine_f64x2, sqrt_complement_f64x2));
|
|
91
|
+
|
|
92
|
+
return wasm_f64x2_mul(earth_radius_f64x2, central_angle_f64x2);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
NK_PUBLIC void nk_haversine_f64_v128relaxed( //
|
|
96
|
+
nk_f64_t const *a_lats, nk_f64_t const *a_lons, //
|
|
97
|
+
nk_f64_t const *b_lats, nk_f64_t const *b_lons, //
|
|
98
|
+
nk_size_t n, nk_f64_t *results) {
|
|
99
|
+
|
|
100
|
+
while (n >= 2) {
|
|
101
|
+
v128_t first_latitudes_f64x2 = wasm_v128_load(a_lats);
|
|
102
|
+
v128_t first_longitudes_f64x2 = wasm_v128_load(a_lons);
|
|
103
|
+
v128_t second_latitudes_f64x2 = wasm_v128_load(b_lats);
|
|
104
|
+
v128_t second_longitudes_f64x2 = wasm_v128_load(b_lons);
|
|
105
|
+
|
|
106
|
+
v128_t distances_f64x2 = nk_haversine_f64x2_v128relaxed_(first_latitudes_f64x2, first_longitudes_f64x2,
|
|
107
|
+
second_latitudes_f64x2, second_longitudes_f64x2);
|
|
108
|
+
wasm_v128_store(results, distances_f64x2);
|
|
109
|
+
|
|
110
|
+
a_lats += 2, a_lons += 2, b_lats += 2, b_lons += 2, results += 2, n -= 2;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Handle tail with partial loads (n can only be 0 or 1 here)
|
|
114
|
+
if (n > 0) {
|
|
115
|
+
nk_b128_vec_t a_lat_vec, a_lon_vec, b_lat_vec, b_lon_vec, result_vec;
|
|
116
|
+
nk_partial_load_b64x2_serial_(a_lats, &a_lat_vec, n);
|
|
117
|
+
nk_partial_load_b64x2_serial_(a_lons, &a_lon_vec, n);
|
|
118
|
+
nk_partial_load_b64x2_serial_(b_lats, &b_lat_vec, n);
|
|
119
|
+
nk_partial_load_b64x2_serial_(b_lons, &b_lon_vec, n);
|
|
120
|
+
v128_t distances_f64x2 = nk_haversine_f64x2_v128relaxed_(a_lat_vec.v128, a_lon_vec.v128, b_lat_vec.v128,
|
|
121
|
+
b_lon_vec.v128);
|
|
122
|
+
result_vec.v128 = distances_f64x2;
|
|
123
|
+
nk_partial_store_b64x2_serial_(&result_vec, results, n);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
NK_INTERNAL v128_t nk_haversine_f32x4_v128relaxed_( //
|
|
128
|
+
v128_t first_latitudes_f32x4, v128_t first_longitudes_f32x4, //
|
|
129
|
+
v128_t second_latitudes_f32x4, v128_t second_longitudes_f32x4) {
|
|
130
|
+
|
|
131
|
+
v128_t const earth_radius_f32x4 = wasm_f32x4_splat((float)NK_EARTH_MEDIATORIAL_RADIUS);
|
|
132
|
+
v128_t const half_f32x4 = wasm_f32x4_splat(0.5f);
|
|
133
|
+
v128_t const one_f32x4 = wasm_f32x4_splat(1.0f);
|
|
134
|
+
v128_t const two_f32x4 = wasm_f32x4_splat(2.0f);
|
|
135
|
+
|
|
136
|
+
v128_t latitude_delta_f32x4 = wasm_f32x4_sub(second_latitudes_f32x4, first_latitudes_f32x4);
|
|
137
|
+
v128_t longitude_delta_f32x4 = wasm_f32x4_sub(second_longitudes_f32x4, first_longitudes_f32x4);
|
|
138
|
+
|
|
139
|
+
// Haversine terms: sin^2(delta/2)
|
|
140
|
+
v128_t latitude_delta_half_f32x4 = wasm_f32x4_mul(latitude_delta_f32x4, half_f32x4);
|
|
141
|
+
v128_t longitude_delta_half_f32x4 = wasm_f32x4_mul(longitude_delta_f32x4, half_f32x4);
|
|
142
|
+
v128_t sin_latitude_delta_half_f32x4 = nk_f32x4_sin_v128relaxed_(latitude_delta_half_f32x4);
|
|
143
|
+
v128_t sin_longitude_delta_half_f32x4 = nk_f32x4_sin_v128relaxed_(longitude_delta_half_f32x4);
|
|
144
|
+
v128_t sin_squared_latitude_delta_half_f32x4 = wasm_f32x4_mul(sin_latitude_delta_half_f32x4,
|
|
145
|
+
sin_latitude_delta_half_f32x4);
|
|
146
|
+
v128_t sin_squared_longitude_delta_half_f32x4 = wasm_f32x4_mul(sin_longitude_delta_half_f32x4,
|
|
147
|
+
sin_longitude_delta_half_f32x4);
|
|
148
|
+
|
|
149
|
+
// Latitude cosine product
|
|
150
|
+
v128_t cos_first_latitude_f32x4 = nk_f32x4_cos_v128relaxed_(first_latitudes_f32x4);
|
|
151
|
+
v128_t cos_second_latitude_f32x4 = nk_f32x4_cos_v128relaxed_(second_latitudes_f32x4);
|
|
152
|
+
v128_t cos_latitude_product_f32x4 = wasm_f32x4_mul(cos_first_latitude_f32x4, cos_second_latitude_f32x4);
|
|
153
|
+
|
|
154
|
+
// a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlon/2)
|
|
155
|
+
v128_t haversine_term_f32x4 = wasm_f32x4_add(
|
|
156
|
+
sin_squared_latitude_delta_half_f32x4,
|
|
157
|
+
wasm_f32x4_mul(cos_latitude_product_f32x4, sin_squared_longitude_delta_half_f32x4));
|
|
158
|
+
|
|
159
|
+
// Clamp to [0, 1] to avoid NaN from sqrt of negative numbers (due to floating point errors)
|
|
160
|
+
// relaxed_min/max: 1 instruction (minps/maxps) vs 6-9 (with NaN/signed-zero_f32x4 fixup) on x86.
|
|
161
|
+
// Safe because haversine_term_f32x4 is a product of finite sin/cos values — NaN is impossible.
|
|
162
|
+
v128_t zero_f32x4 = wasm_f32x4_splat(0.0f);
|
|
163
|
+
haversine_term_f32x4 = wasm_f32x4_relaxed_max(zero_f32x4, wasm_f32x4_relaxed_min(one_f32x4, haversine_term_f32x4));
|
|
164
|
+
|
|
165
|
+
// Central angle: c = 2 * atan2(sqrt(a), sqrt(1-a))
|
|
166
|
+
v128_t sqrt_haversine_f32x4 = wasm_f32x4_sqrt(haversine_term_f32x4);
|
|
167
|
+
v128_t sqrt_complement_f32x4 = wasm_f32x4_sqrt(wasm_f32x4_sub(one_f32x4, haversine_term_f32x4));
|
|
168
|
+
v128_t central_angle_f32x4 = wasm_f32x4_mul(
|
|
169
|
+
two_f32x4, nk_f32x4_atan2_v128relaxed_(sqrt_haversine_f32x4, sqrt_complement_f32x4));
|
|
170
|
+
|
|
171
|
+
return wasm_f32x4_mul(earth_radius_f32x4, central_angle_f32x4);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
NK_PUBLIC void nk_haversine_f32_v128relaxed( //
|
|
175
|
+
nk_f32_t const *a_lats, nk_f32_t const *a_lons, //
|
|
176
|
+
nk_f32_t const *b_lats, nk_f32_t const *b_lons, //
|
|
177
|
+
nk_size_t n, nk_f32_t *results) {
|
|
178
|
+
|
|
179
|
+
while (n >= 4) {
|
|
180
|
+
v128_t first_latitudes_f32x4 = wasm_v128_load(a_lats);
|
|
181
|
+
v128_t first_longitudes_f32x4 = wasm_v128_load(a_lons);
|
|
182
|
+
v128_t second_latitudes_f32x4 = wasm_v128_load(b_lats);
|
|
183
|
+
v128_t second_longitudes_f32x4 = wasm_v128_load(b_lons);
|
|
184
|
+
|
|
185
|
+
v128_t distances_f32x4 = nk_haversine_f32x4_v128relaxed_(first_latitudes_f32x4, first_longitudes_f32x4,
|
|
186
|
+
second_latitudes_f32x4, second_longitudes_f32x4);
|
|
187
|
+
wasm_v128_store(results, distances_f32x4);
|
|
188
|
+
|
|
189
|
+
a_lats += 4, a_lons += 4, b_lats += 4, b_lons += 4, results += 4, n -= 4;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Handle tail with partial loads (n can be 0-3 here)
|
|
193
|
+
if (n > 0) {
|
|
194
|
+
nk_b128_vec_t a_lat_vec, a_lon_vec, b_lat_vec, b_lon_vec, result_vec;
|
|
195
|
+
nk_partial_load_b32x4_serial_(a_lats, &a_lat_vec, n);
|
|
196
|
+
nk_partial_load_b32x4_serial_(a_lons, &a_lon_vec, n);
|
|
197
|
+
nk_partial_load_b32x4_serial_(b_lats, &b_lat_vec, n);
|
|
198
|
+
nk_partial_load_b32x4_serial_(b_lons, &b_lon_vec, n);
|
|
199
|
+
v128_t distances_f32x4 = nk_haversine_f32x4_v128relaxed_(a_lat_vec.v128, a_lon_vec.v128, b_lat_vec.v128,
|
|
200
|
+
b_lon_vec.v128);
|
|
201
|
+
result_vec.v128 = distances_f32x4;
|
|
202
|
+
nk_partial_store_b32x4_serial_(&result_vec, results, n);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @brief WASM Relaxed SIMD helper for Vincenty's geodesic distance on 2 f64 point pairs.
|
|
208
|
+
* @note This is a true SIMD implementation using masked convergence tracking via blending.
|
|
209
|
+
*/
|
|
210
|
+
NK_INTERNAL v128_t nk_vincenty_f64x2_v128relaxed_( //
|
|
211
|
+
v128_t first_latitudes_f64x2, v128_t first_longitudes_f64x2, //
|
|
212
|
+
v128_t second_latitudes_f64x2, v128_t second_longitudes_f64x2) {
|
|
213
|
+
|
|
214
|
+
v128_t const equatorial_radius_f64x2 = wasm_f64x2_splat(NK_EARTH_ELLIPSOID_EQUATORIAL_RADIUS);
|
|
215
|
+
v128_t const polar_radius_f64x2 = wasm_f64x2_splat(NK_EARTH_ELLIPSOID_POLAR_RADIUS);
|
|
216
|
+
v128_t const flattening_f64x2 = wasm_f64x2_splat(1.0 / NK_EARTH_ELLIPSOID_INVERSE_FLATTENING);
|
|
217
|
+
v128_t const convergence_threshold_f64x2 = wasm_f64x2_splat(NK_VINCENTY_CONVERGENCE_THRESHOLD_F64);
|
|
218
|
+
v128_t const one_f64x2 = wasm_f64x2_splat(1.0);
|
|
219
|
+
v128_t const two_f64x2 = wasm_f64x2_splat(2.0);
|
|
220
|
+
v128_t const three_f64x2 = wasm_f64x2_splat(3.0);
|
|
221
|
+
v128_t const four_f64x2 = wasm_f64x2_splat(4.0);
|
|
222
|
+
v128_t const six_f64x2 = wasm_f64x2_splat(6.0);
|
|
223
|
+
v128_t const sixteen_f64x2 = wasm_f64x2_splat(16.0);
|
|
224
|
+
v128_t const epsilon_f64x2 = wasm_f64x2_splat(1e-15);
|
|
225
|
+
|
|
226
|
+
// Longitude difference
|
|
227
|
+
v128_t longitude_difference_f64x2 = wasm_f64x2_sub(second_longitudes_f64x2, first_longitudes_f64x2);
|
|
228
|
+
|
|
229
|
+
// Reduced latitudes: tan(U) = (1-f) * tan(lat)
|
|
230
|
+
v128_t one_minus_f_f64x2 = wasm_f64x2_sub(one_f64x2, flattening_f64x2);
|
|
231
|
+
v128_t tan_first_f64x2 = wasm_f64x2_div(nk_f64x2_sin_v128relaxed_(first_latitudes_f64x2),
|
|
232
|
+
nk_f64x2_cos_v128relaxed_(first_latitudes_f64x2));
|
|
233
|
+
v128_t tan_second_f64x2 = wasm_f64x2_div(nk_f64x2_sin_v128relaxed_(second_latitudes_f64x2),
|
|
234
|
+
nk_f64x2_cos_v128relaxed_(second_latitudes_f64x2));
|
|
235
|
+
v128_t tan_reduced_first_f64x2 = wasm_f64x2_mul(one_minus_f_f64x2, tan_first_f64x2);
|
|
236
|
+
v128_t tan_reduced_second_f64x2 = wasm_f64x2_mul(one_minus_f_f64x2, tan_second_f64x2);
|
|
237
|
+
|
|
238
|
+
// cos(U) = 1/sqrt(1 + tan^2(U)), sin(U) = tan(U) * cos(U)
|
|
239
|
+
v128_t cos_reduced_first_f64x2 = wasm_f64x2_div(
|
|
240
|
+
one_f64x2,
|
|
241
|
+
wasm_f64x2_sqrt(wasm_f64x2_relaxed_madd(tan_reduced_first_f64x2, tan_reduced_first_f64x2, one_f64x2)));
|
|
242
|
+
v128_t sin_reduced_first_f64x2 = wasm_f64x2_mul(tan_reduced_first_f64x2, cos_reduced_first_f64x2);
|
|
243
|
+
v128_t cos_reduced_second_f64x2 = wasm_f64x2_div(
|
|
244
|
+
one_f64x2,
|
|
245
|
+
wasm_f64x2_sqrt(wasm_f64x2_relaxed_madd(tan_reduced_second_f64x2, tan_reduced_second_f64x2, one_f64x2)));
|
|
246
|
+
v128_t sin_reduced_second_f64x2 = wasm_f64x2_mul(tan_reduced_second_f64x2, cos_reduced_second_f64x2);
|
|
247
|
+
|
|
248
|
+
// Initialize lambda_f64x2 and tracking variables
|
|
249
|
+
v128_t lambda_f64x2 = longitude_difference_f64x2;
|
|
250
|
+
v128_t sin_angular_distance_f64x2, cos_angular_distance_f64x2, angular_distance_f64x2;
|
|
251
|
+
v128_t sin_azimuth_f64x2, cos_squared_azimuth_f64x2, cos_double_angular_midpoint_f64x2;
|
|
252
|
+
|
|
253
|
+
// Track convergence and coincident points using masks
|
|
254
|
+
v128_t converged_mask_i64x2 = wasm_i64x2_splat(0);
|
|
255
|
+
v128_t coincident_mask_i64x2 = wasm_i64x2_splat(0);
|
|
256
|
+
|
|
257
|
+
for (nk_u32_t iteration = 0; iteration < NK_VINCENTY_MAX_ITERATIONS; ++iteration) {
|
|
258
|
+
// Check if all lanes converged
|
|
259
|
+
if (wasm_i8x16_all_true(converged_mask_i64x2)) break;
|
|
260
|
+
|
|
261
|
+
v128_t sin_lambda_f64x2 = nk_f64x2_sin_v128relaxed_(lambda_f64x2);
|
|
262
|
+
v128_t cos_lambda_f64x2 = nk_f64x2_cos_v128relaxed_(lambda_f64x2);
|
|
263
|
+
|
|
264
|
+
// sin^2(angular_distance_f64x2) = (cos(U2) * sin(l))^2 + (cos(U1) * sin(U2) - sin(U1) * cos(U2) * cos(l))^2
|
|
265
|
+
v128_t cross_term_f64x2 = wasm_f64x2_mul(cos_reduced_second_f64x2, sin_lambda_f64x2);
|
|
266
|
+
v128_t mixed_term_f64x2 = wasm_f64x2_sub(
|
|
267
|
+
wasm_f64x2_mul(cos_reduced_first_f64x2, sin_reduced_second_f64x2),
|
|
268
|
+
wasm_f64x2_mul(wasm_f64x2_mul(sin_reduced_first_f64x2, cos_reduced_second_f64x2), cos_lambda_f64x2));
|
|
269
|
+
v128_t sin_angular_dist_sq_f64x2 = wasm_f64x2_relaxed_madd(cross_term_f64x2, cross_term_f64x2,
|
|
270
|
+
wasm_f64x2_mul(mixed_term_f64x2, mixed_term_f64x2));
|
|
271
|
+
sin_angular_distance_f64x2 = wasm_f64x2_sqrt(sin_angular_dist_sq_f64x2);
|
|
272
|
+
|
|
273
|
+
// Check for coincident points (sin_angular_distance_f64x2 ~ 0)
|
|
274
|
+
coincident_mask_i64x2 = wasm_f64x2_lt(sin_angular_distance_f64x2, epsilon_f64x2);
|
|
275
|
+
|
|
276
|
+
// cos(angular_distance_f64x2) = sin(U1) * sin(U2) + cos(U1) * cos(U2) * cos(l)
|
|
277
|
+
cos_angular_distance_f64x2 = wasm_f64x2_relaxed_madd(
|
|
278
|
+
wasm_f64x2_mul(cos_reduced_first_f64x2, cos_reduced_second_f64x2), cos_lambda_f64x2,
|
|
279
|
+
wasm_f64x2_mul(sin_reduced_first_f64x2, sin_reduced_second_f64x2));
|
|
280
|
+
|
|
281
|
+
// angular_distance_f64x2 = atan2(sin, cos)
|
|
282
|
+
angular_distance_f64x2 = nk_f64x2_atan2_v128relaxed_(sin_angular_distance_f64x2, cos_angular_distance_f64x2);
|
|
283
|
+
|
|
284
|
+
// sin(azimuth) = cos(U1) * cos(U2) * sin(l) / sin(angular_distance_f64x2)
|
|
285
|
+
// Avoid division by zero by using blending
|
|
286
|
+
// relaxed_laneselect: 1 instruction (vblendvpd) vs 3 (vpand+vpandn+vpor) on x86.
|
|
287
|
+
// Safe because mask is from comparison (all-ones or all-zeros per lane).
|
|
288
|
+
v128_t safe_sin_angular_i64x2 = wasm_i64x2_relaxed_laneselect(one_f64x2, sin_angular_distance_f64x2,
|
|
289
|
+
coincident_mask_i64x2);
|
|
290
|
+
sin_azimuth_f64x2 = wasm_f64x2_div(
|
|
291
|
+
wasm_f64x2_mul(wasm_f64x2_mul(cos_reduced_first_f64x2, cos_reduced_second_f64x2), sin_lambda_f64x2),
|
|
292
|
+
safe_sin_angular_i64x2);
|
|
293
|
+
cos_squared_azimuth_f64x2 = wasm_f64x2_relaxed_nmadd(sin_azimuth_f64x2, sin_azimuth_f64x2, one_f64x2);
|
|
294
|
+
|
|
295
|
+
// Handle equatorial case: cos^2(a) ~ 0
|
|
296
|
+
v128_t equatorial_mask_f64x2 = wasm_f64x2_lt(cos_squared_azimuth_f64x2, epsilon_f64x2);
|
|
297
|
+
v128_t safe_cos_sq_azimuth_i64x2 = wasm_i64x2_relaxed_laneselect(one_f64x2, cos_squared_azimuth_f64x2,
|
|
298
|
+
equatorial_mask_f64x2);
|
|
299
|
+
|
|
300
|
+
// cos(2sm) = cos(s) - 2 * sin(U1) * sin(U2) / cos^2(a)
|
|
301
|
+
v128_t sin_product_f64x2 = wasm_f64x2_mul(sin_reduced_first_f64x2, sin_reduced_second_f64x2);
|
|
302
|
+
cos_double_angular_midpoint_f64x2 = wasm_f64x2_sub(
|
|
303
|
+
cos_angular_distance_f64x2,
|
|
304
|
+
wasm_f64x2_div(wasm_f64x2_mul(two_f64x2, sin_product_f64x2), safe_cos_sq_azimuth_i64x2));
|
|
305
|
+
cos_double_angular_midpoint_f64x2 = wasm_i64x2_relaxed_laneselect(
|
|
306
|
+
wasm_f64x2_splat(0.0), cos_double_angular_midpoint_f64x2, equatorial_mask_f64x2);
|
|
307
|
+
|
|
308
|
+
// C = f/16 * cos^2(a) * (4 + f*(4 - 3*cos^2(a)))
|
|
309
|
+
v128_t correction_factor_f64x2 = wasm_f64x2_mul(
|
|
310
|
+
wasm_f64x2_div(flattening_f64x2, sixteen_f64x2),
|
|
311
|
+
wasm_f64x2_mul(
|
|
312
|
+
cos_squared_azimuth_f64x2,
|
|
313
|
+
wasm_f64x2_relaxed_madd(flattening_f64x2,
|
|
314
|
+
wasm_f64x2_relaxed_nmadd(three_f64x2, cos_squared_azimuth_f64x2, four_f64x2),
|
|
315
|
+
four_f64x2)));
|
|
316
|
+
|
|
317
|
+
// l' = L + (1-C) * f * sin(a) * (s + C * sin(s) * (cos(2sm) + C * cos(s) * (-1 + 2 * cos^2(2sm))))
|
|
318
|
+
v128_t cos_2sm_sq_f64x2 = wasm_f64x2_mul(cos_double_angular_midpoint_f64x2, cos_double_angular_midpoint_f64x2);
|
|
319
|
+
// innermost_f64x2 = -1 + 2 * cos^2(2sm)
|
|
320
|
+
v128_t innermost_f64x2 = wasm_f64x2_relaxed_madd(two_f64x2, cos_2sm_sq_f64x2, wasm_f64x2_splat(-1.0));
|
|
321
|
+
// middle_f64x2 = cos(2sm) + C * cos(s) * innermost_f64x2
|
|
322
|
+
v128_t middle_f64x2 = wasm_f64x2_relaxed_madd(
|
|
323
|
+
wasm_f64x2_mul(correction_factor_f64x2, cos_angular_distance_f64x2), innermost_f64x2,
|
|
324
|
+
cos_double_angular_midpoint_f64x2);
|
|
325
|
+
// inner_f64x2 = C * sin(s) * middle_f64x2
|
|
326
|
+
v128_t inner_f64x2 = wasm_f64x2_mul(wasm_f64x2_mul(correction_factor_f64x2, sin_angular_distance_f64x2),
|
|
327
|
+
middle_f64x2);
|
|
328
|
+
|
|
329
|
+
// l' = L + (1-C) * f * sin_a * (s + inner_f64x2)
|
|
330
|
+
v128_t lambda_new_f64x2 = wasm_f64x2_relaxed_madd(
|
|
331
|
+
wasm_f64x2_mul(wasm_f64x2_mul(wasm_f64x2_sub(one_f64x2, correction_factor_f64x2), flattening_f64x2),
|
|
332
|
+
sin_azimuth_f64x2),
|
|
333
|
+
wasm_f64x2_add(angular_distance_f64x2, inner_f64x2), longitude_difference_f64x2);
|
|
334
|
+
|
|
335
|
+
// Check convergence: |l - l'| < threshold
|
|
336
|
+
v128_t lambda_diff_f64x2 = wasm_f64x2_sub(lambda_new_f64x2, lambda_f64x2);
|
|
337
|
+
v128_t lambda_diff_abs_f64x2 = wasm_f64x2_abs(lambda_diff_f64x2);
|
|
338
|
+
v128_t newly_converged_f64x2 = wasm_f64x2_lt(lambda_diff_abs_f64x2, convergence_threshold_f64x2);
|
|
339
|
+
converged_mask_i64x2 = wasm_v128_or(converged_mask_i64x2, newly_converged_f64x2);
|
|
340
|
+
|
|
341
|
+
// Only update lambda_f64x2 for non-converged lanes
|
|
342
|
+
// relaxed_laneselect: 1 instruction (vblendvpd) vs 3 (vpand+vpandn+vpor) on x86.
|
|
343
|
+
// Safe because mask is from comparison (all-ones or all-zeros per lane).
|
|
344
|
+
lambda_f64x2 = wasm_i64x2_relaxed_laneselect(lambda_f64x2, lambda_new_f64x2, converged_mask_i64x2);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Final distance calculation
|
|
348
|
+
// u^2 = cos^2(a) * (a^2 - b^2) / b^2
|
|
349
|
+
v128_t a_sq_f64x2 = wasm_f64x2_mul(equatorial_radius_f64x2, equatorial_radius_f64x2);
|
|
350
|
+
v128_t b_sq_f64x2 = wasm_f64x2_mul(polar_radius_f64x2, polar_radius_f64x2);
|
|
351
|
+
v128_t u_squared_f64x2 = wasm_f64x2_div(
|
|
352
|
+
wasm_f64x2_mul(cos_squared_azimuth_f64x2, wasm_f64x2_sub(a_sq_f64x2, b_sq_f64x2)), b_sq_f64x2);
|
|
353
|
+
|
|
354
|
+
// A = 1 + u^2/16384 * (4096 + u^2*(-768 + u^2*(320 - 175*u^2)))
|
|
355
|
+
v128_t series_a_f64x2 = wasm_f64x2_relaxed_madd(u_squared_f64x2, wasm_f64x2_splat(-175.0), wasm_f64x2_splat(320.0));
|
|
356
|
+
series_a_f64x2 = wasm_f64x2_relaxed_madd(u_squared_f64x2, series_a_f64x2, wasm_f64x2_splat(-768.0));
|
|
357
|
+
series_a_f64x2 = wasm_f64x2_relaxed_madd(u_squared_f64x2, series_a_f64x2, wasm_f64x2_splat(4096.0));
|
|
358
|
+
series_a_f64x2 = wasm_f64x2_relaxed_madd(wasm_f64x2_div(u_squared_f64x2, wasm_f64x2_splat(16384.0)), series_a_f64x2,
|
|
359
|
+
one_f64x2);
|
|
360
|
+
|
|
361
|
+
// B = u^2/1024 * (256 + u^2*(-128 + u^2*(74 - 47*u^2)))
|
|
362
|
+
v128_t series_b_f64x2 = wasm_f64x2_relaxed_madd(u_squared_f64x2, wasm_f64x2_splat(-47.0), wasm_f64x2_splat(74.0));
|
|
363
|
+
series_b_f64x2 = wasm_f64x2_relaxed_madd(u_squared_f64x2, series_b_f64x2, wasm_f64x2_splat(-128.0));
|
|
364
|
+
series_b_f64x2 = wasm_f64x2_relaxed_madd(u_squared_f64x2, series_b_f64x2, wasm_f64x2_splat(256.0));
|
|
365
|
+
series_b_f64x2 = wasm_f64x2_mul(wasm_f64x2_div(u_squared_f64x2, wasm_f64x2_splat(1024.0)), series_b_f64x2);
|
|
366
|
+
|
|
367
|
+
// Delta-sigma calculation
|
|
368
|
+
v128_t cos_2sm_sq_f64x2 = wasm_f64x2_mul(cos_double_angular_midpoint_f64x2, cos_double_angular_midpoint_f64x2);
|
|
369
|
+
v128_t sin_sq_f64x2 = wasm_f64x2_mul(sin_angular_distance_f64x2, sin_angular_distance_f64x2);
|
|
370
|
+
v128_t term1_f64x2 = wasm_f64x2_relaxed_madd(two_f64x2, cos_2sm_sq_f64x2, wasm_f64x2_splat(-1.0));
|
|
371
|
+
term1_f64x2 = wasm_f64x2_mul(cos_angular_distance_f64x2, term1_f64x2);
|
|
372
|
+
v128_t term2_f64x2 = wasm_f64x2_relaxed_madd(four_f64x2, sin_sq_f64x2, wasm_f64x2_splat(-3.0));
|
|
373
|
+
v128_t term3_f64x2 = wasm_f64x2_relaxed_madd(four_f64x2, cos_2sm_sq_f64x2, wasm_f64x2_splat(-3.0));
|
|
374
|
+
term2_f64x2 = wasm_f64x2_mul(
|
|
375
|
+
wasm_f64x2_mul(wasm_f64x2_div(series_b_f64x2, six_f64x2), cos_double_angular_midpoint_f64x2),
|
|
376
|
+
wasm_f64x2_mul(term2_f64x2, term3_f64x2));
|
|
377
|
+
v128_t delta_sigma_f64x2 = wasm_f64x2_mul(
|
|
378
|
+
series_b_f64x2, wasm_f64x2_mul(sin_angular_distance_f64x2,
|
|
379
|
+
wasm_f64x2_add(cos_double_angular_midpoint_f64x2,
|
|
380
|
+
wasm_f64x2_mul(wasm_f64x2_div(series_b_f64x2, four_f64x2),
|
|
381
|
+
wasm_f64x2_sub(term1_f64x2, term2_f64x2)))));
|
|
382
|
+
|
|
383
|
+
// s = b * A * (s - ds)
|
|
384
|
+
v128_t distances_f64x2 = wasm_f64x2_mul(wasm_f64x2_mul(polar_radius_f64x2, series_a_f64x2),
|
|
385
|
+
wasm_f64x2_sub(angular_distance_f64x2, delta_sigma_f64x2));
|
|
386
|
+
|
|
387
|
+
// Set coincident points to zero
|
|
388
|
+
// relaxed_laneselect: 1 instruction (vblendvpd) vs 3 (vpand+vpandn+vpor) on x86.
|
|
389
|
+
// Safe because mask is from comparison (all-ones or all-zeros per lane).
|
|
390
|
+
distances_f64x2 = wasm_i64x2_relaxed_laneselect(wasm_f64x2_splat(0.0), distances_f64x2, coincident_mask_i64x2);
|
|
391
|
+
|
|
392
|
+
return distances_f64x2;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
NK_PUBLIC void nk_vincenty_f64_v128relaxed( //
|
|
396
|
+
nk_f64_t const *a_lats, nk_f64_t const *a_lons, //
|
|
397
|
+
nk_f64_t const *b_lats, nk_f64_t const *b_lons, //
|
|
398
|
+
nk_size_t n, nk_f64_t *results) {
|
|
399
|
+
|
|
400
|
+
while (n >= 2) {
|
|
401
|
+
v128_t first_latitudes_f64x2 = wasm_v128_load(a_lats);
|
|
402
|
+
v128_t first_longitudes_f64x2 = wasm_v128_load(a_lons);
|
|
403
|
+
v128_t second_latitudes_f64x2 = wasm_v128_load(b_lats);
|
|
404
|
+
v128_t second_longitudes_f64x2 = wasm_v128_load(b_lons);
|
|
405
|
+
|
|
406
|
+
v128_t distances_f64x2 = nk_vincenty_f64x2_v128relaxed_(first_latitudes_f64x2, first_longitudes_f64x2,
|
|
407
|
+
second_latitudes_f64x2, second_longitudes_f64x2);
|
|
408
|
+
wasm_v128_store(results, distances_f64x2);
|
|
409
|
+
|
|
410
|
+
a_lats += 2, a_lons += 2, b_lats += 2, b_lons += 2, results += 2, n -= 2;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Handle remaining elements with partial loads (n can only be 0 or 1 here)
|
|
414
|
+
if (n > 0) {
|
|
415
|
+
nk_b128_vec_t a_lat_vec, a_lon_vec, b_lat_vec, b_lon_vec, result_vec;
|
|
416
|
+
nk_partial_load_b64x2_serial_(a_lats, &a_lat_vec, n);
|
|
417
|
+
nk_partial_load_b64x2_serial_(a_lons, &a_lon_vec, n);
|
|
418
|
+
nk_partial_load_b64x2_serial_(b_lats, &b_lat_vec, n);
|
|
419
|
+
nk_partial_load_b64x2_serial_(b_lons, &b_lon_vec, n);
|
|
420
|
+
v128_t distances_f64x2 = nk_vincenty_f64x2_v128relaxed_(a_lat_vec.v128, a_lon_vec.v128, b_lat_vec.v128,
|
|
421
|
+
b_lon_vec.v128);
|
|
422
|
+
result_vec.v128 = distances_f64x2;
|
|
423
|
+
nk_partial_store_b64x2_serial_(&result_vec, results, n);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @brief WASM Relaxed SIMD helper for Vincenty's geodesic distance on 4 f32 point pairs.
|
|
429
|
+
* @note This is a true SIMD implementation using masked convergence tracking via blending.
|
|
430
|
+
*/
|
|
431
|
+
NK_INTERNAL v128_t nk_vincenty_f32x4_v128relaxed_( //
|
|
432
|
+
v128_t first_latitudes_f32x4, v128_t first_longitudes_f32x4, //
|
|
433
|
+
v128_t second_latitudes_f32x4, v128_t second_longitudes_f32x4) {
|
|
434
|
+
|
|
435
|
+
v128_t const equatorial_radius_f32x4 = wasm_f32x4_splat((float)NK_EARTH_ELLIPSOID_EQUATORIAL_RADIUS);
|
|
436
|
+
v128_t const polar_radius_f32x4 = wasm_f32x4_splat((float)NK_EARTH_ELLIPSOID_POLAR_RADIUS);
|
|
437
|
+
v128_t const flattening_f32x4 = wasm_f32x4_splat(1.0f / (float)NK_EARTH_ELLIPSOID_INVERSE_FLATTENING);
|
|
438
|
+
v128_t const convergence_threshold_f32x4 = wasm_f32x4_splat(NK_VINCENTY_CONVERGENCE_THRESHOLD_F32);
|
|
439
|
+
v128_t const one_f32x4 = wasm_f32x4_splat(1.0f);
|
|
440
|
+
v128_t const two_f32x4 = wasm_f32x4_splat(2.0f);
|
|
441
|
+
v128_t const three_f32x4 = wasm_f32x4_splat(3.0f);
|
|
442
|
+
v128_t const four_f32x4 = wasm_f32x4_splat(4.0f);
|
|
443
|
+
v128_t const six_f32x4 = wasm_f32x4_splat(6.0f);
|
|
444
|
+
v128_t const sixteen_f32x4 = wasm_f32x4_splat(16.0f);
|
|
445
|
+
v128_t const epsilon_f32x4 = wasm_f32x4_splat(1e-7f);
|
|
446
|
+
|
|
447
|
+
// Longitude difference
|
|
448
|
+
v128_t longitude_difference_f32x4 = wasm_f32x4_sub(second_longitudes_f32x4, first_longitudes_f32x4);
|
|
449
|
+
|
|
450
|
+
// Reduced latitudes: tan(U) = (1-f) * tan(lat)
|
|
451
|
+
v128_t one_minus_f_f32x4 = wasm_f32x4_sub(one_f32x4, flattening_f32x4);
|
|
452
|
+
v128_t tan_first_f32x4 = wasm_f32x4_div(nk_f32x4_sin_v128relaxed_(first_latitudes_f32x4),
|
|
453
|
+
nk_f32x4_cos_v128relaxed_(first_latitudes_f32x4));
|
|
454
|
+
v128_t tan_second_f32x4 = wasm_f32x4_div(nk_f32x4_sin_v128relaxed_(second_latitudes_f32x4),
|
|
455
|
+
nk_f32x4_cos_v128relaxed_(second_latitudes_f32x4));
|
|
456
|
+
v128_t tan_reduced_first_f32x4 = wasm_f32x4_mul(one_minus_f_f32x4, tan_first_f32x4);
|
|
457
|
+
v128_t tan_reduced_second_f32x4 = wasm_f32x4_mul(one_minus_f_f32x4, tan_second_f32x4);
|
|
458
|
+
|
|
459
|
+
// cos(U) = 1/sqrt(1 + tan^2(U)), sin(U) = tan(U) * cos(U)
|
|
460
|
+
v128_t cos_reduced_first_f32x4 = wasm_f32x4_div(
|
|
461
|
+
one_f32x4,
|
|
462
|
+
wasm_f32x4_sqrt(wasm_f32x4_relaxed_madd(tan_reduced_first_f32x4, tan_reduced_first_f32x4, one_f32x4)));
|
|
463
|
+
v128_t sin_reduced_first_f32x4 = wasm_f32x4_mul(tan_reduced_first_f32x4, cos_reduced_first_f32x4);
|
|
464
|
+
v128_t cos_reduced_second_f32x4 = wasm_f32x4_div(
|
|
465
|
+
one_f32x4,
|
|
466
|
+
wasm_f32x4_sqrt(wasm_f32x4_relaxed_madd(tan_reduced_second_f32x4, tan_reduced_second_f32x4, one_f32x4)));
|
|
467
|
+
v128_t sin_reduced_second_f32x4 = wasm_f32x4_mul(tan_reduced_second_f32x4, cos_reduced_second_f32x4);
|
|
468
|
+
|
|
469
|
+
// Initialize lambda_f32x4 and tracking variables
|
|
470
|
+
v128_t lambda_f32x4 = longitude_difference_f32x4;
|
|
471
|
+
v128_t sin_angular_distance_f32x4, cos_angular_distance_f32x4, angular_distance_f32x4;
|
|
472
|
+
v128_t sin_azimuth_f32x4, cos_squared_azimuth_f32x4, cos_double_angular_midpoint_f32x4;
|
|
473
|
+
|
|
474
|
+
// Track convergence and coincident points using masks
|
|
475
|
+
v128_t converged_mask_i32x4 = wasm_i32x4_splat(0);
|
|
476
|
+
v128_t coincident_mask_i32x4 = wasm_i32x4_splat(0);
|
|
477
|
+
|
|
478
|
+
for (nk_u32_t iteration = 0; iteration < NK_VINCENTY_MAX_ITERATIONS; ++iteration) {
|
|
479
|
+
// Check if all lanes converged
|
|
480
|
+
if (wasm_i8x16_all_true(converged_mask_i32x4)) break;
|
|
481
|
+
|
|
482
|
+
v128_t sin_lambda_f32x4 = nk_f32x4_sin_v128relaxed_(lambda_f32x4);
|
|
483
|
+
v128_t cos_lambda_f32x4 = nk_f32x4_cos_v128relaxed_(lambda_f32x4);
|
|
484
|
+
|
|
485
|
+
// sin^2(angular_distance_f32x4) = (cos(U2) * sin(l))^2 + (cos(U1) * sin(U2) - sin(U1) * cos(U2) * cos(l))^2
|
|
486
|
+
v128_t cross_term_f32x4 = wasm_f32x4_mul(cos_reduced_second_f32x4, sin_lambda_f32x4);
|
|
487
|
+
v128_t mixed_term_f32x4 = wasm_f32x4_sub(
|
|
488
|
+
wasm_f32x4_mul(cos_reduced_first_f32x4, sin_reduced_second_f32x4),
|
|
489
|
+
wasm_f32x4_mul(wasm_f32x4_mul(sin_reduced_first_f32x4, cos_reduced_second_f32x4), cos_lambda_f32x4));
|
|
490
|
+
v128_t sin_angular_dist_sq_f32x4 = wasm_f32x4_relaxed_madd(cross_term_f32x4, cross_term_f32x4,
|
|
491
|
+
wasm_f32x4_mul(mixed_term_f32x4, mixed_term_f32x4));
|
|
492
|
+
sin_angular_distance_f32x4 = wasm_f32x4_sqrt(sin_angular_dist_sq_f32x4);
|
|
493
|
+
|
|
494
|
+
// Check for coincident points (sin_angular_distance_f32x4 ~ 0)
|
|
495
|
+
coincident_mask_i32x4 = wasm_f32x4_lt(sin_angular_distance_f32x4, epsilon_f32x4);
|
|
496
|
+
|
|
497
|
+
// cos(angular_distance_f32x4) = sin(U1) * sin(U2) + cos(U1) * cos(U2) * cos(l)
|
|
498
|
+
cos_angular_distance_f32x4 = wasm_f32x4_relaxed_madd(
|
|
499
|
+
wasm_f32x4_mul(cos_reduced_first_f32x4, cos_reduced_second_f32x4), cos_lambda_f32x4,
|
|
500
|
+
wasm_f32x4_mul(sin_reduced_first_f32x4, sin_reduced_second_f32x4));
|
|
501
|
+
|
|
502
|
+
// angular_distance_f32x4 = atan2(sin, cos)
|
|
503
|
+
angular_distance_f32x4 = nk_f32x4_atan2_v128relaxed_(sin_angular_distance_f32x4, cos_angular_distance_f32x4);
|
|
504
|
+
|
|
505
|
+
// sin(azimuth) = cos(U1) * cos(U2) * sin(l) / sin(angular_distance_f32x4)
|
|
506
|
+
// relaxed_laneselect: 1 instruction (vblendvps) vs 3 (vpand+vpandn+vpor) on x86.
|
|
507
|
+
// Safe because mask is from comparison (all-ones or all-zeros per lane).
|
|
508
|
+
v128_t safe_sin_angular_i32x4 = wasm_i32x4_relaxed_laneselect(one_f32x4, sin_angular_distance_f32x4,
|
|
509
|
+
coincident_mask_i32x4);
|
|
510
|
+
sin_azimuth_f32x4 = wasm_f32x4_div(
|
|
511
|
+
wasm_f32x4_mul(wasm_f32x4_mul(cos_reduced_first_f32x4, cos_reduced_second_f32x4), sin_lambda_f32x4),
|
|
512
|
+
safe_sin_angular_i32x4);
|
|
513
|
+
cos_squared_azimuth_f32x4 = wasm_f32x4_relaxed_nmadd(sin_azimuth_f32x4, sin_azimuth_f32x4, one_f32x4);
|
|
514
|
+
|
|
515
|
+
// Handle equatorial case: cos^2(a) ~ 0
|
|
516
|
+
v128_t equatorial_mask_f32x4 = wasm_f32x4_lt(cos_squared_azimuth_f32x4, epsilon_f32x4);
|
|
517
|
+
v128_t safe_cos_sq_azimuth_i32x4 = wasm_i32x4_relaxed_laneselect(one_f32x4, cos_squared_azimuth_f32x4,
|
|
518
|
+
equatorial_mask_f32x4);
|
|
519
|
+
|
|
520
|
+
// cos(2sm) = cos(s) - 2 * sin(U1) * sin(U2) / cos^2(a)
|
|
521
|
+
v128_t sin_product_f32x4 = wasm_f32x4_mul(sin_reduced_first_f32x4, sin_reduced_second_f32x4);
|
|
522
|
+
cos_double_angular_midpoint_f32x4 = wasm_f32x4_sub(
|
|
523
|
+
cos_angular_distance_f32x4,
|
|
524
|
+
wasm_f32x4_div(wasm_f32x4_mul(two_f32x4, sin_product_f32x4), safe_cos_sq_azimuth_i32x4));
|
|
525
|
+
cos_double_angular_midpoint_f32x4 = wasm_i32x4_relaxed_laneselect(
|
|
526
|
+
wasm_f32x4_splat(0.0f), cos_double_angular_midpoint_f32x4, equatorial_mask_f32x4);
|
|
527
|
+
|
|
528
|
+
// C = f/16 * cos^2(a) * (4 + f*(4 - 3*cos^2(a)))
|
|
529
|
+
v128_t correction_factor_f32x4 = wasm_f32x4_mul(
|
|
530
|
+
wasm_f32x4_div(flattening_f32x4, sixteen_f32x4),
|
|
531
|
+
wasm_f32x4_mul(
|
|
532
|
+
cos_squared_azimuth_f32x4,
|
|
533
|
+
wasm_f32x4_relaxed_madd(flattening_f32x4,
|
|
534
|
+
wasm_f32x4_relaxed_nmadd(three_f32x4, cos_squared_azimuth_f32x4, four_f32x4),
|
|
535
|
+
four_f32x4)));
|
|
536
|
+
|
|
537
|
+
// l' = L + (1-C) * f * sin(a) * (s + C * sin(s) * (cos(2sm) + C * cos(s) * (-1 + 2 * cos^2(2sm))))
|
|
538
|
+
v128_t cos_2sm_sq_f32x4 = wasm_f32x4_mul(cos_double_angular_midpoint_f32x4, cos_double_angular_midpoint_f32x4);
|
|
539
|
+
v128_t innermost_f32x4 = wasm_f32x4_relaxed_madd(two_f32x4, cos_2sm_sq_f32x4, wasm_f32x4_splat(-1.0f));
|
|
540
|
+
v128_t middle_f32x4 = wasm_f32x4_relaxed_madd(
|
|
541
|
+
wasm_f32x4_mul(correction_factor_f32x4, cos_angular_distance_f32x4), innermost_f32x4,
|
|
542
|
+
cos_double_angular_midpoint_f32x4);
|
|
543
|
+
v128_t inner_f32x4 = wasm_f32x4_mul(wasm_f32x4_mul(correction_factor_f32x4, sin_angular_distance_f32x4),
|
|
544
|
+
middle_f32x4);
|
|
545
|
+
|
|
546
|
+
v128_t lambda_new_f32x4 = wasm_f32x4_relaxed_madd(
|
|
547
|
+
wasm_f32x4_mul(wasm_f32x4_mul(wasm_f32x4_sub(one_f32x4, correction_factor_f32x4), flattening_f32x4),
|
|
548
|
+
sin_azimuth_f32x4),
|
|
549
|
+
wasm_f32x4_add(angular_distance_f32x4, inner_f32x4), longitude_difference_f32x4);
|
|
550
|
+
|
|
551
|
+
// Check convergence: |l - l'| < threshold
|
|
552
|
+
v128_t lambda_diff_f32x4 = wasm_f32x4_sub(lambda_new_f32x4, lambda_f32x4);
|
|
553
|
+
v128_t lambda_diff_abs_f32x4 = wasm_f32x4_abs(lambda_diff_f32x4);
|
|
554
|
+
v128_t newly_converged_f32x4 = wasm_f32x4_lt(lambda_diff_abs_f32x4, convergence_threshold_f32x4);
|
|
555
|
+
converged_mask_i32x4 = wasm_v128_or(converged_mask_i32x4, newly_converged_f32x4);
|
|
556
|
+
|
|
557
|
+
// Only update lambda_f32x4 for non-converged lanes
|
|
558
|
+
// relaxed_laneselect: 1 instruction (vblendvps) vs 3 (vpand+vpandn+vpor) on x86.
|
|
559
|
+
// Safe because mask is from comparison (all-ones or all-zeros per lane).
|
|
560
|
+
lambda_f32x4 = wasm_i32x4_relaxed_laneselect(lambda_f32x4, lambda_new_f32x4, converged_mask_i32x4);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Final distance calculation
|
|
564
|
+
v128_t a_sq_f32x4 = wasm_f32x4_mul(equatorial_radius_f32x4, equatorial_radius_f32x4);
|
|
565
|
+
v128_t b_sq_f32x4 = wasm_f32x4_mul(polar_radius_f32x4, polar_radius_f32x4);
|
|
566
|
+
v128_t u_squared_f32x4 = wasm_f32x4_div(
|
|
567
|
+
wasm_f32x4_mul(cos_squared_azimuth_f32x4, wasm_f32x4_sub(a_sq_f32x4, b_sq_f32x4)), b_sq_f32x4);
|
|
568
|
+
|
|
569
|
+
// A = 1 + u^2/16384 * (4096 + u^2*(-768 + u^2*(320 - 175*u^2)))
|
|
570
|
+
v128_t series_a_f32x4 = wasm_f32x4_relaxed_madd(u_squared_f32x4, wasm_f32x4_splat(-175.0f),
|
|
571
|
+
wasm_f32x4_splat(320.0f));
|
|
572
|
+
series_a_f32x4 = wasm_f32x4_relaxed_madd(u_squared_f32x4, series_a_f32x4, wasm_f32x4_splat(-768.0f));
|
|
573
|
+
series_a_f32x4 = wasm_f32x4_relaxed_madd(u_squared_f32x4, series_a_f32x4, wasm_f32x4_splat(4096.0f));
|
|
574
|
+
series_a_f32x4 = wasm_f32x4_relaxed_madd(wasm_f32x4_div(u_squared_f32x4, wasm_f32x4_splat(16384.0f)),
|
|
575
|
+
series_a_f32x4, one_f32x4);
|
|
576
|
+
|
|
577
|
+
// B = u^2/1024 * (256 + u^2*(-128 + u^2*(74 - 47*u^2)))
|
|
578
|
+
v128_t series_b_f32x4 = wasm_f32x4_relaxed_madd(u_squared_f32x4, wasm_f32x4_splat(-47.0f), wasm_f32x4_splat(74.0f));
|
|
579
|
+
series_b_f32x4 = wasm_f32x4_relaxed_madd(u_squared_f32x4, series_b_f32x4, wasm_f32x4_splat(-128.0f));
|
|
580
|
+
series_b_f32x4 = wasm_f32x4_relaxed_madd(u_squared_f32x4, series_b_f32x4, wasm_f32x4_splat(256.0f));
|
|
581
|
+
series_b_f32x4 = wasm_f32x4_mul(wasm_f32x4_div(u_squared_f32x4, wasm_f32x4_splat(1024.0f)), series_b_f32x4);
|
|
582
|
+
|
|
583
|
+
// Delta-sigma calculation
|
|
584
|
+
v128_t cos_2sm_sq_f32x4 = wasm_f32x4_mul(cos_double_angular_midpoint_f32x4, cos_double_angular_midpoint_f32x4);
|
|
585
|
+
v128_t sin_sq_f32x4 = wasm_f32x4_mul(sin_angular_distance_f32x4, sin_angular_distance_f32x4);
|
|
586
|
+
v128_t term1_f32x4 = wasm_f32x4_relaxed_madd(two_f32x4, cos_2sm_sq_f32x4, wasm_f32x4_splat(-1.0f));
|
|
587
|
+
term1_f32x4 = wasm_f32x4_mul(cos_angular_distance_f32x4, term1_f32x4);
|
|
588
|
+
v128_t term2_f32x4 = wasm_f32x4_relaxed_madd(four_f32x4, sin_sq_f32x4, wasm_f32x4_splat(-3.0f));
|
|
589
|
+
v128_t term3_f32x4 = wasm_f32x4_relaxed_madd(four_f32x4, cos_2sm_sq_f32x4, wasm_f32x4_splat(-3.0f));
|
|
590
|
+
term2_f32x4 = wasm_f32x4_mul(
|
|
591
|
+
wasm_f32x4_mul(wasm_f32x4_div(series_b_f32x4, six_f32x4), cos_double_angular_midpoint_f32x4),
|
|
592
|
+
wasm_f32x4_mul(term2_f32x4, term3_f32x4));
|
|
593
|
+
v128_t delta_sigma_f32x4 = wasm_f32x4_mul(
|
|
594
|
+
series_b_f32x4, wasm_f32x4_mul(sin_angular_distance_f32x4,
|
|
595
|
+
wasm_f32x4_add(cos_double_angular_midpoint_f32x4,
|
|
596
|
+
wasm_f32x4_mul(wasm_f32x4_div(series_b_f32x4, four_f32x4),
|
|
597
|
+
wasm_f32x4_sub(term1_f32x4, term2_f32x4)))));
|
|
598
|
+
|
|
599
|
+
// s = b * A * (s - ds)
|
|
600
|
+
v128_t distances_f32x4 = wasm_f32x4_mul(wasm_f32x4_mul(polar_radius_f32x4, series_a_f32x4),
|
|
601
|
+
wasm_f32x4_sub(angular_distance_f32x4, delta_sigma_f32x4));
|
|
602
|
+
|
|
603
|
+
// Set coincident points to zero
|
|
604
|
+
// relaxed_laneselect: 1 instruction (vblendvps) vs 3 (vpand+vpandn+vpor) on x86.
|
|
605
|
+
// Safe because mask is from comparison (all-ones or all-zeros per lane).
|
|
606
|
+
distances_f32x4 = wasm_i32x4_relaxed_laneselect(wasm_f32x4_splat(0.0f), distances_f32x4, coincident_mask_i32x4);
|
|
607
|
+
|
|
608
|
+
return distances_f32x4;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
NK_PUBLIC void nk_vincenty_f32_v128relaxed( //
|
|
612
|
+
nk_f32_t const *a_lats, nk_f32_t const *a_lons, //
|
|
613
|
+
nk_f32_t const *b_lats, nk_f32_t const *b_lons, //
|
|
614
|
+
nk_size_t n, nk_f32_t *results) {
|
|
615
|
+
|
|
616
|
+
while (n >= 4) {
|
|
617
|
+
v128_t first_latitudes_f32x4 = wasm_v128_load(a_lats);
|
|
618
|
+
v128_t first_longitudes_f32x4 = wasm_v128_load(a_lons);
|
|
619
|
+
v128_t second_latitudes_f32x4 = wasm_v128_load(b_lats);
|
|
620
|
+
v128_t second_longitudes_f32x4 = wasm_v128_load(b_lons);
|
|
621
|
+
|
|
622
|
+
v128_t distances_f32x4 = nk_vincenty_f32x4_v128relaxed_(first_latitudes_f32x4, first_longitudes_f32x4,
|
|
623
|
+
second_latitudes_f32x4, second_longitudes_f32x4);
|
|
624
|
+
wasm_v128_store(results, distances_f32x4);
|
|
625
|
+
|
|
626
|
+
a_lats += 4, a_lons += 4, b_lats += 4, b_lons += 4, results += 4, n -= 4;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Handle remaining elements with partial loads (n can be 1-3 here)
|
|
630
|
+
if (n > 0) {
|
|
631
|
+
nk_b128_vec_t a_lat_vec, a_lon_vec, b_lat_vec, b_lon_vec, result_vec;
|
|
632
|
+
nk_partial_load_b32x4_serial_(a_lats, &a_lat_vec, n);
|
|
633
|
+
nk_partial_load_b32x4_serial_(a_lons, &a_lon_vec, n);
|
|
634
|
+
nk_partial_load_b32x4_serial_(b_lats, &b_lat_vec, n);
|
|
635
|
+
nk_partial_load_b32x4_serial_(b_lons, &b_lon_vec, n);
|
|
636
|
+
v128_t distances_f32x4 = nk_vincenty_f32x4_v128relaxed_(a_lat_vec.v128, a_lon_vec.v128, b_lat_vec.v128,
|
|
637
|
+
b_lon_vec.v128);
|
|
638
|
+
result_vec.v128 = distances_f32x4;
|
|
639
|
+
nk_partial_store_b32x4_serial_(&result_vec, results, n);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
#if defined(__clang__)
|
|
644
|
+
#pragma clang attribute pop
|
|
645
|
+
#endif
|
|
646
|
+
|
|
647
|
+
#if defined(__cplusplus)
|
|
648
|
+
} // extern "C"
|
|
649
|
+
#endif
|
|
650
|
+
|
|
651
|
+
#endif // NK_TARGET_V128RELAXED
|
|
652
|
+
#endif // NK_GEOSPATIAL_V128RELAXED_H
|