| 1 | # geohash |
| 2 | |
| 3 | Integer [geohash](https://en.wikipedia.org/wiki/Geohash) encoding. |
| 4 | |
| 5 | Refer to ["Geohash in Golang Assembly"](https://mmcloughlin.com/posts/geohash-assembly) for implementation details. |
| 6 | |
| 7 | [embedmd]:# (asm.go /func main/ $) |
| 8 | ```go |
| 9 | func main() { |
| 10 | TEXT("EncodeInt", NOSPLIT, "func(lat, lng float64) uint64") |
| 11 | Doc("EncodeInt computes the 64-bit integer geohash of (lat, lng).") |
| 12 | lat := Load(Param("lat"), XMM()) |
| 13 | lng := Load(Param("lng"), XMM()) |
| 14 | |
| 15 | MULSD(ConstData("reciprocal180", F64(1/180.0)), lat) |
| 16 | onepointfive := ConstData("onepointfive", F64(1.5)) |
| 17 | ADDSD(onepointfive, lat) |
| 18 | |
| 19 | MULSD(ConstData("reciprocal360", F64(1/360.0)), lng) |
| 20 | ADDSD(onepointfive, lng) |
| 21 | |
| 22 | lngi, lati := GP64(), GP64() |
| 23 | MOVQ(lat, lati) |
| 24 | SHRQ(U8(20), lati) |
| 25 | MOVQ(lng, lngi) |
| 26 | SHRQ(U8(20), lngi) |
| 27 | |
| 28 | mask := ConstData("mask", U64(0x5555555555555555)) |
| 29 | ghsh := GP64() |
| 30 | PDEPQ(mask, lati, ghsh) |
| 31 | temp := GP64() |
| 32 | PDEPQ(mask, lngi, temp) |
| 33 | SHLQ(U8(1), temp) |
| 34 | XORQ(temp, ghsh) |
| 35 | |
| 36 | Store(ghsh, ReturnIndex(0)) |
| 37 | RET() |
| 38 | |
| 39 | Generate() |
| 40 | } |
| 41 | ``` |