Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Now that the question is considered solved, this piece of code might serve as an interesting side note about (premature) optimization.

I was going to observe that ord('C') = 0x43 and ord('G') = 0x47, so you could do the comparison in one step (if (*gcString | 4 == 'G') or if (*gcString & 0xFB == 'C')), and perhaps compare 8 bytes in one go by casting the char * pointer to uint64 * and doing the necessary accounting.

Then it occurred to me to check the code the compiler actually generates from the simple and readable function above. There is a nice online service at godbolt.org that lets you do exactly that. Paste the function text into the source window (and add the necessary #include <cstring> header to make it compile), enter -O3 for compiler options, and behold. GCC 8.2 not only notices the similar ASCII codes and uses a trick similar to mine, but it generates an efficient but nearly unreadable main loop using SIMD instructions that compares 16 bytes in one go (which is better than what you can do with simple, standard C).

I also had the idea of replacing the loop in the function with while (*gcString++), thinking that strlen needlessly scans through the string once to find the terminator, but guess what - this kills the optimization. It needs to know the length in advance to be able to do the advanced SIMD loop.


In reply to Re^3: Inline CPP undefined subroutine by kikuchiyo
in thread Inline CPP undefined subroutine by Alessandro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-28 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found