public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* Re: how to implement general macro-insn expansion?
@ 2000-12-27 10:39 Nick Clifton
  0 siblings, 0 replies; 9+ messages in thread
From: Nick Clifton @ 2000-12-27 10:39 UTC (permalink / raw)
  To: greg; +Cc: dje, cgen, binutils

Hi Greg,

: I see no way around the need to change the md_assemble() interface.
: Somehow md_assemble() needs to return a `sb' (string block)
: representing the expansion of a macro-insn so that read_a_source_file()
: can push it as a nested input source and continue assembling.  A
: sneaky way to do this that doesn't require changing any of the
: zillions of instances of md_assemble is to pass a zeroed sb as a
: second argument, then detect macro-insn by whether or not the sb's
: fields come back filled-in.  However, I don't like sneakiness and gas
: is sourceware, so I'm content to hack all instances of md_assmeble to
: take the second argument and return a boolean to indicate what we did.
: md_assmble() should return nonzero if it assembled an insn, and should
: return 0 if a macro expansion was deposited into `sb'.
: 
: Sound reasonable?

Alternatively you could create a new target macro, say
MD_MACRO_ASSEMBLE.  If this is defined, then read_a_source_file()
would invoke this macro, which is expected to return a string block,
and if it is not defined then read_a_source_file() would invoke
md_assemble() as normal.  That way you do not have to modify hundreds
of ports, and you only need to define for those ports that really need
this feature.

Cheers
	Nick


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-27 14:21               ` Doug Evans
@ 2001-01-09 15:23                 ` Greg McGary
  0 siblings, 0 replies; 9+ messages in thread
From: Greg McGary @ 2001-01-09 15:23 UTC (permalink / raw)
  To: Doug Evans; +Cc: cgen, binutils

Doug Evans <dje@transmeta.com> writes:

>  > I was striving to reuse existing mechanisms, make local labels and
>  > pseudo-ops easily usable, which is best achievable by having
>  > md_assemble() return an expansion.  Can you live with that?
> 
> Dunno.  Are we talking gas implementation or cgen design?

Mostly gas.

> If all of this is just how you're going to implement something
> in gas I don't care (much).  But I'd like to see how this will appear in cgen.

I have been considering wrapping CGEN_OPCODE.format in a union, and
adding (const char *) as an alternative.  Like so:

  union {
    /* Format entry for hard insn.  */
    const CGEN_IFMT *format;
#define CGEN_OPCODE_FORMAT(opc) ((opc)->u.format)
#define CGEN_OPCODE_MASK_BITSIZE(opc) CGEN_IFMT_MASK_LENGTH (CGEN_OPCODE_FORMAT (opc))
#define CGEN_OPCODE_BITSIZE(opc) CGEN_IFMT_LENGTH (CGEN_OPCODE_FORMAT (opc))
#define CGEN_OPCODE_IFLDS(opc) CGEN_IFMT_IFLDS (CGEN_OPCODE_FORMAT (opc))
    /* string macro insn.  */
    const char *expansion;
#define CGEN_OPCODE_MACRO_EXPANSION(opc) ((opc)->u.expansion)
  } u;

Based on attributes, we'll either insert strings in the u.expansion
template and return that from md_assmeble, or we'll do the usual
thing.  When the general builder-function multi-insn expansions are
implemented, a third alternative would be added which is a
specification of the builder to use (either a code or a function pointer).

That brings me to the matter of macro-insn attributes.  At present,
there's only one: ALIAS.  Unfortunately, it has been over-used to mean
two things:

	1) ignore for sim
	2) 1:1 alias for a real insn

IMO, ALIAS should only mean (2).  We need attributes sufficient to
express the following:

	1) ignore for sim
	2) 1:1 alias for a real insn (the expansion is degenerate)
	3) expansion is a string template that wants textual
	   substitution of operand strings at assembly time.
	4) expansion is a builder function that wants to be called
	   at assembly time, passing operand values.

