yarv-diff:16
From: ko1 atdot.net
Date: 22 Jun 2005 04:00:38 -0000
Subject: [yarv-diff:16] r171 - in trunk: . test
Author: ko1
Date: 2005-06-22 13:00:37 +0900 (Wed, 22 Jun 2005)
New Revision: 171
Modified:
trunk/ChangeLog
trunk/compile.c
trunk/insns.def
trunk/test.rb
trunk/test/test_bin.rb
trunk/yarvcore.c
trunk/yarvcore.h
Log:
* yarvcore.h, yarvcore.c, insns.def, compile.c : add mult optimization
* test/test_bin.rb : add test_fact
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/ChangeLog 2005-06-22 04:00:37 UTC (rev 171)
@@ -4,6 +4,13 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-06-22(Wed) 12:58:26 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * yarvcore.h, yarvcore.c, insns.def, compile.c : add mult optimization
+
+ * test/test_bin.rb : add test_fact
+
+
2005-06-21(Tue) 22:34:07 +0900 Koichi Sasada <ko1 atdot.net>
* yarvcore.h, compile.[ch], tmpl/optinsn.inc.tmpl, rb/insns2vm.rb :
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/compile.c 2005-06-22 04:00:37 UTC (rev 171)
@@ -2618,6 +2618,9 @@
else if(node->nd_mid == idMINUS){
ADD_INSN(ret, nd_line(node), opt_minus);
}
+ else if(node->nd_mid == idMULT){
+ ADD_INSN(ret, nd_line(node), opt_mult);
+ }
else if(node->nd_mid == idLT){
ADD_INSN(ret, nd_line(node), opt_lt);
}
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/insns.def 2005-06-22 04:00:37 UTC (rev 171)
@@ -1497,8 +1497,8 @@
sp + niseqobj->stack_max){
rb_bug("stack overflow");
}
- /* TODO: fix me to set exact stack limit */
- th->stack_mark_pointer = th->stack + YARV_THREAD_STACK_SIZE;
+ /* TODO: maybe more severe check is needed */
+ th->stack_mark_pointer = sp + niseqobj->stack_max;
/* clear locals */
if(niseqobj->local_tbl){
@@ -1980,6 +1980,41 @@
/**
@c optimize
+ @e optimized X*Y.
+ @j K X*YB
+ */
+DEFINE_INSN
+opt_mult
+()
+(VALUE recv, VALUE obj)
+(VALUE val)
+{
+ if(FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_MULT)){
+ long a, b, c;
+
+ a = FIX2LONG(recv);
+ b = FIX2LONG(obj);
+ c = a * b;
+ val = LONG2FIX(c);
+
+ if (FIX2LONG(val) != c) {
+ val = rb_big_mul(rb_int2big(a), rb_int2big(b));
+ }
+ }
+ else{
+ /* other */
+#ifdef YARV_AOT_COMPILED
+ val = rb_funcall(recv, idMULT, 1, obj);
+#else
+ PUSH(recv); PUSH(obj);
+ tmp_id = idMULT;
+ goto LABEL_IS_SC(start_init_in_send_for_opt_1);
+#endif
+ }
+}
+
+/**
+ @c optimize
@e optimized X<Y.
@j K X<YB
*/
Modified: trunk/test/test_bin.rb
===================================================================
--- trunk/test/test_bin.rb 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/test/test_bin.rb 2005-06-22 04:00:37 UTC (rev 171)
@@ -300,6 +300,18 @@
m
}
end
-
+
+ def test_fact
+ ae %q{
+ def fact(n)
+ if(n > 1)
+ n * fact(n-1)
+ else
+ 1
+ end
+ end
+ fact(7300)
+ }
+ end
end
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/test.rb 2005-06-22 04:00:37 UTC (rev 171)
@@ -9,6 +9,37 @@
###########################################################
$prog =<<'__EOP__'
+def fact(n)
+ if(n > 1)
+ n * fact(n-1)
+ else
+ 1
+ end
+end
+
+fact(7)
+__END__
+class C
+ def m
+ 1
+ end
+end
+
+class CC < C
+ def m
+ super()
+ end
+end
+
+obj = CC.new
+
+i = 0
+while i<10000000
+ obj.m
+ i+=1
+end
+
+__END__
i=0
while i<100
i+=1
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/yarvcore.c 2005-06-22 04:00:37 UTC (rev 171)
@@ -29,6 +29,7 @@
ID idPLUS;
ID idMINUS;
+ID idMULT;
ID idLT;
ID idLTLT;
ID idEqq;
@@ -879,6 +880,7 @@
/* for optimize */
idPLUS = rb_intern("+");
idMINUS= rb_intern("-");
+ idMULT = rb_intern("*");
idLT = rb_intern("<");
idLTLT = rb_intern("<<");
idEqq = rb_intern("===");
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2005-06-21 13:39:40 UTC (rev 170)
+++ trunk/yarvcore.h 2005-06-22 04:00:37 UTC (rev 171)
@@ -27,6 +27,7 @@
/* special id */
extern ID idPLUS;
extern ID idMINUS;
+extern ID idMULT;
extern ID idLT;
extern ID idLTLT;
extern ID idEqq;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml