[macruby-changes] [2299] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Aug 12 16:38:08 PDT 2009
Revision: 2299
http://trac.macosforge.org/projects/ruby/changeset/2299
Author: lsansonetti at apple.com
Date: 2009-08-12 16:38:08 -0700 (Wed, 12 Aug 2009)
Log Message:
-----------
most fast ops in place
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-12 22:49:34 UTC (rev 2298)
+++ MacRuby/trunk/compiler.cpp 2009-08-12 23:38:08 UTC (rev 2299)
@@ -53,6 +53,14 @@
return_from_block_ids = 0;
dispatcherFunc = NULL;
+ fastPlusFunc = NULL;
+ fastMinusFunc = NULL;
+ fastMultFunc = NULL;
+ fastDivFunc = NULL;
+ fastLtFunc = NULL;
+ fastLeFunc = NULL;
+ fastGtFunc = NULL;
+ fastGeFunc = NULL;
fastEqFunc = NULL;
fastNeqFunc = NULL;
fastEqqFunc = NULL;
@@ -359,33 +367,53 @@
}
Value *
-RoxorCompiler::compile_fast_op_call(SEL sel, Value *selfVal, Value *comparedToVal)
+RoxorCompiler::compile_fast_op_call(SEL sel, Value *selfVal, Value *otherVal)
{
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;
+
+ // VALUE rb_vm_fast_op(struct mcache *cache, VALUE left, VALUE right);
+#define fast_op(storage, name) \
+ do { \
+ if (storage == NULL) { \
+ storage = cast<Function>(module->getOrInsertFunction(name, \
+ RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL)); \
+ } \
+ func = storage; \
+ } \
+ while (0);
+
+ if (sel == selPLUS) {
+ fast_op(fastPlusFunc, "rb_vm_fast_plus");
}
+ else if (sel == selMINUS) {
+ fast_op(fastMinusFunc, "rb_vm_fast_minus");
+ }
+ else if (sel == selDIV) {
+ fast_op(fastDivFunc, "rb_vm_fast_div");
+ }
+ else if (sel == selMULT) {
+ fast_op(fastMultFunc, "rb_vm_fast_mult");
+ }
+ else if (sel == selLT) {
+ fast_op(fastLtFunc, "rb_vm_fast_lt");
+ }
+ else if (sel == selLE) {
+ fast_op(fastLeFunc, "rb_vm_fast_le");
+ }
+ else if (sel == selGT) {
+ fast_op(fastGtFunc, "rb_vm_fast_gt");
+ }
+ else if (sel == selGE) {
+ fast_op(fastGeFunc, "rb_vm_fast_ge");
+ }
+ else if (sel == selEq) {
+ fast_op(fastEqFunc, "rb_vm_fast_eq");
+ }
else if (sel == selNeq) {
- if (fastNeqFunc == NULL) {
- fastNeqFunc = cast<Function>(module->getOrInsertFunction(
- "rb_vm_fast_neq",
- RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL));
- }
- func = fastNeqFunc;
+ fast_op(fastNeqFunc, "rb_vm_fast_neq");
}
else if (sel == selEqq) {
- if (fastEqqFunc == NULL) {
- fastEqqFunc = cast<Function>(module->getOrInsertFunction(
- "rb_vm_fast_eqq",
- RubyObjTy, PtrTy, RubyObjTy, RubyObjTy, NULL));
- }
- func = fastEqqFunc;
+ fast_op(fastEqqFunc, "rb_vm_fast_eqq");
}
else {
return NULL;
@@ -394,7 +422,7 @@
std::vector<Value *> params;
params.push_back(compile_mcache(sel, false));
params.push_back(selfVal);
- params.push_back(comparedToVal);
+ params.push_back(otherVal);
return compile_protected_call(func, params);
}
Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h 2009-08-12 22:49:34 UTC (rev 2298)
+++ MacRuby/trunk/compiler.h 2009-08-12 23:38:08 UTC (rev 2299)
@@ -104,6 +104,14 @@
int return_from_block_ids;
Function *dispatcherFunc;
+ Function *fastPlusFunc;
+ Function *fastMinusFunc;
+ Function *fastMultFunc;
+ Function *fastDivFunc;
+ Function *fastLtFunc;
+ Function *fastLeFunc;
+ Function *fastGtFunc;
+ Function *fastGeFunc;
Function *fastEqFunc;
Function *fastNeqFunc;
Function *fastEqqFunc;
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2009-08-12 22:49:34 UTC (rev 2298)
+++ MacRuby/trunk/vm.cpp 2009-08-12 23:38:08 UTC (rev 2299)
@@ -564,6 +564,7 @@
if (sel == selEq || sel == selEqq || sel == selNeq) {
return klass == (Class)rb_cFixnum
|| klass == (Class)rb_cFloat
+ || klass == (Class)rb_cBignum
|| klass == (Class)rb_cSymbol
|| klass == (Class)rb_cNSString
|| klass == (Class)rb_cNSMutableString
@@ -575,14 +576,14 @@
if (sel == selPLUS || sel == selMINUS || sel == selDIV
|| sel == selMULT || sel == selLT || sel == selLE
|| sel == selGT || sel == selGE) {
- return klass == (Class)rb_cFixnum;
+ return klass == (Class)rb_cFixnum
+ || klass == (Class)rb_cFloat
+ || klass == (Class)rb_cBignum;
}
-
if (sel == selLTLT || sel == selAREF || sel == selASET) {
return klass == (Class)rb_cNSArray
|| klass == (Class)rb_cNSMutableArray;
}
-
if (sel == selSend || sel == sel__send__ || sel == selEval) {
// Matches any class, since these are Kernel methods.
return true;
@@ -2809,63 +2810,157 @@
extern "C"
VALUE
-rb_vm_fast_eq(struct mcache *cache, VALUE self, VALUE comparedTo)
+rb_vm_fast_plus(struct mcache *cache, VALUE self, VALUE other)
{
+ switch (TYPE(self)) {
+ // TODO: Array, String
+ case T_BIGNUM:
+ return rb_big_plus(self, other);
+ }
+ return rb_vm_dispatch(cache, self, selPLUS, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_minus(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ // TODO: Array, String
+ case T_BIGNUM:
+ return rb_big_minus(self, other);
+ }
+ return rb_vm_dispatch(cache, self, selMINUS, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_div(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ case T_BIGNUM:
+ return rb_big_div(self, other);
+ }
+ return rb_vm_dispatch(cache, self, selDIV, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_mult(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ // TODO: Array, String
+ case T_BIGNUM:
+ return rb_big_mul(self, other);
+ }
+ return rb_vm_dispatch(cache, self, selMULT, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_lt(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ case T_BIGNUM:
+ return FIX2INT(rb_big_cmp(self, other)) < 0 ? Qtrue : Qfalse;
+ }
+ return rb_vm_dispatch(cache, self, selLT, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_le(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ case T_BIGNUM:
+ return FIX2INT(rb_big_cmp(self, other)) <= 0 ? Qtrue : Qfalse;
+ }
+ return rb_vm_dispatch(cache, self, selLE, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_gt(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ case T_BIGNUM:
+ return FIX2INT(rb_big_cmp(self, other)) > 0 ? Qtrue : Qfalse;
+ }
+ return rb_vm_dispatch(cache, self, selGT, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_ge(struct mcache *cache, VALUE self, VALUE other)
+{
+ switch (TYPE(self)) {
+ case T_BIGNUM:
+ return FIX2INT(rb_big_cmp(self, other)) >= 0 ? Qtrue : Qfalse;
+ }
+ return rb_vm_dispatch(cache, self, selGE, NULL, 0, 1, other);
+}
+
+extern "C"
+VALUE
+rb_vm_fast_eq(struct mcache *cache, VALUE self, VALUE other)
+{
const int self_type = TYPE(self);
switch (self_type) {
case T_SYMBOL:
- return self == comparedTo ? Qtrue : Qfalse;
+ return self == other ? Qtrue : Qfalse;
case T_STRING:
case T_ARRAY:
case T_HASH:
- if (self == comparedTo) {
+ if (self == other) {
return Qtrue;
}
- if (TYPE(comparedTo) != self_type) {
+ if (TYPE(other) != self_type) {
return Qfalse;
}
if (self_type == T_ARRAY) {
- return rb_ary_equal(self, comparedTo);
+ return rb_ary_equal(self, other);
}
- return CFEqual((CFTypeRef)self, (CFTypeRef)comparedTo)
+ return CFEqual((CFTypeRef)self, (CFTypeRef)other)
? Qtrue : Qfalse;
+
+ case T_BIGNUM:
+ return rb_big_eq(self, other);
}
- return rb_vm_dispatch(cache, self, selEq, NULL, 0, 1, comparedTo);
+ return rb_vm_dispatch(cache, self, selEq, NULL, 0, 1, other);
}
extern "C"
VALUE
-rb_vm_fast_neq(struct mcache *cache, VALUE self, VALUE comparedTo)
+rb_vm_fast_neq(struct mcache *cache, VALUE self, VALUE other)
{
// TODO
- return rb_vm_dispatch(cache, self, selNeq, NULL, 0, 1, comparedTo);
+ return rb_vm_dispatch(cache, self, selNeq, NULL, 0, 1, other);
}
extern "C"
VALUE
-rb_vm_fast_eqq(struct mcache *cache, VALUE self, VALUE comparedTo)
+rb_vm_fast_eqq(struct mcache *cache, VALUE self, VALUE other)
{
switch (TYPE(self)) {
// TODO: Range
case T_STRING:
- if (self == comparedTo) {
+ if (self == other) {
return Qtrue;
}
- return rb_str_equal(self, comparedTo);
+ return rb_str_equal(self, other);
case T_REGEXP:
- return rb_reg_eqq(self, selEqq, comparedTo);
+ return rb_reg_eqq(self, selEqq, other);
case T_SYMBOL:
- return (self == comparedTo ? Qtrue : Qfalse);
+ return (self == other ? Qtrue : Qfalse);
case T_MODULE:
case T_CLASS:
- return rb_obj_is_kind_of(comparedTo, self);
+ return rb_obj_is_kind_of(other, self);
default:
- return rb_vm_dispatch(cache, self, selEqq, NULL, 0, 1, comparedTo);
+ return rb_vm_dispatch(cache, self, selEqq, NULL, 0, 1, other);
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090812/323334d5/attachment-0001.html>
More information about the macruby-changes
mailing list