Skip to content

Commit b74d54a

Browse files
stephentyroneairspeedswift
authored andcommitted
[5.0] SIMD into stdlib (#20896)
* SIMD into stdlib Implements SE-0229. Also updates simd module types in the Apple SDKs to use the new types, and updates a couple tests to work with the new types and protocols. (cherry picked from commit fb8b9e1) * Move most of the simd operators into an optional module (#20914) * Move most of the simd operators into an optional module Adding simd to the stdlib caused some typechecker regressions. We can resolve them in the near-term by making the types universally available, but moving the arithmetic operators into a separate module that must be explicitly imported. * Move two fuzzing tests back to fixed. * Add SIMDOperators as a dependency for MediaPlayer. * Move the .-prefixed operator declarations back into the stdlib. (cherry picked from commit 28962b5)
1 parent 7f14ddb commit b74d54a

25 files changed

+1174
-354
lines changed

include/swift/Runtime/BuiltinTypes.def

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,43 @@ BUILTIN_VECTOR_TYPE(Bi16_, Int16, 4)
7474
BUILTIN_VECTOR_TYPE(Bi16_, Int16, 8)
7575
BUILTIN_VECTOR_TYPE(Bi16_, Int16, 16)
7676
BUILTIN_VECTOR_TYPE(Bi16_, Int16, 32)
77+
BUILTIN_VECTOR_TYPE(Bi16_, Int16, 64)
7778

7879
// Int32 vector types
7980
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 2)
8081
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 3)
8182
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 4)
8283
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 8)
8384
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 16)
85+
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 32)
86+
BUILTIN_VECTOR_TYPE(Bi32_, Int32, 64)
8487

8588
// Int64 vector types
8689
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 2)
8790
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 3)
8891
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 4)
8992
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 8)
93+
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 16)
94+
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 32)
95+
BUILTIN_VECTOR_TYPE(Bi64_, Int64, 64)
9096

9197
// Float32 vector types
9298
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 2)
9399
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 3)
94100
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 4)
95101
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 8)
96102
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 16)
103+
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 32)
104+
BUILTIN_VECTOR_TYPE(Bf32_, FPIEEE32, 64)
97105

98106
// Float64 vector types
99107
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 2)
100108
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 3)
101109
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 4)
102110
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 8)
111+
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 16)
112+
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 32)
113+
BUILTIN_VECTOR_TYPE(Bf64_, FPIEEE64, 64)
103114

104115
#undef BUILTIN_VECTOR_TYPE
105116
#undef VECTOR_BUILTIN_SYMBOL_NAME

lib/IRGen/GenClangType.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ GenClangType::visitBoundGenericType(CanBoundGenericType type) {
453453
AutoreleasingUnsafeMutablePointer,
454454
Unmanaged,
455455
CFunctionPointer,
456+
SIMD,
456457
} kind = llvm::StringSwitch<StructKind>(swiftStructDecl->getName().str())
457458
.Case("UnsafeMutablePointer", StructKind::UnsafeMutablePointer)
458459
.Case("UnsafePointer", StructKind::UnsafePointer)
@@ -461,6 +462,7 @@ GenClangType::visitBoundGenericType(CanBoundGenericType type) {
461462
StructKind::AutoreleasingUnsafeMutablePointer)
462463
.Case("Unmanaged", StructKind::Unmanaged)
463464
.Case("CFunctionPointer", StructKind::CFunctionPointer)
465+
.StartsWith("SIMD", StructKind::SIMD)
464466
.Default(StructKind::Invalid);
465467

