Skip to content

Commit 260ea4b

Browse files
brooniewilldeacon
authored andcommitted
selftests: arm64: Factor out utility functions for assembly FP tests
The various floating point test programs written in assembly have a bunch of helper functions and macros which are cut'n'pasted between them. Factor them out into a separate source file which is linked into all of them. We don't include memcmp() since it isn't as generic as it should be and directly branches to report an error in the programs. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 0ba1ce1 commit 260ea4b

File tree

5 files changed

+185
-329
lines changed

5 files changed

+185
-329
lines changed

tools/testing/selftests/arm64/fp/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ TEST_PROGS_EXTENDED := fpsimd-test fpsimd-stress \
99

1010
all: $(TEST_GEN_PROGS) $(TEST_PROGS_EXTENDED)
1111

12-
fpsimd-test: fpsimd-test.o
12+
fpsimd-test: fpsimd-test.o asm-utils.o
1313
$(CC) -nostdlib $^ -o $@
1414
rdvl-sve: rdvl-sve.o rdvl.o
1515
sve-ptrace: sve-ptrace.o
1616
sve-probe-vls: sve-probe-vls.o rdvl.o
17-
sve-test: sve-test.o
17+
sve-test: sve-test.o asm-utils.o
1818
$(CC) -nostdlib $^ -o $@
1919
vec-syscfg: vec-syscfg.o rdvl.o
2020
vlset: vlset.o
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
// Copyright (C) 2015-2021 ARM Limited.
3+
// Original author: Dave Martin <[email protected]>
4+
//
5+
// Utility functions for assembly code.
6+
7+
#include <asm/unistd.h>
8+
#include "assembler.h"
9+
10+
// Print a single character x0 to stdout
11+
// Clobbers x0-x2,x8
12+
function putc
13+
str x0, [sp, #-16]!
14+
15+
mov x0, #1 // STDOUT_FILENO
16+
mov x1, sp
17+
mov x2, #1
18+
mov x8, #__NR_write
19+
svc #0
20+
21+
add sp, sp, #16
22+
ret
23+
endfunction
24+
.globl putc
25+
26+
// Print a NUL-terminated string starting at address x0 to stdout
27+
// Clobbers x0-x3,x8
28+
function puts
29+
mov x1, x0
30+
31+
mov x2, #0
32+
0: ldrb w3, [x0], #1
33+
cbz w3, 1f
34+
add x2, x2, #1
35+
b 0b
36+
37+
1: mov w0, #1 // STDOUT_FILENO
38+
mov x8, #__NR_write
39+
svc #0
40+
41+
ret
42+
endfunction
43+
.globl puts
44+
45+
// Print an unsigned decimal number x0 to stdout
46+
// Clobbers x0-x4,x8
47+
function putdec
48+
mov x1, sp
49+
str x30, [sp, #-32]! // Result can't be > 20 digits
50+
51+
mov x2, #0
52+
strb w2, [x1, #-1]! // Write the NUL terminator
53+
54+
mov x2, #10
55+
0: udiv x3, x0, x2 // div-mod loop to generate the digits
56+
msub x0, x3, x2, x0
57+
add w0, w0, #'0'
58+
strb w0, [x1, #-1]!
59+
mov x0, x3
60+
cbnz x3, 0b
61+
62+
ldrb w0, [x1]
63+
cbnz w0, 1f
64+
mov w0, #'0' // Print "0" for 0, not ""
65+
strb w0, [x1, #-1]!
66+
67+
1: mov x0, x1
68+
bl puts
69+
70+
ldr x30, [sp], #32
71+
ret
72+
endfunction
73+
.globl putdec
74+
75+
// Print an unsigned decimal number x0 to stdout, followed by a newline
76+
// Clobbers x0-x5,x8
77+
function putdecn
78+
mov x5, x30
79+
80+
bl putdec
81+
mov x0, #'\n'
82+
bl putc
83+
84+
ret x5
85+
endfunction
86+
.globl putdecn
87+
88+
// Clobbers x0-x3,x8
89+
function puthexb
90+
str x30, [sp, #-0x10]!
91+
92+
mov w3, w0
93+
lsr w0, w0, #4
94+
bl puthexnibble
95+
mov w0, w3
96+
97+
ldr x30, [sp], #0x10
98+
// fall through to puthexnibble
99+
endfunction
100+
.globl puthexb
101+
102+
// Clobbers x0-x2,x8
103+
function puthexnibble
104+
and w0, w0, #0xf
105+
cmp w0, #10
106+
blo 1f
107+
add w0, w0, #'a' - ('9' + 1)
108+
1: add w0, w0, #'0'
109+
b putc
110+
endfunction
111+
.globl puthexnibble
112+
113+
// x0=data in, x1=size in, clobbers x0-x5,x8
114+
function dumphex
115+
str x30, [sp, #-0x10]!
116+
117+
mov x4, x0
118+
mov x5, x1
119+
120+
0: subs x5, x5, #1
121+
b.lo 1f
122+
ldrb w0, [x4], #1
123+
bl puthexb
124+
b 0b
125+
126+
1: ldr x30, [sp], #0x10
127+
ret
128+
endfunction
129+
.globl dumphex
130+
131+
// Trivial memory copy: copy x2 bytes, starting at address x1, to address x0.
132+
// Clobbers x0-x3
133+
function memcpy
134+
cmp x2, #0
135+
b.eq 1f
136+
0: ldrb w3, [x1], #1
137+
strb w3, [x0], #1
138+
subs x2, x2, #1
139+
b.ne 0b
140+
1: ret
141+
endfunction
142+
.globl memcpy
143+
144+
// Fill x1 bytes starting at x0 with 0xae (for canary purposes)
145+
// Clobbers x1, x2.
146+
function memfill_ae
147+
mov w2, #0xae
148+
b memfill
149+
endfunction
150+
.globl memfill_ae
151+
152+
// Fill x1 bytes starting at x0 with 0.
153+
// Clobbers x1, x2.
154+
function memclr
155+
mov w2, #0
156+
endfunction
157+
.globl memclr
158+
// fall through to memfill
159+
160+
// Trivial memory fill: fill x1 bytes starting at address x0 with byte w2
161+
// Clobbers x1
162+
function memfill
163+
cmp x1, #0
164+
b.eq 1f
165+
166+
0: strb w2, [x0], #1
167+
subs x1, x1, #1
168+
b.ne 0b
169+
170+
1: ret
171+
endfunction
172+
.globl memfill

tools/testing/selftests/arm64/fp/assembler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,15 @@ endfunction
5454
.purgem \name\()_entry
5555
.endm
5656

57+
// Utility macro to print a literal string
58+
// Clobbers x0-x4,x8
59+
.macro puts string
60+
.pushsection .rodata.str1.1, "aMS", 1
61+
.L__puts_literal\@: .string "\string"
62+
.popsection
63+
64+
ldr x0, =.L__puts_literal\@
65+
bl puts
66+
.endm
67+
5768
#endif /* ! ASSEMBLER_H */

tools/testing/selftests/arm64/fp/fpsimd-test.S

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -33,131 +33,6 @@
3333
define_accessor setv, NVR, _vldr
3434
define_accessor getv, NVR, _vstr
3535

36-
// Print a single character x0 to stdout
37-
// Clobbers x0-x2,x8
38-
function putc
39-
str x0, [sp, #-16]!
40-
41-
mov x0, #1 // STDOUT_FILENO
42-
mov x1, sp
43-
mov x2, #1
44-
mov x8, #__NR_write
45-
svc #0
46-
47-
add sp, sp, #16
48-
ret
49-
endfunction
50-
51-
// Print a NUL-terminated string starting at address x0 to stdout
52-
// Clobbers x0-x3,x8
53-
function puts
54-
mov x1, x0
55-
56-
mov x2, #0
57-
0: ldrb w3, [x0], #1
58-
cbz w3, 1f
59-
add x2, x2, #1
60-
b 0b
61-
62-
1: mov w0, #1 // STDOUT_FILENO
63-
mov x8, #__NR_write
64-
svc #0
65-
66-
ret
67-
endfunction
68-
69-
// Utility macro to print a literal string
70-
// Clobbers x0-x4,x8
71-
.macro puts string
72-
.pushsection .rodata.str1.1, "aMS", 1
73-
.L__puts_literal\@: .string "\string"
74-
.popsection
75-
76-
ldr x0, =.L__puts_literal\@
77-
bl puts
78-
.endm
79-
80-
// Print an unsigned decimal number x0 to stdout
81-
// Clobbers x0-x4,x8
82-
function putdec
83-
mov x1, sp
84-
str x30, [sp, #-32]! // Result can't be > 20 digits
85-
86-
mov x2, #0
87-
strb w2, [x1, #-1]! // Write the NUL terminator
88-
89-
mov x2, #10
90-
0: udiv x3, x0, x2 // div-mod loop to generate the digits
91-
msub x0, x3, x2, x0
92-
add w0, w0, #'0'
93-
strb w0, [x1, #-1]!
94-
mov x0, x3
95-
cbnz x3, 0b
96-
97-
ldrb w0, [x1]
98-
cbnz w0, 1f
99-
mov w0, #'0' // Print "0" for 0, not ""
100-
strb w0, [x1, #-1]!
101-
102-
1: mov x0, x1
103-
bl puts
104-
105-
ldr x30, [sp], #32
106-
ret
107-
endfunction
108-
109-
// Print an unsigned decimal number x0 to stdout, followed by a newline
110-
// Clobbers x0-x5,x8
111-
function putdecn
112-
mov x5, x30
113-
114-
bl putdec
115-
mov x0, #'\n'
116-
bl putc
117-
118-
ret x5
119-
endfunction
120-
121-
122-
// Clobbers x0-x3,x8
123-
function puthexb
124-
str x30, [sp, #-0x10]!
125-
126-
mov w3, w0
127-
lsr w0, w0, #4
128-
bl puthexnibble
129-
mov w0, w3
130-
131-
ldr x30, [sp], #0x10
132-
// fall through to puthexnibble
133-
endfunction
134-
// Clobbers x0-x2,x8
135-
function puthexnibble
136-
and w0, w0, #0xf
137-
cmp w0, #10
138-
blo 1f
139-
add w0, w0, #'a' - ('9' + 1)
140-
1: add w0, w0, #'0'
141-
b putc
142-
endfunction
143-
144-
// x0=data in, x1=size in, clobbers x0-x5,x8
145-
function dumphex
146-
str x30, [sp, #-0x10]!
147-
148-
mov x4, x0
149-
mov x5, x1
150-
151-
0: subs x5, x5, #1
152-
b.lo 1f
153-
ldrb w0, [x4], #1
154-
bl puthexb
155-
b 0b
156-
157-
1: ldr x30, [sp], #0x10
158-
ret
159-
endfunction
160-
16136
// Declare some storate space to shadow the SVE register contents:
16237
.pushsection .text
16338
.data
@@ -168,18 +43,6 @@ scratch:
16843
.space MAXVL_B
16944
.popsection
17045

171-
// Trivial memory copy: copy x2 bytes, starting at address x1, to address x0.
172-
// Clobbers x0-x3
173-
function memcpy
174-
cmp x2, #0
175-
b.eq 1f
176-
0: ldrb w3, [x1], #1
177-
strb w3, [x0], #1
178-
subs x2, x2, #1
179-
b.ne 0b
180-
1: ret
181-
endfunction
182-
18346
// Generate a test pattern for storage in SVE registers
18447
// x0: pid (16 bits)
18548
// x1: register number (6 bits)
@@ -227,33 +90,6 @@ function setup_vreg
22790
ret x4
22891
endfunction
22992

230-
// Fill x1 bytes starting at x0 with 0xae (for canary purposes)
231-
// Clobbers x1, x2.
232-
function memfill_ae
233-
mov w2, #0xae
234-
b memfill
235-
endfunction
236-
237-
// Fill x1 bytes starting at x0 with 0.
238-
// Clobbers x1, x2.
239-
function memclr
240-
mov w2, #0
241-
endfunction
242-
// fall through to memfill
243-
244-
// Trivial memory fill: fill x1 bytes starting at address x0 with byte w2
245-
// Clobbers x1
246-
function memfill
247-
cmp x1, #0
248-
b.eq 1f
249-
250-
0: strb w2, [x0], #1
251-
subs x1, x1, #1
252-
b.ne 0b
253-
254-
1: ret
255-
endfunction
256-
25793
// Trivial memory compare: compare x2 bytes starting at address x0 with
25894
// bytes starting at address x1.
25995
// Returns only if all bytes match; otherwise, the program is aborted.

0 commit comments

Comments
 (0)