From: Fabrizio Fazzino <fabrizio@fazzino.it>
To: linux-mips@linux-mips.org
Subject: Re: Assembly macro with parameters
Date: Sun, 03 Jul 2005 12:31:00 +0200 [thread overview]
Message-ID: <42C7BE64.7020102@fazzino.it> (raw)
In-Reply-To: <Pine.LNX.4.61L.0507010927130.30138@blysk.ds.pg.gda.pl>
Many thanks Maciej and David,
during these days I've learned a lot about stringification, a feature
that I had never used before.
In any case I didn't have to use this feature... I was just missing the
fact that the opcode evaluation didn't have to happen by declaring an
int variable (in this case the value is computed at runtime) but by the
preprocessor, so I solved my problem this way:
#define NEWOPCODE(base,rd,rs,rt) (base|(rs<<21)|(rt<<16)|(rd<<11))
#define myopcode(rd,rs,rt) asm(".long %0" : : "i" (NEWOPCODE(0xC4000000,rd,rs,rt)))
and then I call it simply as myopcode(10,8,9).
By the way, is there any quick way of writing a setreg(reg_num,reg_val)
C macro to set the value of a register?
And another one to read the value like a reg2var(reg_num,&result) to put
the value of a register inside my own C variable?
I have written my own versions for both but they have a 32-case switch
statement inside so they are not so efficient...
In any case thanks a lot for your suggestions, I've put acknowledgments
to macro@linux-mips.org inside my code!
Fabrizio
David Daney wrote:
>
> The arguments to the asm() statement are strings not char*. They are evaluated at compile time not run time.
>
> You will probably have to use the C preprocessor stringification and concatination operators ('#' and '##').
>
> David Daney
>
Maciej W. Rozycki wrote:
>
> This is untested, but it should be a reasonable starting point:
>
> #define myopcode(rs,rt,rd) do { \
> int opcode_number = 0xC4000000 | (rs<<21) | (rt<<16) | (rd<<11); \
> asm(".word %0" : : "i" (opcode_number)); \
> } while (0)
>
> But you may want to add code to tell GCC that these registers are used and
> how, because otherwise you may have little use of your macro. You'll
> probably have to investigate the explicit register variable GCC feature
> and cpp stringification. It should be straightforward though rather
> boring, so I'm leaving it as an exercise.
>
> Maciej
>
--
============================================
Fabrizio Fazzino - fabrizio@fazzino.it
Fazzino.IT - http://www.fazzino.it
============================================
next prev parent reply other threads:[~2005-07-03 10:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-07 17:53 Assembly macro with parameters Fabrizio Fazzino
2005-04-07 18:25 ` Ralf Baechle
2005-04-08 16:47 ` Fabrizio Fazzino
2005-04-08 16:57 ` Daniel Jacobowitz
2005-06-30 17:20 ` Fabrizio Fazzino
2005-06-30 17:32 ` David Daney
2005-07-01 8:38 ` Maciej W. Rozycki
2005-07-03 10:31 ` Fabrizio Fazzino [this message]
2005-07-04 7:40 ` Geert Uytterhoeven
2005-07-04 12:12 ` Maciej W. Rozycki
2005-07-09 7:22 ` Fabrizio Fazzino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42C7BE64.7020102@fazzino.it \
--to=fabrizio@fazzino.it \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox