@@ -114,6 +114,35 @@ UnsafeMutableRawPointerExtraTestSuite.test("load.unaligned")
114
114
expectEqual ( result, 0xffff_0000 )
115
115
}
116
116
117
+ UnsafeMutableRawPointerExtraTestSuite . test ( " load.unaligned.SIMD " )
118
+ . skip ( . custom( {
119
+ if #available( SwiftStdlib 5 . 7 , * ) { return false }
120
+ return true
121
+ } , reason: " Requires Swift 5.7's stdlib " ) )
122
+ . code {
123
+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
124
+ var bytes : [ UInt8 ] = Array ( 0 ..< 64 )
125
+ var offset = 3
126
+ let vector16 = bytes. withUnsafeBytes { buffer -> SIMD16 < UInt8 > in
127
+ let aligned = buffer. baseAddress!. alignedUp ( for: SIMD16< UInt8> . self )
128
+ offset += buffer. baseAddress!. distance ( to: aligned)
129
+ return buffer. loadUnaligned ( fromByteOffset: offset, as: SIMD16< UInt8> . self )
130
+ }
131
+ expectEqual ( Int ( vector16 [ 0 ] ) , offset)
132
+ var lastIndex = vector16. indices. last!
133
+ expectEqual ( Int ( vector16 [ lastIndex] ) , offset+ lastIndex)
134
+
135
+ offset = 11
136
+ let vector32 = bytes. withUnsafeMutableBytes { buffer -> SIMD32 < UInt8 > in
137
+ let aligned = buffer. baseAddress!. alignedUp ( for: SIMD16< UInt8> . self )
138
+ offset += buffer. baseAddress!. distance ( to: aligned)
139
+ return buffer. loadUnaligned ( fromByteOffset: offset, as: SIMD32< UInt8> . self )
140
+ }
141
+ expectEqual ( Int ( vector32 [ 0 ] ) , offset)
142
+ lastIndex = vector32. indices. last!
143
+ expectEqual ( Int ( vector32 [ lastIndex] ) , offset+ lastIndex)
144
+ }
145
+
117
146
UnsafeMutableRawPointerExtraTestSuite . test ( " load.invalid " )
118
147
. skip ( . custom( { !_isDebugAssertConfiguration( ) } ,
119
148
reason: " This tests a debug precondition.. " ) )
0 commit comments