mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This supports both built-in vector types and the SIMDX<T> Swift types that are used through type aliases like float3. These SIMD types are passed via compatibility structs (with their valued memcpy-d into the ABI compatible struct) as they have special ABI rules. E.g., a float3 is not passed as float3, but as float4 on the ABI level. Previously, we did not expose simd types from Swift to C++ (unless the SIMD types were impoted from clang). rdar://153218744
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-frontend %S/swift-simd-in-cxx.swift -module-name SIMD -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/simd.h
|
|
|
|
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-simd-execution.o
|
|
// RUN: %target-interop-build-swift %S/swift-simd-in-cxx.swift -o %t/swift-simd-execution -Xlinker %t/swift-simd-execution.o -module-name SIMD -Xfrontend -entry-point-function-name -Xfrontend swiftMain
|
|
|
|
// RUN: %target-codesign %t/swift-simd-execution
|
|
// RUN: %target-run %t/swift-simd-execution | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: rdar157848231
|
|
|
|
#include "simd.h"
|
|
#include <assert.h>
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
swift_float3 vec{1.0, 2.0, 3.0};
|
|
SIMD::swiftThingSIMD(vec);
|
|
// CHECK: SIMD3<Float>(1.0, 2.0, 3.0)
|
|
SIMD::swiftThingSIMD2(vec);
|
|
// CHECK: SIMD3<Float>(1.0, 2.0, 3.0)
|
|
swift_float3 vec2 = SIMD::swiftThingSIMD3();
|
|
std::cout << vec2.x << " " << vec2.y << " " << vec2.z << "\n";
|
|
// CHECK: 4 5 6
|
|
vec2 = SIMD::swiftThingSIMD4();
|
|
std::cout << vec2.x << " " << vec2.y << " " << vec2.z << "\n";
|
|
// CHECK: 4 5 6
|
|
return 0;
|
|
}
|
|
|