GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit ef89c4e5 authored by Kunshan Wang's avatar Kunshan Wang

Allow comparing between pointers

parent 886a718f
......@@ -73,6 +73,7 @@ trait InstructionExecutor extends InterpreterActions with CommInstExecutor {
val (op2b, op2o) = b2.asIRef
PrimOpHelpers.irefCmp(op, op1b, op1o, op2b, op2o, ctx)
}
case t:AbstractPointerType => PrimOpHelpers.intCmp(op, TypeSizes.WORD_SIZE_BITS.toInt, b1.asPtr, b2.asPtr, ctx)
case _ => throw new UvmRuntimeException(ctx + "Comparison not suitable for type %s".format(opndTy))
}
}
......
......@@ -360,6 +360,66 @@ class UvmInterpreterSpec extends UvmBundleTesterBase {
ctx.closeContext()
}
"Comparing operations" should "work on pointer types" in {
val ctx = microVM.newContext()
val func = ctx.handleFromFunc("@cmpptr")
val a0 = ctx.handleFromPtr("@ptri64", 1)
val a1 = ctx.handleFromPtr("@ptri64", 2)
testFunc(ctx, func, Seq(a0, a1)) { (ctx, th, st, wp) =>
val Seq(eq, ne, ult, ule, ugt, uge, slt, sle, sgt, sge) = ctx.dumpKeepalives(st, 0)
eq.vb.asUInt(1) shouldEqual 0
ne.vb.asUInt(1) shouldEqual 1
ult.vb.asUInt(1) shouldEqual 1
ule.vb.asUInt(1) shouldEqual 1
ugt.vb.asUInt(1) shouldEqual 0
uge.vb.asUInt(1) shouldEqual 0
slt.vb.asUInt(1) shouldEqual 1
sle.vb.asUInt(1) shouldEqual 1
sgt.vb.asUInt(1) shouldEqual 0
sge.vb.asUInt(1) shouldEqual 0
Rebind(st, PassValues(Seq()))
}
testFunc(ctx, func, Seq(a0, a0)) { (ctx, th, st, wp) =>
val Seq(eq, ne, ult, ule, ugt, uge, slt, sle, sgt, sge) = ctx.dumpKeepalives(st, 0)
eq.vb.asUInt(1) shouldEqual 1
ne.vb.asUInt(1) shouldEqual 0
ult.vb.asUInt(1) shouldEqual 0
ule.vb.asUInt(1) shouldEqual 1
ugt.vb.asUInt(1) shouldEqual 0
uge.vb.asUInt(1) shouldEqual 1
slt.vb.asUInt(1) shouldEqual 0
sle.vb.asUInt(1) shouldEqual 1
sgt.vb.asUInt(1) shouldEqual 0
sge.vb.asUInt(1) shouldEqual 1
Rebind(st, PassValues(Seq()))
}
val a2 = ctx.handleFromPtr("@ptri64", -3)
testFunc(ctx, func, Seq(a0, a2)) { (ctx, th, st, wp) =>
val Seq(eq, ne, ult, ule, ugt, uge, slt, sle, sgt, sge) = ctx.dumpKeepalives(st, 0)
eq.vb.asUInt(1) shouldEqual 0
ne.vb.asUInt(1) shouldEqual 1
slt.vb.asUInt(1) shouldEqual 0
sle.vb.asUInt(1) shouldEqual 0
sgt.vb.asUInt(1) shouldEqual 1
sge.vb.asUInt(1) shouldEqual 1
Rebind(st, PassValues(Seq()))
}
ctx.closeContext()
}
"Comparing operations" should "work on float" in {
val ctx = microVM.newContext()
......
......@@ -137,6 +137,26 @@
COMMINST @uvm.thread_exit
}
.funcsig @cmpptr_sig = (@ptri64 @ptri64) -> ()
.funcdef @cmpptr VERSION %v1 <@cmpptr_sig> {
%entry(<@ptri64> %p0 <@ptri64> %p1):
%eq = EQ <@ptri64> %p0 %p1
%ne = NE <@ptri64> %p0 %p1
%ult = ULT <@ptri64> %p0 %p1
%ule = ULE <@ptri64> %p0 %p1
%ugt = UGT <@ptri64> %p0 %p1
%uge = UGE <@ptri64> %p0 %p1
%slt = SLT <@ptri64> %p0 %p1
%sle = SLE <@ptri64> %p0 %p1
%sgt = SGT <@ptri64> %p0 %p1
%sge = SGE <@ptri64> %p0 %p1
[%trap] TRAP <> KEEPALIVE (
%eq %ne %ult %ule %ugt %uge %slt %sle %sgt %sge
)
COMMINST @uvm.thread_exit
}
.funcsig @cmp_f_sig = (@float @float) -> ()
.funcdef @cmp_f VERSION %v1 <@cmp_f_sig> {
%entry(<@float> %p0 <@float> %p1):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment