Browse files

Generalize jit generation for fixnum comparison operations

  • Loading branch information...
1 parent 23fd0d9 commit ba653f14f9fbb0581b3456eb1692992c11f94eab @dbussink dbussink committed Jun 3, 2010
Showing with 44 additions and 10 deletions.
  1. +44 −10 vm/llvm/inline_primitive.cpp
View
54 vm/llvm/inline_primitive.cpp
@@ -248,7 +248,12 @@ namespace rubinius {
i.set_result(ops.as_obj(tagged));
}
- static void fixnum_le(JITOperations& ops, Inliner& i) {
+ enum MathOperation {
+ cAdd, cSub, cMultiply, cDivide, cMod,
+ cEqual, cLessThan, cLessThanEqual, cGreaterThan, cGreaterThanEqual
+ };
+
+ static void fixnum_compare(MathOperation op, JITOperations& ops, Inliner& i) {
Value* lint = ops.cast_int(i.recv());
Value* rint = ops.cast_int(i.arg(0));
@@ -270,21 +275,38 @@ namespace rubinius {
ops.set_block(push);
+ Value* performed = 0;
+
+ switch(op) {
+ case cEqual:
+ performed = ops.b().CreateICmpEQ(lint, rint, "fixnum.eq");
+ break;
+ case cLessThan:
+ performed = ops.b().CreateICmpSLT(lint, rint, "fixnum.lt");
+ break;
+ case cLessThanEqual:
+ performed = ops.b().CreateICmpSLE(lint, rint, "fixnum.le");
+ break;
+ case cGreaterThan:
+ performed = ops.b().CreateICmpSGT(lint, rint, "fixnum.gt");
+ break;
+ case cGreaterThanEqual:
+ performed = ops.b().CreateICmpSGE(lint, rint, "fixnum.ge");
+ break;
+ default:
+ abort();
+ }
+
Value* le = ops.b().CreateSelect(
- ops.b().CreateICmpSLE(lint, rint, "fixnums_le_p"),
+ performed,
ops.constant(Qtrue),
ops.constant(Qfalse));
i.exception_safe();
i.set_result(ops.as_obj(le));
}
- enum FloatOperation {
- cAdd, cSub, cMultiply, cDivide, cMod,
- cEqual, cLessThan, cLessThanEqual, cGreaterThan, cGreaterThanEqual
- };
-
- static void float_op(FloatOperation op, Class* klass,
+ static void float_op(MathOperation op, Class* klass,
JITOperations& ops, Inliner& i)
{
Value* self = i.recv();
@@ -343,7 +365,7 @@ namespace rubinius {
i.set_result(ops.b().CreateBitCast(res, ops.ObjType));
}
- static void float_compare(FloatOperation op, Class* klass,
+ static void float_compare(MathOperation op, Class* klass,
JITOperations& ops, Inliner& i)
{
Value* self = i.recv();
@@ -467,9 +489,21 @@ namespace rubinius {
} else if(prim == Primitives::fixnum_neg && count_ == 0) {
inlined_prim = "fixnum_neg";
fixnum_neg(ops_, *this);
+ } else if(prim == Primitives::fixnum_equal && count_ == 1) {
+ inlined_prim = "fixnum_eq";
+ fixnum_compare(cEqual, ops_, *this);
+ } else if(prim == Primitives::fixnum_lt && count_ == 1) {
+ inlined_prim = "fixnum_lt";
+ fixnum_compare(cLessThan, ops_, *this);
} else if(prim == Primitives::fixnum_le && count_ == 1) {
inlined_prim = "fixnum_le";
- fixnum_le(ops_, *this);
+ fixnum_compare(cLessThanEqual, ops_, *this);
+ } else if(prim == Primitives::fixnum_gt && count_ == 1) {
+ inlined_prim = "fixnum_gt";
+ fixnum_compare(cGreaterThan, ops_, *this);
+ } else if(prim == Primitives::fixnum_ge && count_ == 1) {
+ inlined_prim = "fixnum_ge";
+ fixnum_compare(cGreaterThanEqual, ops_, *this);
} else if(prim == Primitives::object_equal && count_ == 1) {
inlined_prim = "object_equal";
object_equal(klass, ops_, *this);

0 comments on commit ba653f1

Please sign in to comment.