Skip to content

Commit fee3739

Browse files
committed
mask_asm: Note implementation may not be perfect
1 parent a1bb441 commit fee3739

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

Diff for: go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module nhooyr.io/websocket
22

33
go 1.19
4+
5+
require golang.org/x/sys v0.17.0 // indirect

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
2+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

Diff for: mask_arm64.s

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ TEXT ·maskAsm(SB), NOSPLIT, $0-28
1515
CMP $64, R1
1616
BLT less_than_64
1717

18-
// TODO: align memory like amd64
19-
2018
loop_64:
2119
VLD1 (R0), [V1.B16, V2.B16, V3.B16, V4.B16]
2220
VEOR V1.B16, V0.B16, V1.B16
@@ -29,6 +27,7 @@ loop_64:
2927
BGE loop_64
3028

3129
less_than_64:
30+
CBZ R1, end
3231
TBZ $5, R1, less_than_32
3332
VLD1 (R0), [V1.B16, V2.B16]
3433
VEOR V1.B16, V0.B16, V1.B16

Diff for: mask_asm.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
package websocket
44

5+
import "golang.org/x/sys/cpu"
6+
57
func mask(b []byte, key uint32) uint32 {
68
if len(b) > 0 {
79
return maskAsm(&b[0], len(b), key)
810
}
911
return key
1012
}
1113

12-
var useAVX2 = true
14+
var useAVX2 = cpu.X86.HasAVX2
1315

16+
// @nhooyr: I am not confident that the amd64 or the arm64 implementations of this
17+
// function are perfect. There are almost certainly missing optimizations or
18+
// opportunities for // simplification. I'm confident there are no bugs though.
19+
// For example, the arm64 implementation doesn't align memory like the amd64.
20+
// Or the amd64 implementation could use AVX512 instead of just AVX2.
1421
//go:noescape
1522
func maskAsm(b *byte, len int, key uint32) uint32

0 commit comments

Comments
 (0)