diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StructRendering.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StructRendering.kt index 19c46daae06..ae9f31f7c7e 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StructRendering.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StructRendering.kt @@ -66,6 +66,7 @@ private fun tryRenderVar(type: Type, name: String): String? = when (type) { CharType, is BoolType -> "char $name" is IntegerType -> "${type.spelling} $name" is FloatingType -> "${type.spelling} $name" + is VectorType -> "${type.spelling} $name" is RecordType -> "${tryRenderStructOrUnion(type.decl.def!!)} $name" is EnumType -> tryRenderVar(type.def.baseType, name) is PointerType -> "void* $name" diff --git a/backend.native/tests/interop/basics/ctypes.def b/backend.native/tests/interop/basics/ctypes.def index a0a11ca243d..a02b35e53a6 100644 --- a/backend.native/tests/interop/basics/ctypes.def +++ b/backend.native/tests/interop/basics/ctypes.def @@ -69,4 +69,16 @@ enum NonStrictEnum1 { enum NonStrictEnum2 { NonStrictEnum2A, NonStrictEnum2B __attribute__((unused)) = 1 -}; \ No newline at end of file +}; + +typedef float __attribute__ ((__vector_size__ (16))) KVector4f; +typedef int __attribute__ ((__vector_size__ (16))) KVector4i32; + +static float sendV4F(KVector4f v) { + return v[0] + 2 * v[1] + 4 * v[2] + 8 * v[3]; +} + +static int sendV4I(KVector4i32 v) { + return v[0] + 2 * v[1] + 4 * v[2] + 8 * v[3]; +} + diff --git a/backend.native/tests/interop/basics/types.kt b/backend.native/tests/interop/basics/types.kt index 17888e3dd07..07a557290a2 100644 --- a/backend.native/tests/interop/basics/types.kt +++ b/backend.native/tests/interop/basics/types.kt @@ -21,4 +21,8 @@ fun main() { assertEquals(1u, StrictEnum2.StrictEnum2B.value) assertEquals(0u, NonStrictEnum1A) assertEquals(1u, NonStrictEnum2B) -} \ No newline at end of file + + assertEquals(49, sendV4I(vectorOf(1, 2, 3, 4))) + assertEquals(49, (sendV4F(vectorOf(1f, 2f, 3f, 4f)) + 0.00001).toInt()) +} + diff --git a/backend.native/tests/interop/objc/msg_send/main.kt b/backend.native/tests/interop/objc/msg_send/main.kt index c16c1dbb7f9..84ba36a842f 100644 --- a/backend.native/tests/interop/objc/msg_send/main.kt +++ b/backend.native/tests/interop/objc/msg_send/main.kt @@ -13,6 +13,7 @@ private fun primitives() { assertEquals(3.14f, PrimitiveTestSubject.floatFn()) assertEquals(3.14, PrimitiveTestSubject.doubleFn()) assertEquals(42, PrimitiveTestSubject.intFn()) + assertEquals(vectorOf(2f, 4f, 5f, 8f), PrimitiveTestSubject.simdFn()) } private fun aggregates() { @@ -44,4 +45,14 @@ private fun aggregates() { assertEquals(3.0f, f3) assertEquals(4.0f, f4) } -} \ No newline at end of file + AggregateTestSubject.simd_quatfFn().useContents { + assertEquals(vectorOf(1f, 4f, 9f, 25f), vector) + } + AggregateTestSubject.geterogeneousSmallFn().useContents { + assertEquals(1, s1) + assertEquals(vectorOf(1f, 4f, 9f, 25f), v2) + assertEquals(3f, f3) + assertEquals(4, i4) + } +} + diff --git a/backend.native/tests/interop/objc/msg_send/messaging.h b/backend.native/tests/interop/objc/msg_send/messaging.h index 12433706251..bb80a427d26 100644 --- a/backend.native/tests/interop/objc/msg_send/messaging.h +++ b/backend.native/tests/interop/objc/msg_send/messaging.h @@ -1,10 +1,12 @@ #import +#include @interface PrimitiveTestSubject : NSObject + (int)intFn; + (float)floatFn; + (double)doubleFn; ++ (simd_float4)simdFn; @end; @@ -45,6 +47,13 @@ typedef struct { // TODO: Add more cases later: SIMD, bitfields. +typedef struct { + short s1; + simd_float4 v2; + float f3; + int i4; +} GeterogeneousSmall; + @interface AggregateTestSubject : NSObject + (SingleFloat)singleFloatFn; @@ -52,5 +61,8 @@ typedef struct { + (EvenSmallerPacked)evenSmallerPackedFn; + (HomogeneousSmall)homogeneousSmallFn; + (HomogeneousBig)homogeneousBigFn; ++ (simd_quatf)simd_quatfFn; ++ (GeterogeneousSmall)geterogeneousSmallFn; + @end; \ No newline at end of file diff --git a/backend.native/tests/interop/objc/msg_send/messaging.m b/backend.native/tests/interop/objc/msg_send/messaging.m index 5b5ff5bad45..6c82209321f 100644 --- a/backend.native/tests/interop/objc/msg_send/messaging.m +++ b/backend.native/tests/interop/objc/msg_send/messaging.m @@ -14,6 +14,15 @@ return 3.14; } ++ (simd_float4)simdFn { + simd_float4 v; + v.x = 2; + v.y = 4; + v.z = 5; + v.w = 8; + return v; +} + @end; @implementation AggregateTestSubject @@ -61,4 +70,12 @@ return s; } ++ (GeterogeneousSmall)geterogeneousSmallFn { + return (GeterogeneousSmall){1, {1, 4, 9, 25}, 3, 4}; +} + ++ (simd_quatf)simd_quatfFn { + return (simd_quatf){ {1, 4, 9, 25} }; +} + @end; \ No newline at end of file