We could do it with three attrs:

	Primary attribute for all macros is MACRO, which always
	means ignore for sim.  Secondary attrs tell how to expand
	the macro.

	ALIAS	  = 1:1 alias for real insn (degenerate expansion)
	STRING	  = expansion is a string template
	<default> = expansion is a builder function

	<default> means no secondary attribute.  This is done to
	conserve attribute bits.  If one wanted to burn attr bits,
	we could add a BUILDER attribute.

Comments?

Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-27 12:09             ` Greg McGary
@ 2000-12-27 14:21               ` Doug Evans
  2001-01-09 15:23                 ` Greg McGary
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2000-12-27 14:21 UTC (permalink / raw)
  To: Greg McGary; +Cc: cgen, binutils

Greg McGary writes:
 > I was striving to reuse existing mechanisms, make local labels and
 > pseudo-ops easily usable, which is best achievable by having
 > md_assemble() return an expansion.  Can you live with that?

Dunno.  Are we talking gas implementation or cgen design?

If all of this is just how you're going to implement something
in gas I don't care (much).  But I'd like to see how this will appear in cgen.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-27 11:28           ` Doug Evans
@ 2000-12-27 12:09             ` Greg McGary
  2000-12-27 14:21               ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Greg McGary @ 2000-12-27 12:09 UTC (permalink / raw)
  To: Doug Evans; +Cc: cgen, binutils

Doug Evans <dje@transmeta.com> writes:

> 1) I was kind of thinking the macro-insn expander would call
>    appropriate insn emitters rather than doing string substitution.
>    That doesn't preclude going the latter route though.

Earlier, I had stated a preference for emitters as well, but then I
was seduced by the convenience of writing simple string expansions.

> One goal of cgen is to have a large part of the assembler in
> a library, gas then becoming just one user of the library.
> Whether macro-insns should be part of this library I dunno.
> At the very least, don't tie the specification of macro-insns
> to any gas implementation artifacts.

OK.  In that case, md_assemble shouldn't deal with the `sb', but
should rather return a simple char* expansion, if the insn was a
macro.  The caller can then wrap the string in an `sb', as necessary.

> 2) Is this something that has to be handled at a layer above md_assemble?
>    For example, I'm not sure I want to support the result of the expansion
>    containing pseudo-ops.

The main thing I wanted at the layer above md_assemble() was the ability
to define numbered local labels.  I have no immediate plans to use
pseudo-ops, but I didn't want to close the door on them either.

>    One can implement this macro-processing in a reasonable way without
>    returning from md_assemble (assuming the result of the
>    macro-expansion only contains things that md_assemble should
>    otherwise handle).

I was striving to reuse existing mechanisms, make local labels and
pseudo-ops easily usable, which is best achievable by having
md_assemble() return an expansion.  Can you live with that?

Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-26 17:43         ` Greg McGary
@ 2000-12-27 11:28           ` Doug Evans
  2000-12-27 12:09             ` Greg McGary
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2000-12-27 11:28 UTC (permalink / raw)
  To: Greg McGary; +Cc: cgen, binutils

Greg McGary writes:
 > I had originally stated that I wanted to first implement the most
 > general scheme form of expansion (sequence () ...).  Since then, I
 > have changed my mind, since none of the multi-insn macro expansions
 > need runtime evaluation, and string substitution suits me just fine.
 > Now, I'm faced with gas's inadequacy to handle general multi-insn
 > macro expansion at the machine-dependent layer.

Some notes:

1) I was kind of thinking the macro-insn expander would call
   appropriate insn emitters rather than doing string substitution.
   That doesn't preclude going the latter route though.

One goal of cgen is to have a large part of the assembler in
a library, gas then becoming just one user of the library.
Whether macro-insns should be part of this library I dunno.
At the very least, don't tie the specification of macro-insns
to any gas implementation artifacts.

 > read_a_source_file() is the outer machine-independent loop that
 > handles all assembler directives (a.k.a. pseudo-ops) and only invokes
 > the machine-dependent md_assemble() when it has a line that looks like
 > an instruction.  md_assemble() operates on a single line only.
 > read_a_source_file() can handle gasp macro expansion, but that doesn't
 > fit with the macro-insn model.  The strength of macro-insns is that a
 > single opcode can be overloaded to handle multiple insns (both real
 > insns and 1:n macros) differentiated by operand formats and actual
 > operand values (e.g., MIPS).  We can't know until we're inside
 > md_assemble and subsidiaries if we have a macro insn, but it's outside
 > md_assemble that we want to push the old input source's context take
 > input from the new input source which is the macro's expansion string.

