lamuguo / re2

Automatically exported from code.google.com/p/re2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

swap out_ and out1_ in Prog::Inst for performance #95

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
to swap out_ and out1_(and other field in this union), we can avoid 
shifting(opcode_out_>>3) when calling ip->out() 
which is the most frequency call in every kind of search.

the union is reduced to 29 bits, but still enough for other field.
cap_, match_id, empty_ are small integers, fine to declare as uint16.

modified fields may declare as follow:

...
    uint32 out_;         // 32 bits of out, aligned make ip->out() fast
    struct {              // additional instruction arguments:                       
      uint8 opcode_;     // opcode 8 bit, only 3 bit used.
      union {       
    struct {           // opcode == kInstAlt,            
          uint8 out1_hi_;  // 24 bit should? be enough,
          uint16 out1_lo_; // ([a-zA-Z]){1000} ?!
        };
        uint16 cap_;        // opcode == kInstCapture                        
        uint16 match_id_;  // opcode == kInstMatch
        struct {           // opcode == kInstByteRange
          uint8 lo_;       //   byte range is lo_-hi_ inclusive
          uint8 hi_;       //
          uint8 foldcase_; //   convert A-Z to a-z before checking range.
        };
        uint16 empty_;    // opcode == kInstEmptyWidth        
    };             //   Match ID to identify this match (for re2::Set).     
...

Please provide any additional information below.
NOTE: If you have a suggested patch, please see
http://code.google.com/p/re2/wiki/Contribute
for information about sending it in for review.  Thanks.

Original issue reported on code.google.com by Lyricconch on 27 Oct 2013 at 9:20

GoogleCodeExporter commented 9 years ago
forget me, after benchmark, no gain.

declare as:

    uint32 out_;         // 32 bits of out, aligned make ip->out() fast   
    union {
    uint32 out1_opcode_;
    struct {              // additional instruction arguments:
      uint8 opcode_;     // opcode 8 bit, only 3 bit used.             
      union {
        uint8 foldcase_; //   convert A-Z to a-z before checking range.
      }; 
      union {       
        uint16 cap_;        // opcode == kInstCapture                        
        uint16 match_id_;  // opcode == kInstMatch
        struct {           // opcode == kInstByteRange
          uint8 lo_;       //   byte range is lo_-hi_ inclusive
          uint8 hi_;       //
        };
        uint16 empty_;    // opcode == kInstEmptyWidth  
      };
    };
    };

Original comment by Lyricconch on 27 Oct 2013 at 11:47

GoogleCodeExporter commented 9 years ago

Original comment by rsc@golang.org on 29 Oct 2013 at 1:20