examples/geohash: first version

Adds helper for constants as DATA sections.
This commit is contained in:
Michael McLoughlin
2018-12-27 15:44:52 -08:00
parent 5dea46407c
commit 6fc67c1fbc
6 changed files with 101 additions and 0 deletions

40
examples/geohash/asm.go Normal file
View File

@@ -0,0 +1,40 @@
// +build ignore
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
)
func main() {
TEXT("EncodeInt", "func(lat, lng float64) uint64")
lat := Load(Param("lat"), Xv())
lng := Load(Param("lng"), Xv())
MULSD(ConstData("reciprocal180", F64(1/180.0)), lat)
onepointfive := ConstData("onepointfive", F64(1.5))
ADDSD(onepointfive, lat)
MULSD(ConstData("reciprocal360", F64(1/360.0)), lng)
ADDSD(onepointfive, lng)
lngi, lati := GP64v(), GP64v()
MOVQ(lat, lati)
SHRQ(U8(20), lati)
MOVQ(lng, lngi)
SHRQ(U8(20), lngi)
mask := ConstData("mask", U64(0x5555555555555555))
ghsh := GP64v()
PDEPQ(mask, lati, ghsh)
temp := GP64v()
PDEPQ(mask, lngi, temp)
SHLQ(U8(1), temp)
XORQ(temp, ghsh)
Store(ghsh, ReturnIndex(0))
RET()
Generate()
}

View File

@@ -0,0 +1,34 @@
// Code generated by command: go run asm.go -out geohash.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func EncodeInt(lat float64, lng float64) uint64
TEXT ·EncodeInt(SB), 0, $0-24
MOVSD lat(FP), X0
MOVSD lng+8(FP), X1
MULSD reciprocal180<>(SB), X0
ADDSD onepointfive<>(SB), X0
MULSD reciprocal360<>(SB), X1
ADDSD onepointfive<>(SB), X1
MOVQ X0, CX
SHRQ $0x14, CX
MOVQ X1, AX
SHRQ $0x14, AX
PDEPQ mask<>(SB), CX, CX
PDEPQ mask<>(SB), AX, AX
SHLQ $0x01, AX
XORQ AX, CX
MOVQ CX, ret+16(FP)
RET
DATA reciprocal180<>(SB)/8, $(0.005555555555555556)
GLOBL reciprocal180<>(SB), RODATA, $8
DATA onepointfive<>(SB)/8, $(1.5)
GLOBL onepointfive<>(SB), RODATA, $8
DATA reciprocal360<>(SB)/8, $(0.002777777777777778)
GLOBL reciprocal360<>(SB), RODATA, $8
DATA mask<>(SB)/8, $0x5555555555555555
GLOBL mask<>(SB), RODATA, $8

View File

@@ -0,0 +1,13 @@
package geohash
import (
"testing"
)
//go:generate go run asm.go -out geohash.s -stubs stub.go
func TestEncodeIntMountEverest(t *testing.T) {
if EncodeInt(27.988056, 86.925278) != 0xceb7f254240fd612 {
t.Fail()
}
}

5
examples/geohash/stub.go Normal file
View File

@@ -0,0 +1,5 @@
// Code generated by command: go run asm.go -out geohash.s -stubs stub.go. DO NOT EDIT.
package geohash
func EncodeInt(lat float64, lng float64) uint64