[guru-lang] r530 committed - a minor low-level optimization good for a few percent improvement on a...

0 views
Skip to first unread message

guru...@googlecode.com

unread,
Aug 13, 2011, 10:27:13 PM8/13/11
to guru...@googlegroups.com
Revision: 530
Author: aaron.stump
Date: Sat Aug 13 19:26:21 2011
Log: a minor low-level optimization good for a few percent improvement
on at least one benchmark I tried; also some small changes to facilitate
profiling (changing some preprocessor definitions to inline functions)
http://code.google.com/p/guru-lang/source/detail?r=530

Modified:
/branches/1.0/guru/carraway/Datatype.java
/branches/1.0/guru/carraway/Include.java
/branches/1.0/lib/unowned.g

=======================================
--- /branches/1.0/guru/carraway/Datatype.java Thu Mar 11 07:23:45 2010
+++ /branches/1.0/guru/carraway/Datatype.java Sat Aug 13 19:26:21 2011
@@ -163,13 +163,29 @@
String fl = "free_"+ctor_tp;
String cfl = "clear_free_"+ctor_tp;

- // emit prototype for the clear() function
-
+ // emit the clear function
+
if (R == null)
// nothing to clear for 0-ary ctor
ctxt.cw.println("#define clear_"+ctor_tp+"(x) \n");
- else
- ctxt.cw.println("void clear_"+ctor_tp+"(void
*_x);");
+ else {
+ ctxt.cw.println("inline void
clear_"+ctor_tp+"(void *_x) {");
+ ctxt.cw.println(" "+ctor_tp+" *x = ("+ctor_tp+"
*)_x;");
+ for (int j = 0; j < jend; j++) {
+ String v = R.vars[j].toString(ctxt);
+ Expr Tj = F.types[j];
+ if (Tj.consumable(ctxt)) {
+ Sym Tjh = (Tj.construct == Expr.PIN ?
((Pin)Tj).s : (Sym)Tj);
+ Sym df = ctxt.getDropFunction(Tjh);
+ Expr rttype = R.types[j];
+ String rttypestr = rttype.toString(ctxt);
+ if (ctxt.isVar((Sym)rttype))
+ rttypestr = "x->"+rttypestr;
+
ctxt.cw.println(" "+df.toString(ctxt)+"("+rttypestr+", x->"+v+");");
+ }
+ }
+ ctxt.cw.println("}\n");
+ }

// emit the free list and delete function

@@ -202,27 +218,6 @@
ctxt.cw.println(" }");
ctxt.cw.println("}\n");

- // emit the clear function
-
- if (R != null) {
- ctxt.cw.println("void clear_"+ctor_tp+"(void *_x)
{");
- ctxt.cw.println(" "+ctor_tp+" *x = ("+ctor_tp+"
*)_x;");
- for (int j = 0; j < jend; j++) {
- String v = R.vars[j].toString(ctxt);
- Expr Tj = F.types[j];
- if (Tj.consumable(ctxt)) {
- Sym Tjh = (Tj.construct == Expr.PIN ?
((Pin)Tj).s : (Sym)Tj);
- Sym df = ctxt.getDropFunction(Tjh);
- Expr rttype = R.types[j];
- String rttypestr = rttype.toString(ctxt);
- if (ctxt.isVar((Sym)rttype))
- rttypestr = "x->"+rttypestr;
-
ctxt.cw.println(" "+df.toString(ctxt)+"("+rttypestr+", x->"+v+");");
- }
- }
- ctxt.cw.println("}\n");
- }
-
// emit function to build data

ctxt.cw.print("void *"+ctors[i].toString(ctxt)+"(");
=======================================
--- /branches/1.0/guru/carraway/Include.java Tue Sep 8 07:28:12 2009
+++ /branches/1.0/guru/carraway/Include.java Sat Aug 13 19:26:21 2011
@@ -27,8 +27,8 @@

public static void start_emit(Context ctxt) {
ctxt.cw.println("void release(int tp, void *x, int clear);\n");
- ctxt.cw.println("#define carraway_malloc(x) malloc(x)");
- ctxt.cw.println("#define carraway_free(x) free(x)");
+ ctxt.cw.println("void *carraway_malloc(int x) { return malloc(x); }");
+ ctxt.cw.println("void carraway_free(void *x) { free(x); }");
ctxt.cw.println("#define guru_malloc(x) carraway_malloc(x)");
ctxt.cw.println("#define guru_free(x) carraway_free(x)");

=======================================
--- /branches/1.0/lib/unowned.g Fri Aug 12 06:47:43 2011
+++ /branches/1.0/lib/unowned.g Sat Aug 13 19:26:21 2011
@@ -18,7 +18,7 @@
release(A,r,1);
}

- #define gconsume_unowned__match gconsume_unowned
+ inline void gconsume_unowned__match(int A, void *r) {
gconsume_unowned(A,r); }

END.

Reply all
Reply to author
Forward
0 new messages