examples/geohash: first version
Adds helper for constants as DATA sections.
This commit is contained in:
@@ -58,3 +58,5 @@ func Load(src gotypes.Component, dst reg.Register) reg.Register { return ctx.Loa
|
||||
func Store(src reg.Register, dst gotypes.Component) { ctx.Store(src, dst) }
|
||||
|
||||
func AllocLocal(size int) operand.Mem { return ctx.AllocLocal(size) }
|
||||
|
||||
func ConstData(name string, v operand.Constant) operand.Mem { return ctx.ConstData(name, v) }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/mmcloughlin/avo/operand"
|
||||
"github.com/mmcloughlin/avo/reg"
|
||||
|
||||
"github.com/mmcloughlin/avo/gotypes"
|
||||
@@ -42,3 +43,9 @@ func (c *Context) Store(src reg.Register, dst gotypes.Component) {
|
||||
}
|
||||
c.mov(src, b.Addr, int(src.Bytes()), int(gotypes.Sizes.Sizeof(b.Type)), b.Type)
|
||||
}
|
||||
|
||||
func (c *Context) ConstData(name string, v operand.Constant) operand.Mem {
|
||||
g := c.StaticGlobal(name)
|
||||
c.AppendDatum(v)
|
||||
return g
|
||||
}
|
||||
|
||||
40
examples/geohash/asm.go
Normal file
40
examples/geohash/asm.go
Normal 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()
|
||||
}
|
||||
34
examples/geohash/geohash.s
Normal file
34
examples/geohash/geohash.s
Normal 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
|
||||
13
examples/geohash/geohash_test.go
Normal file
13
examples/geohash/geohash_test.go
Normal 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
5
examples/geohash/stub.go
Normal 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
|
||||
Reference in New Issue
Block a user