From 1fea5cdac2c976a72f7275cb9c1dc336cbee92a3 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Thu, 21 Nov 2019 14:05:43 +0300 Subject: [PATCH] Use unaligned instructions for simd struct member access (#3596) --- .../backend/konan/llvm/CodeGenerator.kt | 5 ++- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 22 +++++++++---- .../backend/konan/llvm/VariableManager.kt | 4 ++- backend.native/tests/runtime/basic/simd.kt | 31 +++++++++++++++++-- 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt index 918fb5dd3ee..d1353a45066 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt @@ -318,13 +318,12 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, updateRef(value, ptr, onStack = true) } - fun storeAny(value: LLVMValueRef, ptr: LLVMValueRef, onStack: Boolean) { - if (isObjectRef(value)) { + fun storeAny(value: LLVMValueRef, ptr: LLVMValueRef, onStack: Boolean) = if (isObjectRef(value)) { if (onStack) storeStackRef(value, ptr) else storeHeapRef(value, ptr) + null } else { LLVMBuildStore(builder, value, ptr) } - } fun freeze(value: LLVMValueRef, exceptionHandler: ExceptionHandler) { if (isObjectRef(value)) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index c968715201d..d996dd162b2 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.konan.target.CompilerOutputKind +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.descriptorUtil.classId import org.jetbrains.kotlin.resolve.descriptorUtil.module @@ -1476,15 +1477,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map) + if (value.symbol.owner.correspondingPropertySymbol?.owner?.isConst == true) { + evaluateConst(value.symbol.owner.initializer?.expression as IrConst<*>) } else { if (context.config.threadsAreAllowed && value.symbol.owner.isMainOnlyNonPrimitive) { functionGenerationContext.checkMainThread(currentCodeContext.exceptionHandler) @@ -1492,6 +1493,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map(t: T) { + var value = t +} + +class UnalignedC(t: Vector128) { + var smth = 1 + var value = t +} + +fun testBoxingSimple() { + val v = vectorOf(1f, 3.162f, 10f, 31f) + val box: Box = Box(v) + assertEquals(v, box.value, "testBoxingSimple FAILED") +} + +fun testBoxing() { + var u = UnalignedC(vectorOf(0, 1, 2, 3)) + assertEquals(3, u.value.getIntAt(3)) + u.value = vectorOf(0f, 1f, 2f, 3f) + assertEquals(vectorOf(0f, 1f, 2f, 3f), u.value, "testBoxing FAILED") +} + fun testSetGet() { var v4any = vectorOf(0, 1, 2, 3) - (0 until 4).forEach { assertEquals(it, v4any.getIntAt(it)) } + (0 until 4).forEach { assertEquals(it, v4any.getIntAt(it), "testSetGet FAILED for <4 x i32>") } // type punning: set the variable to another runtime type val a = arrayOf(1f, 3.162f, 10f, 31f) v4any = vectorOf(a[0], a[1], a[2], a[3]) - (0 until 4).forEach { assertEquals(a[it], v4any.getFloatAt(it)) } + (0 until 4).forEach { assertEquals(a[it], v4any.getFloatAt(it), "testSetGet FAILED for <4 x float>") } } fun testString() { val v4i = vectorOf(100, 1024, Int.MAX_VALUE, Int.MIN_VALUE) - assertEquals("(0x64, 0x400, 0x7fffffff, 0x80000000)", v4i.toString()) + assertEquals("(0x64, 0x400, 0x7fffffff, 0x80000000)", v4i.toString(), "testString FAILED") } fun testOOB() {