[macruby-changes] [2250] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 6 21:23:31 PDT 2009
Revision: 2250
http://trac.macosforge.org/projects/ruby/changeset/2250
Author: lsansonetti at apple.com
Date: 2009-08-06 21:23:31 -0700 (Thu, 06 Aug 2009)
Log Message:
-----------
optimize #== and #!= for non fixnum/float types
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
MacRuby/trunk/compiler.h
MacRuby/trunk/vm.cpp
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2009-08-07 04:22:38 UTC (rev 2249)
+++ MacRuby/trunk/compiler.cpp 2009-08-07 04:23:31 UTC (rev 2250)
@@ -64,6 +64,8 @@
return_from_block_ids = 0;
dispatcherFunc = NULL;
+ fastEqFunc = NULL;
+ fastNeqFunc = NULL;
fastEqqFunc = NULL;
whenSplatFunc = NULL;
prepareBlockFunc = NULL;
@@ -368,21 +370,44 @@
}
Value *
-RoxorCompiler::compile_fast_eqq_call(Value *selfVal, Value *comparedToVal)
+RoxorCompiler::compile_fast_op_call(SEL sel, Value *selfVal, Value *comparedToVal)
{
- if (fastEqqFunc == NULL) {
- // VALUE rb_vm_fast_eqq(struct mcache *cache, VALUE left, VALUE right)
- fastEqqFunc = cast<Function>
- (module->getOrInsertFunction("rb_vm_fast_eqq",
- RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL));
+ Function *func = NULL;
+ // VALUE rb_vm_fast_op(struct mcache *cache, VALUE left, VALUE right)
+ if (sel == selEq) {
+ if (fastEqFunc == NULL) {
+ fastEqFunc = cast<Function>(module->getOrInsertFunction(
+ "rb_vm_fast_eq",
+ RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL));
+ }
+ func = fastEqFunc;
}
+ else if (sel == selNeq) {
+ if (fastNeqFunc == NULL) {
+ fastNeqFunc = cast<Function>(module->getOrInsertFunction(
+ "rb_vm_fast_neq",
+ RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL));
+ }
+ func = fastNeqFunc;
+ }
+ else if (sel == selEqq) {
+ if (fastEqqFunc == NULL) {
+ fastEqqFunc = cast<Function>(module->getOrInsertFunction(
+ "rb_vm_fast_eqq",
+ RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL));
+ }
+ func = fastEqqFunc;
+ }
+ else {
+ return NULL;
+ }
std::vector<Value *> params;
- params.push_back(compile_mcache(selEqq, false));
+ params.push_back(compile_mcache(sel, false));
params.push_back(selfVal);
params.push_back(comparedToVal);
- return compile_protected_call(fastEqqFunc, params);
+ return compile_protected_call(func, params);
}
Value *
@@ -2305,11 +2330,8 @@
BranchInst::Create(merge_bb, bb);
bb = dispatch_bb;
- Value *dispatch_val;
- if (sel == selEqq) {
- dispatch_val = compile_fast_eqq_call(leftVal, rightVal);
- }
- else {
+ Value *dispatch_val = compile_fast_op_call(sel, leftVal, rightVal);
+ if (dispatch_val == NULL) {
dispatch_val = compile_dispatch_call(params);
}
dispatch_bb = bb;
Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h 2009-08-07 04:22:38 UTC (rev 2249)
+++ MacRuby/trunk/compiler.h 2009-08-07 04:23:31 UTC (rev 2250)
@@ -104,6 +104,8 @@
int return_from_block_ids;
Function *dispatcherFunc;
+ Function *fastEqFunc;
+ Function *fastNeqFunc;
Function *fastEqqFunc;
Function *whenSplatFunc;
Function *prepareBlockFunc;
@@ -215,7 +217,7 @@
Function *new_function, rb_vm_arity_t &arity, NODE *body);
Value *compile_dispatch_call(std::vector<Value *> ¶ms);
Value *compile_when_splat(Value *comparedToVal, Value *splatVal);
- Value *compile_fast_eqq_call(Value *selfVal, Value *comparedToVal);
+ Value *compile_fast_op_call(SEL sel, Value *selfVal, Value *comparedToVal);
Value *compile_attribute_assign(NODE *node, Value *extra_val);
virtual Value *compile_prepare_block_args(Function *func, int *flags);
Value *compile_block_create(NODE *node);
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2009-08-07 04:22:38 UTC (rev 2249)
+++ MacRuby/trunk/vm.cpp 2009-08-07 04:23:31 UTC (rev 2250)
@@ -565,7 +565,14 @@
{
if (sel == selEq || sel == selEqq || sel == selNeq) {
return klass == (Class)rb_cFixnum
- || klass == (Class)rb_cSymbol;
+ || klass == (Class)rb_cFloat
+ || klass == (Class)rb_cSymbol
+ || klass == (Class)rb_cNSString
+ || klass == (Class)rb_cNSMutableString
+ || klass == (Class)rb_cNSArray
+ || klass == (Class)rb_cNSMutableArray
+ || klass == (Class)rb_cNSHash
+ || klass == (Class)rb_cNSMutableHash;
}
if (sel == selPLUS || sel == selMINUS || sel == selDIV
|| sel == selMULT || sel == selLT || sel == selLE
@@ -2786,14 +2793,46 @@
return retval;
}
+// The rb_vm_fast_* functions don't check if the selector has been redefined or
+// not, because this is already handled by the compiler.
+// Also, fixnums and floats are already handled.
+
extern "C"
VALUE
+rb_vm_fast_eq(struct mcache *cache, VALUE self, VALUE comparedTo)
+{
+ const int self_type = TYPE(self);
+ switch (self_type) {
+ case T_SYMBOL:
+ return self == comparedTo ? Qtrue : Qfalse;
+
+ case T_STRING:
+ case T_ARRAY:
+ case T_HASH:
+ if (self == comparedTo) {
+ return Qtrue;
+ }
+ if (TYPE(comparedTo) != self_type) {
+ return Qfalse;
+ }
+ return CFEqual((CFTypeRef)self, (CFTypeRef)comparedTo)
+ ? Qtrue : Qfalse;
+ }
+ return rb_vm_dispatch(cache, self, selEq, NULL, 0, 1, comparedTo);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_neq(struct mcache *cache, VALUE self, VALUE comparedTo)
+{
+ // TODO
+ return rb_vm_dispatch(cache, self, selNeq, NULL, 0, 1, comparedTo);
+}
+
+extern "C"
+VALUE
rb_vm_fast_eqq(struct mcache *cache, VALUE self, VALUE comparedTo)
{
- // This function does not check if === has been or not redefined
- // so it should only been called by code generated by
- // compile_optimized_dispatch_call().
- // Fixnums are already handled in compile_optimized_dispatch_call
switch (TYPE(self)) {
// TODO: Range
case T_STRING:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090806/58628a4b/attachment-0001.html>
More information about the macruby-changes
mailing list