Re: 3.0.3
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 12, 2007
- 732 views
Derek Parnell wrote: > I haven't looked into the generated code for it but I guess > that it's not as efficient as it could be. In fact, I'm not sure that there > are any optmizations done to the code after it has been generated. Maybe > this is an openning for a future enhancement? I see, I dumped the il to have a look see. These listings are based on my hacked 2.5 frontend, but I've checked 3.0.0 and the results seem to be the same. Derek's routine:
global type boolean (object x) if not integer(x) then return FALSE end if if x = FALSE then return TRUE end if if x = TRUE then return TRUE end if return FALSE end type --il code: {NOVALUE,99,M_NORMAL,SC_GLOBAL,U_UNUSED,1,"boolean",0,TYPE,52,0,0,-1,0, -- rtn 98 {IS_AN_INTEGER,99,100 --1: tmp 100 := IS_AN_INTEGER(x) ,NOT_IFW,100,10 --4: NOT_IFW tmp 100 (10) ,RETURNF,98,94 --7: RETURNF boolean, FALSE ,EQUALS_IFW,99,94,17 --10: x EQUALS_IFW FALSE (17) ,RETURNF,98,96 --14: RETURNF boolean, TRUE ,EQUALS_IFW,99,96,24 --17: x EQUALS_IFW TRUE (24) ,RETURNF,98,96 --21: RETURNF boolean, TRUE ,RETURNF,98,94 --24: RETURNF boolean, FALSE ,BADRETURNF --27: BADRETURNF }} --My routine: type boo2(object x) if integer(x) and (x=FALSE or x=TRUE) then return TRUE end if return FALSE end type --ilcode: {NOVALUE,107,M_NORMAL,SC_LOCAL,U_UNUSED,1,"boo2",0,TYPE,1455,0,0,-1,0, -- rtn 106 {IS_AN_INTEGER,107,108 --1: tmp 108 := IS_AN_INTEGER(x) ,SC1_AND_IF,108,108,29 --4: SC1_AND_IF(tmp 108,tmp 108) --> 29 ,EQUALS,107,94,109 --8: tmp 109 := EQUALS(x,FALSE) ,SC1_OR,109,109,23 --12: SC1_OR(tmp 109,tmp 109) --> 23 ,EQUALS,107,96,110 --16: tmp 110 := EQUALS(x,TRUE) ,SC2_OR,110,109 --20: SC2_OR tmp 110,tmp 109 ,IF,109,29 --23: IF tmp 109 (29) ,RETURNF,106,96 --26: RETURNF boo2, TRUE ,RETURNF,106,94 --29: RETURNF boo2, FALSE ,BADRETURNF --32: BADRETURNF }}
Theoretically, the SC1_AND_IF could (in this case) be a plain IF, the EQUALS/SC1_OR pair a NOTEQ_IFW to the return TRUE statement, and the EQUALS/SC2_OR/IF triple an EQUALS_IFW to the return FALSE statement, I think:
{IS_AN_INTEGER,107,108 --1: tmp 108 := IS_AN_INTEGER(x) ,IF,108,18 --4: IF tmp 108 (18) ,NOTEQ_IFW,107,94,15 --7: x NOTEQ_IFW FALSE (15) ,EQUALS_IFW,107,96,18 --11: x EQUALS_IFW TRUE (18) ,RETURNF,106,96 --15: RETURNF boo2, TRUE ,RETURNF,106,94 --18: RETURNF boo2, FALSE ,BADRETURNF --21: BADRETURNF }
Easier said than done, no doubt. Regards, Pete PS I should perhaps point out that the latter il obviously ought to beat the current il for the same source, though I doubt it will improve any on the il emitted for Derek's code, which looks spot on to me. Both first and last ils execute the same number of il instructions in all cases. The only reason the latter is smaller is it encodes only two return statements instead of four.