# HG changeset patch # User Mike Pavone # Date 1304843864 25200 # Node ID fd06fb07762ad80112a33e7deb9f41d97c6f6fa7 # Parent d2b941f82d74b24c404dbf14252e1a3dcf37d62e Basic inlining of arithmetic and comparison operations on integer types diff -r d2b941f82d74 -r fd06fb07762a backendutils_c.rhope --- a/backendutils_c.rhope Sun May 01 18:41:17 2011 -0700 +++ b/backendutils_c.rhope Sun May 08 01:37:44 2011 -0700 @@ -236,6 +236,27 @@ out <- [[op]Left <<[ [[op]Left >>]Strip Addref ]]Right <<[ [[op]Right >>]Strip Addref ] } +Blueprint Cast +{ + Value + Type +} + +Cast[val,type:out] +{ + out <- [[Build[Cast()]]Value <<[val]]Type <<[type] +} + +Make Op@Cast[cast,func:out] +{ + out <- [func]Cast Value[[cast]Value >>, [cast]Type >>] +} + +Strip Addref@Cast[op:out] +{ + out <- [op]Value <<[[[op]Value >>]Strip Addref] +} + Blueprint NotCond { Condition diff -r d2b941f82d74 -r fd06fb07762a cbackend_c.rhope --- a/cbackend_c.rhope Sun May 01 18:41:17 2011 -0700 +++ b/cbackend_c.rhope Sun May 08 01:37:44 2011 -0700 @@ -513,6 +513,12 @@ out <- [["add_ref((object *)"]Append[ [val]Make Op[func] ]]Append[")"] } +Cast Value@C Function[func,op,type:out] +{ + tname <- Rhope Type to C[type, [func]Escape Pattern >>] + out <- [[[["(("]Append[tname]]Append[")"]]Append[Make Op[op, func]]]Append[")"] +} + Add@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," + "] diff -r d2b941f82d74 -r fd06fb07762a number_c.rhope --- a/number_c.rhope Sun May 01 18:41:17 2011 -0700 +++ b/number_c.rhope Sun May 08 01:37:44 2011 -0700 @@ -20,6 +20,74 @@ } +Compile Number Inline[func,op,type,a,b,outvar:out] +{ + ,ina <- [ + [[func]Move[a, outvar] + ]Copy[outvar] + ]Read Field[Cast[outvar, type], "Num"] + { ,inb <- [~]Read Field[Cast[Strip Addref[b], type], "Num"] + { ,outa <- [~]Write Field[Cast[outvar, type], "Num"] + { out <- [op]Call[~, ina, inb, outa] }}} +} + +Compile Number Comp Inline[func,op,type,a,b,outvar:out] +{ + ,ina <- [ + [func]Allocate Var["compres", [Type Instance["Int32"]]Set Variant["Naked"]] + ]Read Field[Cast[Strip Addref[a], type], "Num"] + { ,inb <- [~]Read Field[Cast[Strip Addref[b], type], "Num"] + { after op <- [op]Call[~, ina, inb, "compres"] }} + + [after op]Do If["compres", [[after op]Instruction Stream]Move[Constant["Boolean_Yes"], outvar]] + { out <- [~]Do If[NotCond["compres"], [[after op]Instruction Stream]Move[Constant["Boolean_No"], outvar]] } +} + +Compile Number Inline Check[func,op,type a,type b,a,b,outvar:out,no inline] +{ + opmap <- [[[[[[[[Dictionary[] + ]Set["+", Add[?]] + ]Set["-", Sub[?]] + ]Set["*", Multiply[?]] + ]Set["/", Divide[?]] + ]Set["LShift", DoLShift[?]] + ]Set["RShift", DoRShift[?]] + ]Set["&", BitAnd[?]] + ]Set["|", BitOr[?]] + backend op <- [opmap]Index[op] + { inline func <- Val[Compile Number Inline[?]] } + { + comp opmap <- [[[[[[Dictionary[] + ]Set["<", CompLess[?]] + ]Set[">", CompGreater[?]] + ]Set["=", CompEqual[?]] + ]Set["<=", CompLessEqual[?]] + ]Set[">=", CompGreaterEqual[?]] + ]Set["!=", CompNotEqual[?]] + backend op, no inline <- [comp opmap]Index[op] + { inline func <- Val[Compile Number Comp Inline[?]] } + } + + + Val[backend op] + { + signed?,int,size,no inline <- [[type a]Name >>]Partition["Int"] + { + ,no inline <- If[[[signed?] = ["U"]] Or [[signed?] = [""]]] + { + ,no inline <- [("8","16","32","64")]Find[=[size, ?]] + { + //TODO: Do an inline type check/conversion rather than falling back on a standard call + ,no inline <- If[[type b] = [type a]] + { + out <- [inline func]Call[func, backend op, type a, a, b, outvar] + } + } + } + } + } +} + Compile Number Comp Method[backend, op, type:out] { name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] diff -r d2b941f82d74 -r fd06fb07762a nworker_c.rhope --- a/nworker_c.rhope Sun May 01 18:41:17 2011 -0700 +++ b/nworker_c.rhope Sun May 08 01:37:44 2011 -0700 @@ -898,11 +898,22 @@ save outs <- [node]Outputs >> out <- Val[after save] }{ - [program]Method?[[[node]Data >>]Name >>] + fname <- [[node]Data >>]Name >> + [program]Method?[fname] { - with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] + with call <- [func]Method Call[fname, inputs] }{ - with call <- [func]Call[[[node]Data >>]Name >>, inputs] + ,normal call <- If[[[fname]Contains["@"]]And[[[inputs]Length]=[2]]] + { + //Check for inline on static method calls + //TODO: Deal with unused output + out,normal call <- Compile Number Inline Check[func, [fname]Partition["@"], [[[node]Input Types >>]Index[0]]Index[0], [[[node]Input Types >>]Index[1]]Index[0], [inputs]Index[0], [inputs]Index[1], Result Var Name[0, node index]] + } + + Val[normal call] + { + with call <- [func]Call[fname, inputs] + } } first unused <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1] If[[first unused] > [[node]Min Outputs >>]]