[phc-internals] [phc commit] r1195 - trunk/src/codegen

codesite-noreply at google.com codesite-noreply at google.com
Fri Apr 25 05:00:09 IST 2008


Author: paul.biggar
Date: Thu Apr 24 20:59:22 2008
New Revision: 1195

Modified:
   trunk/src/codegen/Generate_C.cpp

Log:
In investigating the strcat slowdown, it seems that a lot of assignment 
overwrite themselves. Variables which have a ref-count of one will 
decrement their refcount, then overwite themselves with the new value, 
then increase the ref-count. We add a check to see if the variables are 
the same before this.

Note that we check outside of write_var, as opposed to moving the check 
into write_var. Initially I did the latter, but only got a small speed 
improvement. It seemed that since this was happening in a loop, the 
branch would go the same way each time. But if there is only 1 branch 
location, inside write_var, then the predictor will get confused. If it 
is outside it, then each condition will get its own predictor, which 
should be nearly 100% predictable. Sure enough, this got another speedup.

Overall, this represents a 4-5% speedup.


Modified: trunk/src/codegen/Generate_C.cpp
==============================================================================
--- trunk/src/codegen/Generate_C.cpp	(original)
+++ trunk/src/codegen/Generate_C.cpp	Thu Apr 24 20:59:22 2008
@@ -953,15 +953,18 @@
 				initialize (initializations, var);
 			}
 			code
-				<< "assert (!" << var << "->is_ref);\n"
-				<< "if ((*p_lhs)->is_ref)\n"
-				<<		"overwrite_lhs (*p_lhs, " << var << ");\n"
-				<<	"else\n"
+				<< "if (" << var << " != *p_lhs)\n"
 				<< "{\n"
-				<<		var << "->refcount++;\n"
-				<<		"zval_ptr_dtor (p_lhs);\n"
-				<<		"*p_lhs = " << var << ";\n"
-				<< "}\n";
+				<<		"assert (!" << var << "->is_ref);\n"
+				<<		"if ((*p_lhs)->is_ref)\n"
+				<<			"overwrite_lhs (*p_lhs, " << var << ");\n"
+				<<		"else\n"
+				<<		"{\n"
+				<<			var << "->refcount++;\n"
+				<<			"zval_ptr_dtor (p_lhs);\n"
+				<<			"*p_lhs = " << var << ";\n"
+				<<		"}\n"
+				<<	"}\n";
 		}
 		else
 		{
@@ -1088,7 +1091,8 @@
 				<< "p_rhs = &temp;\n";
 			read (LOCAL, "p_rhs", rhs->value);
 			code
-				<< "write_var (p_lhs, p_rhs, &is_p_rhs_new TSRMLS_CC);\n";
+				<< "if (*p_lhs != *p_rhs)\n"
+				<<		"write_var (p_lhs, p_rhs, &is_p_rhs_new TSRMLS_CC);\n";
 			cleanup ("p_rhs");
 		}
 		else


More information about the phc-internals mailing list