466468
auto args = type.getGenericArgs();
@@ -472,7 +474,7 @@ GenClangType::visitBoundGenericType(CanBoundGenericType type) {
472474
case StructKind::Invalid:
473475
llvm_unreachable("Unexpected non-pointer generic struct type in imported"
474476
" Clang module!");
475-
477+
476478
case StructKind::UnsafeMutablePointer:
477479
case StructKind::Unmanaged:
478480
case StructKind::AutoreleasingUnsafeMutablePointer: {
@@ -499,6 +501,19 @@ GenClangType::visitBoundGenericType(CanBoundGenericType type) {
499501
auto fnPtrTy = clangCtx.getPointerType(functionTy);
500502
return getCanonicalType(fnPtrTy);
501503
}
504+
505+
case StructKind::SIMD: {
506+
clang::QualType scalarTy = Converter.convert(IGM, loweredArgTy);
507+
auto numEltsString = swiftStructDecl->getName().str();
508+
numEltsString.consume_front("SIMD");
509+
unsigned numElts;
510+
bool failedParse = numEltsString.getAsInteger<unsigned>(10, numElts);
511+
assert(!failedParse && "SIMD type name didn't end in count?");
512+
(void) failedParse;
513+
auto vectorTy = getClangASTContext().getVectorType(scalarTy, numElts,
514+
clang::VectorType::VectorKind::GenericVector);
515+
return getCanonicalType(vectorTy);
516+
}
502517
}
503518

504519
llvm_unreachable("Not a valid StructKind.");

stdlib/public/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if(SWIFT_BUILD_STDLIB)
5555
add_subdirectory(runtime)
5656
add_subdirectory(stubs)
5757
add_subdirectory(core)
58+
add_subdirectory(SIMDOperators)
5859
add_subdirectory(SwiftOnoneSupport)
5960
endif()
6061

stdlib/public/SDK/MediaPlayer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_swift_target_library(swiftMediaPlayer ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPE
88
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
99
TARGET_SDKS IOS IOS_SIMULATOR
1010

11-
SWIFT_MODULE_DEPENDS_IOS Darwin AVFoundation CoreAudio CoreFoundation CoreGraphics CoreImage CoreMedia Dispatch Foundation Metal ObjectiveC QuartzCore simd UIKit os CoreData # auto-updated
11+
SWIFT_MODULE_DEPENDS_IOS Darwin AVFoundation CoreAudio CoreFoundation CoreGraphics CoreImage CoreMedia Dispatch Foundation Metal ObjectiveC QuartzCore simd SIMDOperators UIKit os CoreData # auto-updated
1212
FRAMEWORK_DEPENDS_WEAK MediaPlayer
1313

1414
DEPLOYMENT_VERSION_IOS ${SWIFTLIB_DEPLOYMENT_VERSION_MEDIAPLAYER_IOS}

stdlib/public/SDK/SceneKit/SceneKit.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ extension SCNVector3 {
5151
}
5252
}
5353

54-
extension float3 {
54+
extension SIMD3 where Scalar == Float {
5555
public init(_ v: SCNVector3) {
5656
self.init(Float(v.x), Float(v.y), Float(v.z))
5757
}
5858
}
5959

60-
extension double3 {
60+
extension SIMD3 where Scalar == Double {
6161
public init(_ v: SCNVector3) {
6262
self.init(Double(v.x), Double(v.y), Double(v.z))
6363
}
@@ -86,13 +86,13 @@ extension SCNVector4 {
8686
}
8787
}
8888

89-
extension float4 {
89+
extension SIMD4 where Scalar == Float {
9090
public init(_ v: SCNVector4) {
9191
self.init(Float(v.x), Float(v.y), Float(v.z), Float(v.w))
9292
}
9393
}
9494

95-
extension double4 {
95+
extension SIMD4 where Scalar == Double {
9696
public init(_ v: SCNVector4) {
9797
self.init(Double(v.x), Double(v.y), Double(v.z), Double(v.w))
9898
}

stdlib/public/SDK/simd/Quaternion.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import Swift
1616
import Darwin
17+
import SIMDOperators
1718
@_exported import simd
1819

1920
%for scalar in ['Float','Double']:

0 commit comments

Comments
 (0)