yodl icon indicating copy to clipboard operation
yodl copied to clipboard

No need to dynamic_cast upon successful match

Open solodon4 opened this issue 7 years ago • 1 comments

Hi Florian,

Accidentally wondered into your code today and saw you do a dynamic_cast on the subject inside Case statements as for example here:

https://github.com/forflo/yodl/blob/0e6237e9c10fa7ca33355a51c7fd240dfdc4e1a0/vhdlpp/loop_unroller.cc#L121-L126

This is redundant and kills performance as you already have the properly cast subject inside a variable match0, which is local to each Case clause. The type of match0 in the first clause in the above example is Entity& and in the second clause - ScopeBase&.

If you have Match statement on multiple subjects, they are available via match0, match1 etc. respectively. One of the big contributions of Mach7 was not just the concise syntax, but also a very efficient type switch statement in which you get the results of essentially invoking dynamic_cast, which is extremely slow, at the cost of a direct jump.

Yuriy

solodon4 avatar Mar 15 '17 23:03 solodon4

First of all, thank you for your comment on this!

One of the big contributions of Mach7 was not just the concise syntax, but also a very efficient type switch statement in which you get the results of essentially invoking dynamic_cast, which is extremely slow, at the cost of a direct jump.

Yes, I know, I read your paper on Mach7.

I wrote loop_unroller.cc when I still was fairly new with C++ and Mach7. However, if I get back to work on this project, I'll have to rewrite the AST abstraction classes first. It is very likely that I have to rewrite (or adjust) every ast modifier class too, which, of course, would include the loop_unroller.cc.

Performance was never the big goal of this project, though. :)

-- flo

forflo avatar Mar 21 '17 18:03 forflo