summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_zjit.rb14
-rw-r--r--zjit/src/codegen.rs11
2 files changed, 21 insertions, 4 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index c937156fa0..6479d7380e 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -73,13 +73,19 @@ class TestZJIT < Test::Unit::TestCase
}, call_threshold: 2
end
- # FIXME: need to call twice because of call threshold 2, but
- # then this fails because of missing FixnumLt
- def test_less_than
+ def test_less_than_true
assert_compiles 'true', %q{
def test(a, b) = a < b
test(2, 5)
- #test(2, 5)
+ test(2, 5)
+ }, call_threshold: 2
+ end
+
+ def test_less_than_false
+ assert_compiles '[false, false]', %q{
+ def test(a, b) = a < b
+ test(5, 2)
+ [test(5, 2), test(2, 2)]
}, call_threshold: 2
end
diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs
index 28e71fc4c5..9117b6d389 100644
--- a/zjit/src/codegen.rs
+++ b/zjit/src/codegen.rs
@@ -117,6 +117,8 @@ fn gen_insn(jit: &mut JITState, asm: &mut Assembler, function: &Function, insn_i
Insn::Return { val } => return Some(gen_return(&jit, asm, *val)?),
Insn::FixnumAdd { left, right, state } => gen_fixnum_add(jit, asm, *left, *right, function.frame_state(*state))?,
Insn::FixnumSub { left, right, state } => gen_fixnum_sub(jit, asm, *left, *right, function.frame_state(*state))?,
+ // TODO(max): Remove FrameState from FixnumLt
+ Insn::FixnumLt { left, right, .. } => gen_fixnum_lt(jit, asm, *left, *right)?,
Insn::GuardType { val, guard_type, state } => gen_guard_type(jit, asm, *val, *guard_type, function.frame_state(*state))?,
Insn::PatchPoint(_) => return Some(()), // For now, rb_zjit_bop_redefined() panics. TODO: leave a patch point and fix rb_zjit_bop_redefined()
_ => {
@@ -216,6 +218,15 @@ fn gen_fixnum_add(jit: &mut JITState, asm: &mut Assembler, left: InsnId, right:
Some(out_val)
}
+/// Compile Fixnum < Fixnum
+fn gen_fixnum_lt(jit: &mut JITState, asm: &mut Assembler, left: InsnId, right: InsnId) -> Option<lir::Opnd> {
+ let left_opnd = jit.get_opnd(left)?;
+ let right_opnd = jit.get_opnd(right)?;
+ asm.cmp(left_opnd, right_opnd);
+ let out_val = asm.csel_l(Qtrue.into(), Qfalse.into());
+ Some(out_val)
+}
+
/// Compile Fixnum - Fixnum
fn gen_fixnum_sub(jit: &mut JITState, asm: &mut Assembler, left: InsnId, right: InsnId, state: &FrameState) -> Option<lir::Opnd> {
let left_opnd = jit.get_opnd(left)?;