2) Is this something that has to be handled at a layer above md_assemble?
   For example, I'm not sure I want to support the result of the expansion
   containing pseudo-ops.
   One can implement this macro-processing in a reasonable way without
   returning from md_assemble (assuming the result of the
   macro-expansion only contains things that md_assemble should
   otherwise handle).

 > I see no way around the need to change the md_assemble() interface.
 > Somehow md_assemble() needs to return a `sb' (string block)
 > representing the expansion of a macro-insn so that read_a_source_file()
 > can push it as a nested input source and continue assembling.  A
 > sneaky way to do this that doesn't require changing any of the
 > zillions of instances of md_assemble is to pass a zeroed sb as a
 > second argument, then detect macro-insn by whether or not the sb's
 > fields come back filled-in.  However, I don't like sneakiness and gas
 > is sourceware, so I'm content to hack all instances of md_assmeble to
 > take the second argument and return a boolean to indicate what we did.
 > md_assmble() should return nonzero if it assembled an insn, and should
 > return 0 if a macro expansion was deposited into `sb'.
 > 
 > Sound reasonable?
 > 
 > Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-20  7:39       ` Doug Evans
@ 2000-12-26 17:43         ` Greg McGary
  2000-12-27 11:28           ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Greg McGary @ 2000-12-26 17:43 UTC (permalink / raw)
  To: Doug Evans; +Cc: cgen, binutils

Doug Evans <dje@transmeta.com> writes:

>  > ; If the macro expands to a string, arguments in the input string
>  > ; are refered to with %N.
>  > 
>  > By %N, do you mean that %0, %1, %2 stand for first, second and third
>  > operands in the macro-insn's syntax string?
> 
> Yes.  That was some playing around I did _really_ early on.
> Ignore it unless there's a seed of something useful there.

