Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve jit handling of kind_of primitive

Before:

=== bin/rbx ===
Fixnum#kind_of? => true
                     34028137.9 (±5.7%) i/s -  169423056 in   4.999449s (cycle=186384)
Fixnum#kind_of? => false
                     11741717.9 (±3.0%) i/s -   58727508 in   5.006581s (cycle=256452)
String#kind_of? => true
                      8437280.3 (±3.2%) i/s -   42294912 in   5.018171s (cycle=240312)
String#kind_of? => false
                      6445857.7 (±3.3%) i/s -   32352474 in   5.024960s (cycle=210081)

After:

Fixnum#kind_of? => true
                     52071734.0 (±7.1%) i/s -  258535660 in   4.998787s (cycle=219470)
Fixnum#kind_of? => false
                     13135231.3 (±3.0%) i/s -   65761920 in   5.011189s (cycle=268416)
String#kind_of? => true
                      9416535.3 (±2.6%) i/s -   47279880 in   5.024514s (cycle=262666)
String#kind_of? => false
                      6702445.6 (±2.4%) i/s -   33508800 in   5.002335s (cycle=232700)
  • Loading branch information...
commit b677890cef08d3040a2753c2215048968feba2ff 1 parent e91c4a2
@dbussink dbussink authored
Showing with 76 additions and 18 deletions.
  1. +76 −18 vm/llvm/inline_primitive.cpp
View
94 vm/llvm/inline_primitive.cpp
@@ -856,8 +856,8 @@ namespace rubinius {
i.context().leave_inline();
}
- void type_object_equal() {
- log("type_object_equal");
+ void vm_object_equal() {
+ log("Type.object_equal");
Value* cmp = ops.create_equal(i.arg(0), i.arg(1), "identity_equal");
Value* imm_value = SelectInst::Create(cmp, ops.constant(cTrue),
@@ -884,24 +884,75 @@ namespace rubinius {
i.context().leave_inline();
}
- /*
- void object_class(Class* klass, JITOperations& ops, Inliner& i) {
- Value* self = i.recv();
+ void object_kind_of() {
+ log("Object#kind_of");
+ i.context().enter_inline();
- ops.check_class(self, klass, i.failure());
+ Signature sig(ops.state(), ops.state()->ptr_type("Object"));
+ sig << "State";
+ sig << "Object";
+ sig << "Object";
- Signature sig(ops.state(), "Class");
- sig << "State";
- sig << "Object";
+ Value* call_args[] = { ops.vm(), i.recv(), i.arg(0) };
- Value* call_args[] = { ops.vm(), self };
+ Value* val = sig.call("rbx_kind_of", call_args, 3, "hash", ops.b());
- Value* res = sig.call("rbx_class_of", call_args, 2, "object_class", ops.b());
+ i.exception_safe();
+ i.set_result(val);
+ i.context().leave_inline();
+ }
- i.exception_safe();
- i.set_result(ops.downcast(res));
- }
- */
+ void vm_object_kind_of() {
+ log("Type.object_kind_of");
+ i.context().enter_inline();
+
+ Signature sig(ops.state(), ops.state()->ptr_type("Object"));
+ sig << "State";
+ sig << "Object";
+ sig << "Object";
+
+ Value* call_args[] = { ops.vm(), i.arg(0), i.arg(1) };
+
+ Value* val = sig.call("rbx_kind_of", call_args, 3, "hash", ops.b());
+
+ i.exception_safe();
+ i.set_result(val);
+ i.context().leave_inline();
+ }
+
+ void object_class() {
+ log("Object#class");
+ i.context().enter_inline();
+
+ Signature sig(ops.state(), ops.state()->ptr_type("Object"));
+ sig << "State";
+ sig << "Object";
+
+ Value* call_args[] = { ops.vm(), i.recv() };
+
+ Value* val = sig.call("rbx_class_of", call_args, 2, "object_class", ops.b());
+
+ i.exception_safe();
+ i.set_result(val);
+ i.context().leave_inline();
+ }
+
+ void vm_object_class() {
+ log("Type.object_class");
+ i.context().enter_inline();
+
+ Signature sig(ops.state(), ops.state()->ptr_type("Object"));
+ sig << "State";
+ sig << "Object";
+
+ Value* call_args[] = { ops.vm(), i.arg(0) };
+
+ Value* val = sig.call("rbx_class_of", call_args, 2, "object_class", ops.b());
+
+ i.exception_safe();
+ i.set_result(val);
+ i.context().leave_inline();
+ }
};
@@ -935,6 +986,16 @@ namespace rubinius {
ip.fixnum_compare_operation(cGreaterThanEqual);
} else if(prim == Primitives::object_equal && count_ == 1) {
ip.object_equal();
+ } else if(prim == Primitives::vm_object_equal && count_ == 2) {
+ ip.vm_object_equal();
+ } else if(prim == Primitives::object_kind_of && count_ == 1) {
+ ip.object_kind_of();
+ } else if(prim == Primitives::vm_object_kind_of && count_ == 2) {
+ ip.vm_object_kind_of();
+ } else if(prim == Primitives::object_class && count_ == 0) {
+ ip.object_class();
+ } else if(prim == Primitives::vm_object_class && count_ == 1) {
+ ip.vm_object_class();
} else if(prim == Primitives::float_add && count_ == 1) {
ip.float_op(cAdd);
} else if(prim == Primitives::float_sub && count_ == 1) {
@@ -967,9 +1028,6 @@ namespace rubinius {
ip.symbol_s_eqq();
}
- } else if(prim == Primitives::vm_object_equal && count_ == 2) {
- ip.type_object_equal();
-
} else if(prim == Primitives::class_allocate && count_ == 0) {
ip.class_allocate();
Please sign in to comment.
Something went wrong with that request. Please try again.