right tool for the job ? / code expander / auto C loop unrolling
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
right tool for the job ? / code expander / auto C loop unrolling
While I'd normally program in C++
I've a small task that I think might be better solved in Perl or
similar. I'm looking for advice.
I need to make a code expander.
What i have to do is parse a set of C/C++ files and for all occurrences
of a function call.
(MADD192(a,b,c,rp); (or MADD256(a,b,c,rp); or MADD512(a,b,c,rp); etc.)
I need to swap in a block of code (using the the 'N' ).
This code body being an large unwound loop based on the function
parameters and the N (192, 256 etc.).
I considered macros and have used them to prototype the idea
what I need to do will introduce 1000s of lines.
Use nested macros. That is how most cryptographic algorithms are implemented. You can use small, well-tested macros to build larger ones. The compiler does not care how many lines of code you eventually generate.
I'm pretty happy with the results.
One run made a c source file with 67,000 lines
One of the advantages over the preprocessor is that you get more power to name variables in unrolling which helps in debugging compared to my experience with macros
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.