public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: "Chuan-Hua Chang" <chuanhua.chang@gmail.com>
To: "Dave Brolley" <brolley@redhat.com>
Cc: "Frank Ch. Eigler" <fche@redhat.com>, cgen@sourceware.org
Subject: Re: generated decoder code question
Date: Mon, 26 Mar 2007 05:50:00 -0000	[thread overview]
Message-ID: <aefe1a0f0703252250o5be7115cu544916429eadd3d8@mail.gmail.com> (raw)
In-Reply-To: <4603DD87.9090002@redhat.com>

>
> Please point out any cases where the test is not needed and I will see
> if I can eliminate it in those cases.
>

Using sid/component/cgen-cpu/mt/mt-decode.cxx as an example:

---------------------------------------------------------------------------------------------
void
mt_scache::decode (mt_cpu* current_cpu, PCADDR pc, mt_insn_word
base_insn, mt_insn_word entire_insn)
{
  /* Result of decoder.  */
  MT_INSN_TYPE itype;

  {
    mt_insn_word insn = base_insn;

    {
      unsigned int val = (((insn >> 24) & (255 << 0)));
      switch (val)
      {
      case 0 :
        if ((entire_insn & 0xff000fff) == 0x0)
          { itype = MT_INSN_ADD; mt_extract_sfmt_add (this,
current_cpu, pc, base_insn, entire_insn); goto done; }
        itype = MT_INSN_X_INVALID; mt_extract_sfmt_empty (this,
current_cpu, pc, base_insn, entire_insn); goto done;
      case 1 :
        if ((entire_insn & 0xff000000) == 0x1000000)
          { itype = MT_INSN_ADDI; mt_extract_sfmt_addi (this,
current_cpu, pc, base_insn, entire_insn); goto done; }
        itype = MT_INSN_X_INVALID; mt_extract_sfmt_empty (this,
current_cpu, pc, base_insn, entire_insn); goto done;
      case 2 :
        if ((entire_insn & 0xff000fff) == 0x2000000)
          { itype = MT_INSN_ADDU; mt_extract_sfmt_addu (this,
current_cpu, pc, base_insn, entire_insn); goto done; }
        itype = MT_INSN_X_INVALID; mt_extract_sfmt_empty (this,
current_cpu, pc, base_insn, entire_insn); goto done;
      case 3 :
        if ((entire_insn & 0xff000000) == 0x3000000)
          { itype = MT_INSN_ADDUI; mt_extract_sfmt_addui (this,
current_cpu, pc, base_insn, entire_insn); goto done; }
        itype = MT_INSN_X_INVALID; mt_extract_sfmt_empty (this,
current_cpu, pc, base_insn, entire_insn); goto done;
      case 4 :
        if ((entire_insn & 0xff000fff) == 0x4000000)
          { itype = MT_INSN_SUB; mt_extract_sfmt_add (this,
current_cpu, pc, base_insn, entire_insn); goto done; }
        itype = MT_INSN_X_INVALID; mt_extract_sfmt_empty (this,
current_cpu, pc, base_insn, entire_insn); goto done;
      case 5 :
        if ((entire_insn & 0xff000000) == 0x5000000)
          { itype = MT_INSN_SUBI; mt_extract_sfmt_addi (this,
current_cpu, pc, base_insn, entire_insn); goto done; }
        itype = MT_INSN_X_INVALID; mt_extract_sfmt_empty (this,
current_cpu, pc, base_insn, entire_insn); goto done;
---------------------------------------------------------------------------------------------------

The top level switch/case statement tests the upper 8 bits of the
instruction ((>> 24) & 255). For case 0, it is true that additional
lower 12 bits are being tested (& 0xff000fff). However, for case 1, no
additional bits are being tested (& 0xff000000), this is where the
redundancy comes in. I would expect CGEN to detect this case and not
generate unnecessary IF checking here. (e.g similar to M32R code in
the CGEN release.)


>>
>> When looking at the M32R decode function, the IF-statement is absent
>> from the decoder code.  This lets me wonder that if there is a way to
>> remove this redundant IF-statement check in the CGEN flow.
>>
>This is likely a case where all of the decodable bits have already been
>tested in reaching that particular case.
>

May I ask that if the released M32R code is generated by the current
CGEN utils-sim.scm file or generated by another version or hand-edited
to remove the IF checking statement mentioned in my question? I am
asking this since from the the "-gen-decode-insn-entry" function I do
not see any conditional construct to control the generation of the IF
checking code. It seems that the IF checking code is always generated.
I have also re-generated the M32R simulator to confirm my guess, and
the newly-generated M32R decode function DOES have the IF checking
statement now. Am I missing something?

>
>Do you have a sense of how frequently such a test is completely
>redundant, and how much additional time this test takes?
>

For high locality code, the decode function may not be invoked that
frequently, but for low locality code, the decode function will be
invoked a lot more often. it seems that this kind of redundancy should
be made as few as possible.

Thanks for your help.

  reply	other threads:[~2007-03-26  5:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-23  8:40 Chuan-Hua Chang
2007-03-23 11:31 ` Frank Ch. Eigler
2007-03-23 14:13   ` Dave Brolley
2007-03-26  5:50     ` Chuan-Hua Chang [this message]
2007-03-23 13:02 ` Dave Brolley

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=aefe1a0f0703252250o5be7115cu544916429eadd3d8@mail.gmail.com \
    --to=chuanhua.chang@gmail.com \
    --cc=brolley@redhat.com \
    --cc=cgen@sourceware.org \
    --cc=fche@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).