Debian Codegraph @

internal/encoder/string_scan_arm64.s

raw
1 #include "textflag.h"
2
3 // MASK computes into Vd the mask of the bytes of Vx which may need an escape, using Vt as a temporary:
4 // the lane of such a byte is not zero. See nibbleTables: V8 is the table of the low nibbles, V9 the one of
5 // the high nibbles and V10 has 0x0f in every lane.
6 #define MASK(Vx, Vt, Vd) \
7 VAND V10.B16, Vx.B16, Vt.B16 \
8 VUSHR $4, Vx.B16, Vd.B16 \
9 VTBL Vt.B16, [V8.B16], Vt.B16 \
10 VTBL Vd.B16, [V9.B16], Vd.B16 \
11 VAND Vt.B16, Vd.B16, Vd.B16
12
13 // ANY sets R8 to a value which is not zero if a lane of Vd is not zero.
14 #define ANY(Vd) \
15 VUADDLV Vd.B16, V15 \
16 VMOV V15.H[0], R8
17
18 // func scanStringNEON(p unsafe.Pointer, n int, tables *nibbleTables) int
19 //
20 // It returns 1 if a byte of the n bytes at p may need an escape by the tables, or 0. n is 16 or more.
21 // The blocks of 64 bytes are looked at first, then the blocks of 16 bytes, and the last block overlaps the
22 // previous one.
23 TEXT ·scanStringNEON(SB), NOSPLIT, $0-32
24 MOVD p+0(FP), R0
25 MOVD n+8(FP), R1
26 MOVD tables+16(FP), R2
27
28 VLD1 (R2), [V8.B16, V9.B16]
29 MOVD $0x0f, R4
30 VMOV R4, V10.B16
31
32 MOVD R0, R7 // the address of the block
33 SUB $64, R1, R6
34 ADD R0, R6, R6 // the address of the last block of 64 bytes
35 CMP R6, R7
36 BGT small
37 loop64:
38 VLD1.P 64(R7), [V0.B16, V1.B16, V2.B16, V3.B16]
39 MASK(V0, V4, V5)
40 MASK(V1, V4, V6)
41 VORR V6.B16, V5.B16, V5.B16
42 MASK(V2, V4, V6)
43 VORR V6.B16, V5.B16, V5.B16
44 MASK(V3, V4, V6)
45 VORR V6.B16, V5.B16, V5.B16
46 ANY(V5)
47 CBNZ R8, found
48 CMP R6, R7
49 BLE loop64
50 small:
51 SUB $16, R1, R6
52 ADD R0, R6, R6 // the address of the last block of 16 bytes
53 CMP R6, R7
54 BGT last
55 loop16:
56 VLD1.P 16(R7), [V0.B16]
57 MASK(V0, V4, V5)
58 ANY(V5)
59 CBNZ R8, found
60 CMP R6, R7
61 BLE loop16
62 last:
63 // the last block, which overlaps the previous one unless the blocks ended exactly at n.
64 ADD R0, R1, R4
65 CMP R4, R7
66 BEQ none
67 VLD1 (R6), [V0.B16]
68 MASK(V0, V4, V5)
69 ANY(V5)
70 CBNZ R8, found
71 none:
72 MOVD $0, R8
73 MOVD R8, ret+24(FP)
74 RET
75 found:
76 MOVD $1, R8
77 MOVD R8, ret+24(FP)
78 RET