[ Cc'd to binutils, because of general gas implementation issues. ]

%n is the most convenient form for the assembler macro expander.  For
the CGEN machine description writer, it's not as good as syntax-string
operand names, but no worse than GCC machine descriptions, so it's OK.

I had originally stated that I wanted to first implement the most
general scheme form of expansion (sequence () ...).  Since then, I
have changed my mind, since none of the multi-insn macro expansions
need runtime evaluation, and string substitution suits me just fine.
Now, I'm faced with gas's inadequacy to handle general multi-insn
macro expansion at the machine-dependent layer.

read_a_source_file() is the outer machine-independent loop that
handles all assembler directives (a.k.a. pseudo-ops) and only invokes
the machine-dependent md_assemble() when it has a line that looks like
an instruction.  md_assemble() operates on a single line only.
read_a_source_file() can handle gasp macro expansion, but that doesn't
fit with the macro-insn model.  The strength of macro-insns is that a
single opcode can be overloaded to handle multiple insns (both real
insns and 1:n macros) differentiated by operand formats and actual
operand values (e.g., MIPS).  We can't know until we're inside
md_assemble and subsidiaries if we have a macro insn, but it's outside
md_assemble that we want to push the old input source's context take
input from the new input source which is the macro's expansion string.

I see no way around the need to change the md_assemble() interface.
Somehow md_assemble() needs to return a `sb' (string block)
representing the expansion of a macro-insn so that read_a_source_file()
can push it as a nested input source and continue assembling.  A
sneaky way to do this that doesn't require changing any of the
zillions of instances of md_assemble is to pass a zeroed sb as a
second argument, then detect macro-insn by whether or not the sb's
fields come back filled-in.  However, I don't like sneakiness and gas
is sourceware, so I'm content to hack all instances of md_assmeble to
take the second argument and return a boolean to indicate what we did.
md_assmble() should return nonzero if it assembled an insn, and should
return 0 if a macro expansion was deposited into `sb'.

Sound reasonable?

Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-20  0:48     ` Greg McGary
@ 2000-12-20  7:39       ` Doug Evans
  2000-12-26 17:43         ` Greg McGary
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2000-12-20  7:39 UTC (permalink / raw)
  To: Greg McGary; +Cc: cgen

Greg McGary writes:
 > I stared at the code some more, and I think I understand it better
 > now.  rtl-c.scm is a toolkit for making builders.  Having a "builder
 > for each real insn" is what I want to do.

I _think_ that's the way to go.
As you get into it feel free to change your mind. :-)

 > Here's another comment from minsn.scm:
 > 
 > ; Expansion:
 > ; If the macro expands to a string, arguments in the input string
 > ; are refered to with %N.
 > 
 > By %N, do you mean that %0, %1, %2 stand for first, second and third
 > operands in the macro-insn's syntax string?

Yes.  That was some playing around I did _really_ early on.
Ignore it unless there's a seed of something useful there.

 > ; Multiple insns are separated with '\n'.
 > ; String expansion is a special case of the normal form which is a Scheme
 > ; expression that controls the expansion.
 > 
 > Do you still want to support this?  I'd rather just support the
 > general scheme expansion.

Dunno.  Feel free to ignore it for now.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to implement general macro-insn expansion?
  2000-12-19 22:54   ` how to implement general macro-insn expansion? Greg McGary
@ 2000-12-20  0:48     ` Greg McGary
  2000-12-20  7:39       ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Greg McGary @ 2000-12-20  0:48 UTC (permalink / raw)
  To: Doug Evans; +Cc: cgen

Greg McGary <greg@mcgary.org> writes:

> ; Another thing to do is have a builder for each real insn so instead of
> ; expanding to text, the macro-expansion could invoke the builder for each
> ; expanded-to insn.
> 
> I don't understand this statement.  Could you elaborate?

I stared at the code some more, and I think I understand it better
now.  rtl-c.scm is a toolkit for making builders.  Having a "builder
for each real insn" is what I want to do.

Here's another comment from minsn.scm:

; Expansion:
; If the macro expands to a string, arguments in the input string
; are refered to with %N.

By %N, do you mean that %0, %1, %2 stand for first, second and third
operands in the macro-insn's syntax string?

; Multiple insns are separated with '\n'.
; String expansion is a special case of the normal form which is a Scheme
; expression that controls the expansion.

Do you still want to support this?  I'd rather just support the
general scheme expansion.

Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* how to implement general macro-insn expansion?
  2000-12-18 13:09 ` Doug Evans
@ 2000-12-19 22:54   ` Greg McGary
  2000-12-20  0:48     ` Greg McGary
  0 siblings, 1 reply; 9+ messages in thread
From: Greg McGary @ 2000-12-19 22:54 UTC (permalink / raw)
  To: Doug Evans; +Cc: cgen

Doug,

I found this comment in opc-itab.scm before the definition of
`-gen-macro-insn-table':

; The general form is a Scheme expression that is interpreted at runtime to
; decide how to perform the expansion.  Yes, that means having a (perhaps
; minimal) Scheme interpreter in the assembler.

I hope the idea of having a scheme interpreter in the assembler is
outdated.  My plan was to reuse as much of rtl-c.scm as possible to
generate something analogous to sem-switch.c for the gas-runtime
stuff.

; Another thing to do is have a builder for each real insn so instead of
; expanding to text, the macro-expansion could invoke the builder for each
; expanded-to insn.

I don't understand this statement.  Could you elaborate?

Thanks,
Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2001-01-09 15:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-27 10:39 how to implement general macro-insn expansion? Nick Clifton
  -- strict thread matches above, loose matches on Subject: below --
2000-12-18 12:02 multi-insn expansions for macro insns? Greg McGary
2000-12-18 13:09 ` Doug Evans
2000-12-19 22:54   ` how to implement general macro-insn expansion? Greg McGary
2000-12-20  0:48     ` Greg McGary
2000-12-20  7:39       ` Doug Evans
2000-12-26 17:43         ` Greg McGary
2000-12-27 11:28           ` Doug Evans
2000-12-27 12:09             ` Greg McGary
2000-12-27 14:21               ` Doug Evans
2001-01-09 15:23                 ` Greg McGary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).