Skip to content

Commit cffe105

Browse files
authored
Merge pull request swiftlang#41964 from Catfish-Man/single-instruction-multiple-ifdef
Only use SIMD when stdlib vector types are available
2 parents db4a7e6 + c05e47d commit cffe105

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ function(_add_target_variant_swift_compile_flags
300300
if(SWIFT_STDLIB_ENABLE_UNICODE_DATA)
301301
list(APPEND result "-D" "SWIFT_STDLIB_ENABLE_UNICODE_DATA")
302302
endif()
303+
304+
if(SWIFT_STDLIB_ENABLE_VECTOR_TYPES)
305+
list(APPEND result "-D" "SWIFT_STDLIB_ENABLE_VECTOR_TYPES")
306+
endif()
303307

304308
if(SWIFT_STDLIB_HAS_COMMANDLINE)
305309
list(APPEND result "-D" "SWIFT_STDLIB_HAS_COMMANDLINE")

stdlib/public/core/StringUTF16View.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ extension _StringGuts {
520520

521521
extension String.UTF16View {
522522

523+
#if SWIFT_STDLIB_ENABLE_VECTOR_TYPES
523524
@inline(__always)
524525
internal func _utf16Length<U: SIMD, S: SIMD>(
525526
readPtr: inout UnsafeRawPointer,
@@ -551,6 +552,7 @@ extension String.UTF16View {
551552

552553
return utf16Count
553554
}
555+
#endif
554556

555557
@inline(__always)
556558
internal func _utf16Distance(from start: Index, to end: Index) -> Int {
@@ -576,6 +578,7 @@ extension String.UTF16View {
576578
readPtr += 1
577579
}
578580

581+
#if SWIFT_STDLIB_ENABLE_VECTOR_TYPES
579582
// TODO: Currently, using SIMD sizes above SIMD8 is slower
580583
// Once that's fixed we should go up to SIMD64 here
581584

@@ -605,6 +608,7 @@ extension String.UTF16View {
605608
return 0
606609
}
607610
}
611+
#endif
608612

609613
//trailing bytes
610614
while readPtr < endPtr {

0 commit comments

Comments
 (0)