forked from mmcloughlin/avo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b89d211
commit 93b5337
Showing
8 changed files
with
124 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
. "github.com/mmcloughlin/avo/build" | ||
"github.com/mmcloughlin/avo/operand" | ||
"github.com/mmcloughlin/avo/reg" | ||
) | ||
|
||
const ( | ||
OffsetBasis = 0xcbf29ce484222325 | ||
Prime = 0x100000001b3 | ||
) | ||
|
||
func main() { | ||
TEXT("Hash64", "func(data []byte) uint64") | ||
ptr := Load(Param("data").Base(), GP64v()) | ||
n := Load(Param("data").Len(), GP64v()) | ||
|
||
h := reg.RAX | ||
MOVQ(operand.Imm(OffsetBasis), h) | ||
p := GP64v() | ||
MOVQ(operand.Imm(Prime), p) | ||
|
||
LABEL("loop") | ||
CMPQ(n, operand.Imm(0)) | ||
JE(operand.LabelRef("done")) | ||
b := GP64v() | ||
MOVBQZX(operand.Mem{Base: ptr}, b) | ||
XORQ(b, h) | ||
MULQ(p) | ||
INCQ(ptr) | ||
DECQ(n) | ||
|
||
JMP(operand.LabelRef("loop")) | ||
LABEL("done") | ||
Store(h, ReturnIndex(0)) | ||
RET() | ||
Generate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#include "textflag.h" | ||
|
||
// func Hash64(data []byte) uint64 | ||
TEXT ·Hash64(SB),0,$0-32 | ||
MOVQ data_base(FP), CX | ||
MOVQ data_len+8(FP), BX | ||
MOVQ $0xcbf29ce484222325, AX | ||
MOVQ $0x100000001b3, BP | ||
loop: | ||
CMPQ BX, $0x0 | ||
JE done | ||
MOVBQZX (CX), DX | ||
XORQ DX, AX | ||
MULQ BP | ||
INCQ CX | ||
DECQ BX | ||
JMP loop | ||
done: | ||
MOVQ AX, ret+24(FP) | ||
RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fnv1a | ||
|
||
import ( | ||
"hash/fnv" | ||
"testing" | ||
"testing/quick" | ||
) | ||
|
||
//go:generate go run asm.go -out fnv1a.s -stubs stub.go | ||
|
||
func TestHash64(t *testing.T) { | ||
expect := func(data []byte) uint64 { | ||
h := fnv.New64a() | ||
h.Write(data) | ||
return h.Sum64() | ||
} | ||
if err := quick.CheckEqual(Hash64, expect, nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package fnv1a | ||
|
||
func Hash64(data []byte) uint64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters