Skip to content

Commit 43723a1

Browse files
committed
Future-proof the ARM64 ABI by not reserving the entire top byte.
Targets that want to use armv8.5a memory tagging will need this. Hopefully nobody comes up with a brilliant reason they need to use anything else.
1 parent 0070243 commit 43723a1

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

stdlib/public/SwiftShims/System.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@
136136
/// Darwin reserves the low 4GB of address space.
137137
#define SWIFT_ABI_DARWIN_ARM64_LEAST_VALID_POINTER 0x100000000ULL
138138

139-
// TBI guarantees the top byte of pointers is unused.
139+
// TBI guarantees the top byte of pointers is unused, but ARMv8.5-A
140+
// claims the bottom four bits of that for memory tagging.
140141
// Heap objects are eight-byte aligned.
141-
#define SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK 0xFF00000000000007ULL
142+
#define SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK 0xF000000000000007ULL
142143

143144
// Objective-C reserves just the high bit for tagged pointers.
144145
#define SWIFT_ABI_ARM64_OBJC_RESERVED_BITS_MASK 0x8000000000000000ULL

test/IRGen/bridge_object_arm64.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ entry(%c : $C, %w : $Builtin.Word):
3535
// CHECK: [[TAGGED_RESULT:%.*]] = bitcast [[BRIDGE]] %0 to [[C:%objc_object\*]]
3636
// CHECK: br label %tagged-cont
3737
// CHECK: not-tagged-pointer:
38-
// -- 0x00ff_ffff_ffff_fff8
39-
// CHECK: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
38+
// -- 0x0fff_ffff_ffff_fff8
39+
// CHECK: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 1152921504606846968
4040
// CHECK: [[MASKED_RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C]]
4141
// CHECK: br label %tagged-cont
4242
// CHECK: tagged-cont:

test/IRGen/enum_top_bits_reserved.sil

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %swift -module-name test -emit-ir -target arm64-apple-ios10.0 %s | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-arm64
2+
// RUN: %swift -module-name test -emit-ir -target x86_64-apple-macosx10.12 %s | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-x86_64
3+
4+
class NativeClass {}
5+
sil_vtable NativeClass {}
6+
7+
// On 64-bit targets, there are 3 spare bits in the alignment bits and
8+
// either 4 (arm64) or 8 (everywhere else) spare bits in the high byte.
9+
// Consume those bits one by one.
10+
11+
enum A {
12+
case either(NativeClass)
13+
case or(NativeClass)
14+
}
15+
16+
enum B {
17+
case either(A)
18+
case or(A)
19+
}
20+
21+
enum C {
22+
case either(B)
23+
case or(B)
24+
}
25+
26+
enum D {
27+
case either(C)
28+
case or(C)
29+
}
30+
31+
enum E {
32+
case either(D)
33+
case or(D)
34+
}
35+
36+
enum F {
37+
case either(E)
38+
case or(E)
39+
}
40+
41+
enum G {
42+
case either(F)
43+
case or(F)
44+
}
45+
46+
// Okay, we've claimed 7 spare bits. On ARM64, the eighth spare bit will
47+
// require an extra discriminator.
48+
49+
// CHECK-LABEL: @"$s4test1HOWV" = internal constant %swift.enum_vwtable
50+
// CHECK-x86_64-SAME: i64 8,
51+
// CHECK-x86_64-SAME: i64 8,
52+
// CHECK-arm64-SAME: i64 9,
53+
// CHECK-arm64-SAME: i64 16,
54+
55+
enum H {
56+
case either(G)
57+
case or(G)
58+
}

0 commit comments

Comments
 (0)