Subject: Assembly macro with parameters

From: Fabrizio Fazzino <[email-masked]>
Date: Thu, 07 Apr 2005 19:53:49 +0200

Hi all,
I'm working to an hardware extension of the MIPS32 instruction set
and I need to convert my new instruction into an existing opcode
to make it possible for the normal GCC to correctly compile the code.

Just to be clear, to obtain my new FZMIN instruction like

	FZMIN $rd, $rs, $rt

I have to convert it into

	LWC1 $rt, rd<<11 ($rs)

that is an existing (in some cases unused) opcode.

I'm currently using hardcoded values for the parameters, so
fzmin(10,8,9) will be transformed into
	asm("lwc1 $9, 10<<11($8)" : : : "$10");

It works, but I need a way to set the values of the parameters
at runtime; so I've tried the following macro:

	#define fzmin(rd, rs, rt) asm("lwc1 $rt, rd<<11($rs)");

As you can imagine I'm not an expert of MIPS Assembly macros:
what I've written does NOT work since the values of rd,rs,rt
are NOT substituted inside the asm string.

Is there any way to do what I need? I would appreciate your
help very much.

Cheers,
	Fabrizio

-- 
============================================
    Fabrizio Fazzino - [email-masked]
      Fazzino.IT - http://www.fazzino.it
============================================

---

From: Ralf Baechle <[email-masked]>
Date: Thu, 7 Apr 2005 19:25:49 +0100

> 	#define fzmin(rd, rs, rt) asm("lwc1 $rt, rd<<11($rs)");

Which will leave the assembler entirely unimpressed ;-)

> Is there any way to do what I need? I would appreciate your

Unless you only have a few instructions and are going for a quick hack
I really suggest to add proper support for these instructions to binutils.
Having working support in as, gdb, objdump will make your life so much
easier.

  Ralf

---

From: Fabrizio Fazzino <[email-masked]>
Date: Fri, 08 Apr 2005 18:47:58 +0200

Ralf Baechle wrote:
> Fabrizio Fazzino wrote:

I thought that the compiler was able to substitute also the
values inside strings... Is there any way to force it to do so?

> Having working support in as, gdb, objdump will make your life so much

The processor I'm designing probably will not be implemented in
any way (we just have to simulate the VHDL hardware description),
so we just need a quick-and-dirty way to make the opcode
conversion.

	Fabrizio

---

From: Daniel Jacobowitz <[email-masked]>
Date: Fri, 8 Apr 2005 12:57:17 -0400

> so we just need a quick-and-dirty way to make the opcode

You should probably be using .word then, and generating the instruction
completely by hand.

-- 
Daniel Jacobowitz
CodeSourcery, LLC