This is the mail archive of the cgen@sourceware.org mailing list for the CGEN project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: generated decoder code question



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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]