Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
 |
12-27-2007, 08:48 AM
|
#1
|
|
LQ Newbie
Registered: Dec 2007
Posts: 4
Rep:
|
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.).
so
madd192(a,b,c,rp);
is expanded to something like
rp[1] = a[1] * b[1] + c[1];
rp[2] = a[2] * b[2] + c[2];
.
.
rp[192] = a[192] * b[192] + c[192];
its actually a bit more complicated than my example so the compiler can't do it automatically.
Is a job for perl or is there anything else I should look at ?
I'll be doing this a lot for other, similar, functions.
anyone care to to have a go ?
-ds
|
|
|
|
12-27-2007, 09:08 AM
|
#2
|
|
Member
Registered: Nov 2006
Posts: 344
Rep:
|
Have you looked at the Sun Studio C compiler? It has many more capabilities in that area than gcc, etc...
|
|
|
|
12-27-2007, 10:05 AM
|
#3
|
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,300
Rep: 
|
Quote:
Originally Posted by demosuzki
its actually a bit more complicated than my example so the compiler can't do it automatically.
|
Unless I am missing something, you can do it with macros like the rest of us.
Code:
#define MEGAFUNC(a, b, c, d) \
{ \
a[b] = c; \
b[c] = d; \
... \
d[a] = b; \
}
This is a bogus example, but it should illustrate the idea.
|
|
|
|
12-28-2007, 10:51 AM
|
#4
|
|
LQ Newbie
Registered: Dec 2007
Posts: 4
Original Poster
Rep:
|
Quote:
Originally Posted by Dox Systems - Brian
Have you looked at the Sun Studio C compiler? It has many more capabilities in that area than gcc, etc...
|
thank you for your response
Its actually for an architecture (the cell) not supported by Sun.
Its because of the immaturity (non optimal code generation) of the compilers that i am hand optimising
/ds
|
|
|
|
12-28-2007, 10:57 AM
|
#5
|
|
LQ Newbie
Registered: Dec 2007
Posts: 4
Original Poster
Rep:
|
[QUOTE=David1357;3002946]Unless I am missing something, you can do it with macros like the rest of us.
thank you for your response
My example was small to illustrate the idea the real problem is a little more complicated.
I considered macros and have used them to prototype the idea
what I need to do will introduce 1000s of lines.
I'm thinking that 'something else' would ease maintenance and hopefully reduce the possibility of introducing subtle but hard to find bugs.
/ds
|
|
|
|
12-28-2007, 03:04 PM
|
#6
|
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,300
Rep: 
|
Quote:
Originally Posted by demosuzki
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.
|
|
|
|
01-02-2008, 08:55 AM
|
#7
|
|
LQ Newbie
Registered: Dec 2007
Posts: 4
Original Poster
Rep:
|
I've been looking a bit more at this
found a book on code generation ( http://www.manning.com/herrington/)
and
settled on Ruby ( http://www.ruby-lang.org/en/)
to do parsing and text manipulation.
got powerful regexp .
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
-ds
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:00 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|