Check out the fancy SSE4/BMI2 single instruction bit interleaving for geohash creation:
|
/* 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.
mkdir build
cd build
cmake ..
make -j12
A fast C99 geohash library which only provide int64 hash result.
GeoHash.
Just copy all files into your project.