|
2 | 2 | // RUN: %target-codesign %t.out
|
3 | 3 | // RUN: %target-run %t.out
|
4 | 4 | // REQUIRES: executable_test
|
5 |
| -// UNSUPPORTED: freestanding |
6 | 5 |
|
7 | 6 | import Swift
|
8 | 7 | import StdlibUnittest
|
9 | 8 |
|
10 |
| -var UnsafeRawPointerTestSuite = |
11 |
| - TestSuite("UnsafeRawPointerTestSuite") |
| 9 | +var UnsafeRawPointerTestSuite = TestSuite("UnsafeRawPointerTestSuite") |
12 | 10 |
|
13 |
| -UnsafeRawPointerTestSuite.test("load.unaligned.SIMD") |
| 11 | +UnsafeRawPointerTestSuite.test("load.unaligned.largeAlignment") |
14 | 12 | .skip(.custom({
|
15 |
| - if #available(SwiftStdlib 5.7, *) { return false } |
16 |
| - return true |
17 |
| -}, reason: "Requires Swift 5.7's stdlib")) |
| 13 | + if #available(SwiftStdlib 5.7, *) { return false } else { return true } |
| 14 | +}, reason: "Requires standard library from Swift 5.7")) |
18 | 15 | .code {
|
19 | 16 | guard #available(SwiftStdlib 5.7, *) else { return }
|
20 |
| - var bytes: [UInt8] = Array(0..<64) |
21 | 17 | var offset = 3
|
22 |
| - let vector16 = bytes.withUnsafeBytes { buffer -> SIMD16<UInt8> in |
23 |
| - let aligned = buffer.baseAddress!.alignedUp(for: SIMD16<UInt8>.self) |
| 18 | + let int128 = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: 64) { |
| 19 | + temporary -> Builtin.Int128 in |
| 20 | + let buffer = UnsafeRawBufferPointer(temporary) |
| 21 | + _ = temporary.initialize(from: repeatElement(0, count: 64)) |
| 22 | + // Load a 128-bit floating point value |
| 23 | + let fp = buffer.loadUnaligned(fromByteOffset: offset, as: Builtin.FPIEEE128.self) |
| 24 | + noop(fp) |
| 25 | + temporary.baseAddress!.deinitialize(count: 64) |
| 26 | + _ = temporary.initialize(from: 0..<64) |
| 27 | + let aligned = buffer.baseAddress!.alignedUp(for: Builtin.Int128.self) |
24 | 28 | offset += buffer.baseAddress!.distance(to: aligned)
|
25 |
| - return buffer.loadUnaligned(fromByteOffset: offset, as: SIMD16<UInt8>.self) |
| 29 | + // Load and return a 128-bit integer value |
| 30 | + return buffer.loadUnaligned(fromByteOffset: offset, as: Builtin.Int128.self) |
26 | 31 | }
|
27 |
| - expectEqual(Int(vector16[0]), offset) |
28 |
| - var lastIndex = vector16.indices.last! |
29 |
| - expectEqual(Int(vector16[lastIndex]), offset+lastIndex) |
| 32 | + withUnsafeBytes(of: int128) { |
| 33 | + expectEqual(Int($0[0]), offset) |
| 34 | + let lastIndex = $0.indices.last! |
| 35 | + expectEqual(Int($0[lastIndex]), offset+lastIndex) |
| 36 | + } |
| 37 | +} |
30 | 38 |
|
31 |
| - offset = 11 |
32 |
| - let vector32 = bytes.withUnsafeMutableBytes { buffer -> SIMD32<UInt8> in |
33 |
| - let aligned = buffer.baseAddress!.alignedUp(for: SIMD32<UInt8>.self) |
| 39 | +UnsafeRawPointerTestSuite.test("load.unaligned.largeAlignment.mutablePointer") |
| 40 | +.skip(.custom({ |
| 41 | + if #available(SwiftStdlib 5.7, *) { return false } else { return true } |
| 42 | +}, reason: "Requires standard library from Swift 5.7")) |
| 43 | +.code { |
| 44 | + guard #available(SwiftStdlib 5.7, *) else { return } |
| 45 | + var offset = 11 |
| 46 | + let int128 = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: 64) { |
| 47 | + temporary -> Builtin.Int128 in |
| 48 | + let buffer = UnsafeMutableRawBufferPointer(temporary) |
| 49 | + buffer.copyBytes(from: 0..<64) |
| 50 | + let aligned = buffer.baseAddress!.alignedUp(for: Builtin.Int128.self) |
34 | 51 | offset += buffer.baseAddress!.distance(to: aligned)
|
35 |
| - return buffer.loadUnaligned(fromByteOffset: offset, as: SIMD32<UInt8>.self) |
| 52 | + return buffer.loadUnaligned(fromByteOffset: offset, as: Builtin.Int128.self) |
| 53 | + } |
| 54 | + withUnsafeBytes(of: int128) { |
| 55 | + expectEqual(Int($0[0]), offset) |
| 56 | + let lastIndex = $0.indices.last! |
| 57 | + expectEqual(Int($0[lastIndex]), offset+lastIndex) |
36 | 58 | }
|
37 |
| - expectEqual(Int(vector32[0]), offset) |
38 |
| - lastIndex = vector32.indices.last! |
39 |
| - expectEqual(Int(vector32[lastIndex]), offset+lastIndex) |
40 | 59 | }
|
41 | 60 |
|
42 | 61 | runAllTests()
|
0 commit comments