Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more vectorOf functions to Kotlin Native #5265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,25 @@ public final class Vector128 private constructor() {
@GCUnsafeCall("Kotlin_Interop_Vector4f_of")
public external fun vectorOf(f0: Float, f1: Float, f2: Float, f3: Float): Vector128

@SinceKotlin("1.9")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument doesn't seem right -- this declaration won't appear in Kotlin 1.9. See more details here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-since-kotlin/

@ExperimentalForeignApi
@GCUnsafeCall("Kotlin_Interop_Vector2f64_of")
public external fun vectorOf(f0: Double, f1: Double): Vector128

@SinceKotlin("1.9")
@ExperimentalForeignApi
@GCUnsafeCall("Kotlin_Interop_Vector4i32_of")
public external fun vectorOf(f0: Int, f1: Int, f2: Int, f3: Int): Vector128
public external fun vectorOf(i0: Int, i1: Int, i2: Int, i3: Int): Vector128

@SinceKotlin("1.9")
@ExperimentalForeignApi
@GCUnsafeCall("Kotlin_Interop_Vector2i64_of")
public external fun vectorOf(l0: Long, l1: Long): Vector128

@SinceKotlin("1.9")
@ExperimentalForeignApi
@GCUnsafeCall("Kotlin_Interop_Vector8i16_of")
public external fun vectorOf(s0: Short, s1: Short, s2: Short, s3: Short, s4: Short, s5: Short, s6: Short, s7: Short): Vector128


@SinceKotlin("1.9")
Expand Down
20 changes: 18 additions & 2 deletions kotlin-native/runtime/src/main/cpp/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,27 @@ KVector4f Kotlin_Interop_Vector4f_of(KFloat f0, KFloat f1, KFloat f2, KFloat f3)
* To avoid illegal bitcast from/to function types the following function
* return type MUST be <4 x float> and explicit type cast is done on the variable type.
*/
KVector4f Kotlin_Interop_Vector4i32_of(KInt f0, KInt f1, KInt f2, KInt f3) {
KInt __attribute__ ((__vector_size__(16))) v4i = {f0, f1, f2, f3};

KVector4f Kotlin_Interop_Vector4i32_of(KInt i0, KInt i1, KInt i2, KInt i3) {
KInt __attribute__ ((__vector_size__(16))) v4i = {i0, i1, i2, i3};
return (KVector4f)v4i;
}

KVector4f Kotlin_Interop_Vector8i16_of(KShort s0, KShort s1, KShort s2, KShort s3, KShort s4, KShort s5, KShort s6, KShort s7) {
KShort __attribute__ ((__vector_size__(16))) v8s = {s0, s1, s2, s3, s4, s5, s6, s7};
return (KVector4f)v8s;
}

KVector4f Kotlin_Interop_Vector2i64_of(KLong l0, KLong l1) {
KLong __attribute__ ((__vector_size__(16))) v2l = {l0, l1};
return (KVector4f)v2l;
}

KVector4f Kotlin_Interop_Vector2f64_of(KDouble d0, KDouble d1) {
KDouble __attribute__ ((__vector_size__(16))) v2d = {d0, d1};
return (KVector4f)v2d;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, it makes sense to implement those operations as compiler intrinsics. This would help avoid copy-pasting. The intrinsics are implemented here:


long Kotlin_longTypeProvider() {
return 0;
}
Expand Down