LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 12-27-2007, 08:48 AM   #1
demosuzki
LQ Newbie
 
Registered: Dec 2007
Posts: 4

Rep: Reputation: 0
Question 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
 
Old 12-27-2007, 09:08 AM   #2
Dox Systems - Brian
Member
 
Registered: Nov 2006
Posts: 344

Rep: Reputation: 31
Have you looked at the Sun Studio C compiler? It has many more capabilities in that area than gcc, etc...
 
Old 12-27-2007, 10:05 AM   #3
David1357
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
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by demosuzki View Post
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.
 
Old 12-28-2007, 10:51 AM   #4
demosuzki
LQ Newbie
 
Registered: Dec 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Dox Systems - Brian View Post
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
 
Old 12-28-2007, 10:57 AM   #5
demosuzki
LQ Newbie
 
Registered: Dec 2007
Posts: 4

Original Poster
Rep: Reputation: 0
[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
 
Old 12-28-2007, 03:04 PM   #6
David1357
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
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by demosuzki View Post
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.
 
Old 01-02-2008, 08:55 AM   #7
demosuzki
LQ Newbie
 
Registered: Dec 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
ruby


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl forcing loop to next b4 first job is done. ryedunn Programming 1 09-20-2006 01:14 PM
for loop to retrieve info and write approbiate line of code? ati Programming 2 05-07-2006 11:07 AM
best tool for the job or how to tell what distro is best for me Desidarius Linux - Distributions 1 10-08-2004 09:55 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 11:21 AM
Looking for auto text tool bitpicker Linux - Software 0 01-13-2004 02:08 AM


All times are GMT -5. The time now is 06:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration