public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Instruction bundling on IA64 and the Intel Assembler
@ 2003-12-15 22:56 Richard Kenner
  2003-12-15 23:09 ` Vladimir Makarov
  0 siblings, 1 reply; 17+ messages in thread
From: Richard Kenner @ 2003-12-15 22:56 UTC (permalink / raw)
  To: vmakarov; +Cc: gcc

    Could you be more specific.  I tried to describe the code in details.
    I see the following comment for the function.

For one thing, the only description of the algorithm is "based on dynamic
programming".  In what *way* is it based on it?  Somewhere in the
function (but probably not in the front, since that describes the
*external* view of the function, it would be good to give some overview
of the algorithm.

    /* First (forward) pass -- generates states. */
    /* Finding state with a minimal cost:  */
    /* Second (backward) pass: adding nops and templates:  */
    /* Insert additional cycles for MM-insns: */

These are more "tags" than comments.  Each comment should be at least a
full sentence and perhaps even a paragraph.

Let's just look at the first comment ("First (forward) pass --
generates states."  This has a whole bunch of sequential code, then one
short loop followed by a long loop which has at least two inner loops.
There are no comments saying what any of those are doing.  It's worse
later on.

There are also variables like "pos", where there is no idea what that is.
Also, you set INSN_MODE to TImode with no indication whatsoever of what
that flag is supposed to mean.

    IMHO this code is far from the worst one with the point view of comments.

True, and I complain about all of the others as well!

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Instruction bundling on IA64 and the Intel Assembler
@ 2003-12-15 23:59 Richard Kenner
  2003-12-16  4:58 ` Robert Dewar
  0 siblings, 1 reply; 17+ messages in thread
From: Richard Kenner @ 2003-12-15 23:59 UTC (permalink / raw)
  To: vmakarov; +Cc: gcc

    I don't like when the sentence used without context.  I meant the
    article here not the comments.  

I'm sorry.  It sounded like you were saying "to describe this would be
like writing an article and I don't have time to do that".

    By the way when I wrote the patch, in my opinion I wrote the comments
    enough to understand the code and e.g.  Richard Henderson understood
    the code. 

The issue isn't "is it possible to understand this code without comments".
Given enough work, it's possible to understand *machine code* without
comments. 

The purpose of comments is to make it *easier* to understand the code
so that needed changes can be made.  The present situation is a good
example of that.  To add code to mark the end of a bundle is something
that should be relatively easy.  It shouldn't be necessary to understand
every detail of the code in order to do that.  Instead, the comments
are supposed to explain the overview of each piece of code so somebody doesn't
have to spend the time to understand every piece of code in detail to
make a change like that.

    You can not understand the code without some work on the code.  

I don't follow.

    There should be a balance with comment size and the code.  

Sure.  If you have straightforward sequential code you can often get
away with few or no comments.  But a comment for every loop and for
every non-trivial "if" statement is an absolute minimum.

A good guide (which few of us can meet, admittedly) is that you should
be able to understand the most important part of the function just from
the comments and with all the code deleted.

    Sometimes a lot of comments is even worse.

Sure, but the code in question is *nowhere* near that level.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Instruction bundling on IA64 and the Intel Assembler
@ 2003-12-15 23:11 Richard Kenner
  2003-12-15 23:42 ` Vladimir Makarov
  0 siblings, 1 reply; 17+ messages in thread
From: Richard Kenner @ 2003-12-15 23:11 UTC (permalink / raw)
  To: vmakarov; +Cc: gcc

    Unfortunately I have no time for this.

This is a perfect example of why patches should not be approved until
they are adequately documented.  It's *very* hard (often impossible)
to get that done later.  Indeed it's usually recommended to write the
comments *before* the code.

    As I wrote in my previous email I'll try to write more comments and
    divide the function on several ones when the main line is in stage 1.

Please write the comments now.  Dividing the function up can probably
safely be done now, but can indeed wait for stage 1.

Take a look at reorg.c.  That's code of roughly equivalent complexity.
Try to match the commenting style in that code.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Instruction bundling on IA64 and the Intel Assembler
@ 2003-12-15 22:22 Richard Kenner
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Kenner @ 2003-12-15 22:22 UTC (permalink / raw)
  To: zack; +Cc: gcc

    NOPs have to be considered when determining bundle boundaries, so I think
    that the naive three-insns-farther approach will be correct.

Sure, but that's not what I meant.  What I meant is that you can't simply
look three insns ahead when the bundle start insn is emitted because the
nops haven't yet been emitted.  So you have to know where to look forward
and that requires *some* knowlege of the function in question.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Instruction bundling on IA64 and the Intel Assembler
@ 2003-12-15 22:01 Richard Kenner
  2003-12-15 22:05 ` Zack Weinberg
  2003-12-15 22:21 ` Vladimir Makarov
  0 siblings, 2 replies; 17+ messages in thread
From: Richard Kenner @ 2003-12-15 22:01 UTC (permalink / raw)
  To: zack; +Cc: gcc

    Always print "{.whatever" in the bundle_selector output template;
    then, whenever bundling() goes to emit a bundle_selector, have it also
    look three insns ahead and emit an "}" insn.  I think this will always
    be right, not interfere with labels and directives, and shouldn't
    require you to comprehend this problem function.

It still requires *some* comprehension because it's not completely clear
when those three insns are written out (consider nops).

However, that still doesn't address part of Geert's comment, which is that
there is little or no documentation in that function and certainly no
overview comments saying what's going on.  Even if there is some simple
way to deal with this issue, that documentation still needs to be provided.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Instruction bundling on IA64 and the Intel Assembler
@ 2003-12-15 21:14 Geert Bosch
  2003-12-15 21:40 ` Zack Weinberg
  0 siblings, 1 reply; 17+ messages in thread
From: Geert Bosch @ 2003-12-15 21:14 UTC (permalink / raw)
  To: gcc; +Cc: Vladimir Makarov

For the IA64 port to OpenVMS, we'll be using the Intel Assembler (IAS).
However, currently the assembly code output by GCC is specific to the
GNU assembler (gas) in a few areas. We have identified and fixed most
such parts (patches will follow), but one more tricky issue is
instruction bundling and template selection.

The Itanium Architecture Assembly Language Guide specifies that
template selection directives must appear inside the braces of a bundle,
like this:

  {.mmi		// use the mmi template for this bundle
   m inst		// memory instruction
   ;;			// stop
   m inst		// memory instruction
   i inst		// integer instruction
  }

However, GCC omits the braces and GAS is OK with that. The template
selector is inserted as an instruction by the function "bundling",
which seems to be the right place to add the "instruction" that
closes a bundle. However, this functions is 339 lines, without any
comments on meaning of variables used or reason for tests etc.
It would be very helpful if at least every for-loop would have
an initial comment indicating what it is doing.

There are six places that insert template selection directives,
and I don't know what the difference is between these places what
the state is at these points.

Vladimir, could you give some insights in what this function is
doing, and preferably add some comments? I searched the mailing
lists for more information on the function, but a I didn't find
any details regarding the implementation. If you have links to
old messages explaining things, please let me know.

   -Geert

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

end of thread, other threads:[~2003-12-16  3:10 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-15 22:56 Instruction bundling on IA64 and the Intel Assembler Richard Kenner
2003-12-15 23:09 ` Vladimir Makarov
  -- strict thread matches above, loose matches on Subject: below --
2003-12-15 23:59 Richard Kenner
2003-12-16  4:58 ` Robert Dewar
2003-12-15 23:11 Richard Kenner
2003-12-15 23:42 ` Vladimir Makarov
2003-12-15 22:22 Richard Kenner
2003-12-15 22:01 Richard Kenner
2003-12-15 22:05 ` Zack Weinberg
2003-12-15 22:21 ` Vladimir Makarov
2003-12-15 21:14 Geert Bosch
2003-12-15 21:40 ` Zack Weinberg
2003-12-15 21:54   ` Geert Bosch
2003-12-15 21:58     ` Zack Weinberg
2003-12-15 22:25       ` Geert Bosch
2003-12-15 22:53         ` Vladimir Makarov
2003-12-15 22:18   ` Geert Bosch

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).