diff --git a/countlines_arm64.go b/countlines_arm64.go new file mode 100644 index 0000000..07090c7 --- /dev/null +++ b/countlines_arm64.go @@ -0,0 +1,14 @@ +//go:build arm64 && !gccgo && !appengine + +package countlines + +func CountNewlines(s []byte) uint64 { + if len(s) == 0 { + return 0 + } + + return countNewlinesASM(&s[0], uint64(len(s))) +} + +//go:noescape +func countNewlinesASM(src *byte, len uint64) (ret uint64) diff --git a/countlines_arm64.s b/countlines_arm64.s index 9076c5d..a4ecd3a 100644 --- a/countlines_arm64.s +++ b/countlines_arm64.s @@ -3,11 +3,11 @@ #include "textflag.h" TEXT ·countNewlinesASM(SB),NOSPLIT,$0 - MOVQ src+0(FP), R1 - MOVQ len+8(FP), R2 + MOVD src+0(FP), R1 + MOVD len+8(FP), R2 MOVD ZR, R0 - VMOVI $0x0A V23.B16 + VMOVI $0x0A, V23.B16 CMP $16, R2 BLT tail @@ -65,7 +65,8 @@ tail: next: SUB $1, R2 - JNZ tail + CMP ZR, R2 + BNE tail ret: diff --git a/countlines_generic.go b/countlines_generic.go index aad9afe..63c9469 100644 --- a/countlines_generic.go +++ b/countlines_generic.go @@ -1,4 +1,4 @@ -//go:build !amd64 || gccgo || appengine +//go:build (!amd64 && !arm64) || gccgo || appengine package countlines