Skip to content

This is my old updates to geohash-int enabling SSE4/BMI2 single instruction multi-bit deposit and extraction for the fastest bit interleaving possible (plus many other structural improvements, but the base geohash-int repo has diverged from when these changes started a while ago so nothing is cleanly mergable back again).

License

Notifications You must be signed in to change notification settings

mattsta/geohash-int

 
 

Repository files navigation

Feature Hacking Branch

Check out the fancy SSE4/BMI2 single instruction bit interleaving for geohash creation:

geohash-int/geohash.c

Lines 73 to 91 in 599c753

/* If we're compiled with -mbmi2 and running on a Haswell platform (2013+),
* we can compute the z-order curve in ~2.5 CPU cycles per dimension.
* Below, both intrinsic {de,}interleave64 functions take less than 6 CPU
* cycles (as compared with ~18 CPU cycles for the non-intrinsic version). */
#ifdef __BMI2__
#include <immintrin.h>
static const bool _geohashBuiltForBMI2 = true;
static const uint64_t __X = 0x5555555555555555ULL; /* 0x5 = 0101 */
static const uint64_t __Y = 0xAAAAAAAAAAAAAAAAULL; /* 0xA = 1010 */
static uint64_t interleave64(uint32_t x, uint32_t y) {
/* pdep(a, b) = parallel deposit from 'a' according to selector mask 'b' */
return _pdep_u64(x, __X) | _pdep_u64(y, __Y);
}
static void deinterleave64(uint64_t combined, uint32_t *x, uint32_t *y) {
/* pext(a, b) = parallel extract from 'a' according to selector mask 'b' */
*x = (uint32_t)_pext_u64(combined, __X);
*y = (uint32_t)_pext_u64(combined, __Y);
}

Also includes other refactorings against the original geohash-int release from 2014, but code has diverged somewhat since then.

Building:

mkdir build
cd build
cmake ..
make -j12

geohash-int

A fast C99 geohash library which only provide int64 hash result. GeoHash.

Embedding geohash-int

Just copy all files into your project.

About

This is my old updates to geohash-int enabling SSE4/BMI2 single instruction multi-bit deposit and extraction for the fastest bit interleaving possible (plus many other structural improvements, but the base geohash-int repo has diverged from when these changes started a while ago so nothing is cleanly mergable back again).

Resources

License

Stars

Watchers

Forks

Languages

  • C 79.8%
  • C++ 16.0%
  • CMake 4.2%