authorgravatar for cgburgess10@gmail.comChris Burgess <cgburgess10@gmail.com> 2026-10-21 21:02:25+00:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-22 20:36:32+02:00
log3cc91ba1495c486ff37ba0073b1d35301b25e2db
tree4c86b2d6b44fc176eeba660becad020f98198b05
parentd20b0a4ad5992a24be45ebe78533691a5848dd5b
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux.aarch64: declare SVE registers as syscall clobbers

The kernel zeroes P0-P15 and the bits of Z0-Z31 above 128 on syscall. Only declare them when SVE is enabled, since LLVM treats a Z clobber as clobbering the overlapping V register, which would add spills to code built without SVE. closes https://codeberg.org/ziglang/zig/issues/37321

1 files changed, 61 insertions(+), 7 deletions(-)

lib/std/os/linux/aarch64.zig+61-7
......@@ -4,13 +4,67 @@ const SYS = std.os.linux.SYS;
44
55pub const syscall_arg_t = u64;
66
7/// Declared only with SVE, since a Z clobber also clobbers the V register within it.
8const clobbers: std.lang.assembly.Clobbers = if (builtin.zig_backend != .stage2_aarch64 and
9 builtin.cpu.has(.aarch64, .sve)) .{
10 .memory = true,
11 .p0 = true,
12 .p1 = true,
13 .p2 = true,
14 .p3 = true,
15 .p4 = true,
16 .p5 = true,
17 .p6 = true,
18 .p7 = true,
19 .p8 = true,
20 .p9 = true,
21 .p10 = true,
22 .p11 = true,
23 .p12 = true,
24 .p13 = true,
25 .p14 = true,
26 .p15 = true,
27 .z0 = true,
28 .z1 = true,
29 .z2 = true,
30 .z3 = true,
31 .z4 = true,
32 .z5 = true,
33 .z6 = true,
34 .z7 = true,
35 .z8 = true,
36 .z9 = true,
37 .z10 = true,
38 .z11 = true,
39 .z12 = true,
40 .z13 = true,
41 .z14 = true,
42 .z15 = true,
43 .z16 = true,
44 .z17 = true,
45 .z18 = true,
46 .z19 = true,
47 .z20 = true,
48 .z21 = true,
49 .z22 = true,
50 .z23 = true,
51 .z24 = true,
52 .z25 = true,
53 .z26 = true,
54 .z27 = true,
55 .z28 = true,
56 .z29 = true,
57 .z30 = true,
58 .z31 = true,
59} else .{ .memory = true };
60
761pub fn syscall0(
862 number: SYS,
963) u64 {
1064 return asm volatile ("svc #0"
1165 : [ret] "={x0}" (-> u64),
1266 : [number] "{x8}" (@backingInt(number)),
13 : .{ .memory = true });
67 : clobbers);
1468}
1569
1670pub fn syscall1(
......@@ -21,7 +75,7 @@ pub fn syscall1(
2175 : [ret] "={x0}" (-> u64),
2276 : [number] "{x8}" (@backingInt(number)),
2377 [arg1] "{x0}" (arg1),
24 : .{ .memory = true });
78 : clobbers);
2579}
2680
2781pub fn syscall2(
......@@ -34,7 +88,7 @@ pub fn syscall2(
3488 : [number] "{x8}" (@backingInt(number)),
3589 [arg1] "{x0}" (arg1),
3690 [arg2] "{x1}" (arg2),
37 : .{ .memory = true });
91 : clobbers);
3892}
3993
4094pub fn syscall3(
......@@ -49,7 +103,7 @@ pub fn syscall3(
49103 [arg1] "{x0}" (arg1),
50104 [arg2] "{x1}" (arg2),
51105 [arg3] "{x2}" (arg3),
52 : .{ .memory = true });
106 : clobbers);
53107}
54108
55109pub fn syscall4(
......@@ -66,7 +120,7 @@ pub fn syscall4(
66120 [arg2] "{x1}" (arg2),
67121 [arg3] "{x2}" (arg3),
68122 [arg4] "{x3}" (arg4),
69 : .{ .memory = true });
123 : clobbers);
70124}
71125
72126pub fn syscall5(
......@@ -85,7 +139,7 @@ pub fn syscall5(
85139 [arg3] "{x2}" (arg3),
86140 [arg4] "{x3}" (arg4),
87141 [arg5] "{x4}" (arg5),
88 : .{ .memory = true });
142 : clobbers);
89143}
90144
91145pub fn syscall6(
......@@ -106,7 +160,7 @@ pub fn syscall6(
106160 [arg4] "{x3}" (arg4),
107161 [arg5] "{x4}" (arg5),
108162 [arg6] "{x5}" (arg6),
109 : .{ .memory = true });
163 : clobbers);
110164}
111165
112166pub fn clone() callconv(.naked) u64 {