[WASM] Optimize varargs without spreads

This commit is contained in:
Igor Yakovlev
2022-10-26 18:44:15 +02:00
committed by teamcity
parent 913ce9d817
commit 346b2f162c
19 changed files with 211 additions and 37 deletions
@@ -17,6 +17,10 @@ import kotlin.wasm.internal.*
public class Array<T> constructor(size: Int) {
internal val storage: WasmAnyArray = WasmAnyArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmAnyArray) : this(check(false) as Int)
/**
* Creates a new array with the specified [size], where each element is calculated by calling the specified
* [init] function.
@@ -10,6 +10,10 @@ import kotlin.wasm.internal.*
public class ByteArray(size: Int) {
internal val storage = WasmByteArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmByteArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Byte) : this(size) {
storage.fill(size, init)
}
@@ -40,6 +44,10 @@ internal fun byteArrayIterator(array: ByteArray) = object : ByteIterator() {
public class CharArray(size: Int) {
internal val storage = WasmCharArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmCharArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Char) : this(size) {
storage.fill(size) { init(it) }
}
@@ -71,6 +79,10 @@ internal fun charArrayIterator(array: CharArray) = object : CharIterator() {
public class ShortArray(size: Int) {
internal val storage = WasmShortArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmShortArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Short) : this(size) {
storage.fill(size, init)
}
@@ -102,6 +114,10 @@ internal fun shortArrayIterator(array: ShortArray) = object : ShortIterator() {
public class IntArray(size: Int) {
internal val storage = WasmIntArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmIntArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Int) : this(size) {
storage.fill(size, init)
}
@@ -133,6 +149,10 @@ internal fun intArrayIterator(array: IntArray) = object : IntIterator() {
public class LongArray(size: Int) {
internal val storage = WasmLongArray (size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmLongArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Long) : this(size) {
storage.fill(size, init)
}
@@ -163,6 +183,10 @@ internal fun longArrayIterator(array: LongArray) = object : LongIterator() {
public class FloatArray(size: Int) {
internal val storage = WasmFloatArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmFloatArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Float) : this(size) {
storage.fill(size, init)
}
@@ -193,6 +217,10 @@ internal fun floatArrayIterator(array: FloatArray) = object : FloatIterator() {
public class DoubleArray(size: Int) {
internal val storage = WasmDoubleArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmDoubleArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Double) : this(size) {
storage.fill(size, init)
}
@@ -223,6 +251,10 @@ internal fun doubleArrayIterator(array: DoubleArray) = object : DoubleIterator()
public class BooleanArray(size: Int) {
internal val storage = WasmByteArray(size)
@Suppress("TYPE_PARAMETER_AS_REIFIED")
@WasmPrimitiveConstructor
internal constructor(storage: WasmByteArray) : this(check(false) as Int)
public constructor(size: Int, init: (Int) -> Boolean) : this(size) {
storage.fill(size) { init(it).toInt().reinterpretAsByte() }
}
@@ -28,7 +28,7 @@ internal fun <To> wasm_ref_test(a: Any?): Boolean =
internal fun <T> wasm_array_copy(destination: T, destinationIndex: Int, source: T, sourceIndex: Int, length: Int): Unit =
implementedAsIntrinsic
internal fun <T> array_new_data0(address: Int, length: Int): WasmCharArray =
internal fun <T> array_new_data0(address: Int, length: Int): T =
implementedAsIntrinsic
@WasmOp(WasmOp.I32_EQ)
@@ -253,6 +253,8 @@ internal annotation class WasmOp(val name: String) {
const val ARRAY_SET = "ARRAY_SET"
const val ARRAY_LEN = "ARRAY_LEN"
const val ARRAY_COPY = "ARRAY_COPY"
const val ARRAY_NEW_DATA = "ARRAY_NEW_DATA"
const val ARRAY_NEW_FIXED = "ARRAY_NEW_FIXED"
const val I31_NEW = "I31_NEW"
const val I31_GET_S = "I31_GET_S"
const val I31_GET_U = "I31_GET_U"