changeset 122:7361d70fbba6

Improve comparison performance by using a constant rather than building a new result object each time
author Mike Pavone <pavone@retrodev.com>
date Thu, 28 Oct 2010 21:04:44 -0400
parents 1af91ceaaf49
children 4e4ecbca0b5d
files number_c.rhope
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/number_c.rhope	Thu Oct 28 21:04:12 2010 -0400
+++ b/number_c.rhope	Thu Oct 28 21:04:44 2010 -0400
@@ -29,16 +29,18 @@
 	]Set Input Type[type inst, 0]
 	]Set Input Type[type inst, 1]
 	]Set Output Type[Type Instance["Boolean"], 0]
-	]Register Constant["Blueprint_Boolean", Type Instance["Boolean"]]
-	]Call["Build", [()]Append[Constant["Blueprint_Boolean"]]]
-	]Move[Result[0], "out"]
+	]Register Constant["Boolean_Yes", Yes]
+	]Register Constant["Boolean_No", No]
+	]Allocate Var["compres", [Type Instance["Int32"]]Set Variant["Naked"]]
 	
 	,ina <- [func]Read Field["a", "Num"]
 	{ ,inb <- [~]Read Field["b", "Num"]
-	{ ,outa <- [~]Write Field["out", "Val"]
-	{ after op <- [backend func]Call[~, ina, inb, outa] }}}
+	{ after op <- [backend func]Call[~, ina, inb, "compres"] }}
+
+	[after op]Do If["compres", [[after op]Instruction Stream]Move[Constant["Boolean_Yes"], "out"]]
+	{ after out <- [~]Do If[NotCond["compres"], [[after op]Instruction Stream]Move[Constant["Boolean_No"], "out"]] }
 	
-	out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ]
+	out <- [backend]Store Function[ [[after out]Release["a"]]Release["b"] ]
 	
 }
 
@@ -82,13 +84,15 @@
 _Generate Number Methods[backend, type:out]
 {
 	//Old crappy parser doesn't like Worker literals in List literals, work around for now
-	opmap <- [[[[[[()
+	opmap <- [[[[[[[[()
 		]Append[ [("+")]Append[Add[?]] ]
 		]Append[ [("-")]Append[Sub[?]] ]
 		]Append[ [("*")]Append[Multiply[?]] ]
 		]Append[ [("/")]Append[Divide[?]] ]
 		]Append[ [("LShift")]Append[DoLShift[?]] ]
 		]Append[ [("RShift")]Append[DoRShift[?]] ]
+		]Append[ [("&")]Append[BitAnd[?]] ]
+		]Append[ [("|")]Append[BitOr[?]] ]
 	//(("+", Add[?]), ("-", Sub[?]), ("*", Multiply[?]), ("/", Divide[?]), ("LShift", DoLShift[?]), ("RShift", DoRShift[?]))
 	compops <- [[[[[[()
 		]Append[ [("<")]Append[CompLess[?]] ]
@@ -173,7 +177,7 @@
 
 _Register Number Methods[program,type:out]
 {
-	methods <- ("+", "-", "*", "/", "LShift", "RShift")
+	methods <- ("+", "-", "*", "/", "LShift", "RShift", "&", "|")
 	compmethods <- ("<", ">", "=", "<=", ">=", "!=")
 	register <- Val[Register Number Method[?, ?, type]]
 	Fold[[register]Set Input[3, type], program, methods]