They both have a loop dependency on the table element. If the table is not densely populated, it can be beneficial to split the loop increment to either side of the test-and-branch. A pos += max_shift on the branch-predicted path has no memory dependency, thus allowing the loop to run speculatively ahead several iterations.

That sounds interesting. I think I get what you mean by the third sentence; but the emboldened bit of the second sentence could do with a little fleshing out?

If it helps, here is the 16-bit table code. Perhaps you could indicate what you would modify? No need to test; just suggest :)

static U64 count = 0; // just for gathering statistics. #define SL( v, o ) __shiftleft128( *((v)+1), *((v)), o ) void scan16( I64 *table, const U64 *pin, U8 opin, U64 lpin ) { U64 i; for( i = 0; i < 65536; ++i ) table[ i ] = lpin - 16 + 1; for( i = 0; i < lpin - 16 +1; ++i ) { U64 q = SL( pin+(i/64), (opin+i)%64 ); U16 idx = (q & 0xffff000000000000) >> 48ull; table[ idx ] = lpin - 16 - i; if( table[ idx ] < 1 ) table[ idx ] = 1; } } __forceinline U8 cmpBits4( const register U64 *hay, const register U64 *pin, U8 regi +ster ohay, U8 register opin, U64 lpin ) { U64 register i; for( i=0; i < lpin/64; ++i, ++hay, ++pin ) { ++count; if( SL( hay, ohay ) != SL( pin, opin ) ) return 0; } { U8 lastbits = lpin % 64; U64 mask = ( ( 1ull << ( lastbits ) ) -1 ) << ( 64 - lastbits +); ++count; if( ( SL( hay, ohay ) & mask ) != ( SL( pin, opin ) & mask ) ) + return 0; } return 1; } U64 bitstrstr4( const register U64 *hay, U64 *pin, U8 register ohay, U +8 register opin, U64 lhay, U64 lpin ) { U64 register i; I64 table[65536]; scan16( table, pin, opin, lpin ); count = 0; for( i = ohay; i < lhay+ohay-lpin; ) { if( cmpBits4( hay+(i/64), pin, i%64, opin, lpin ) ) return i; else { U16 idx = ( SL( hay+((i+lpin-16)/64), (i+lpin-16)%64 ) & 0 +xffff000000000000 ) >> 48; i += table[ idx ]; } } return -1; }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Re^10: Why Boyer-Moore, Horspool, alpha-skip et.al don't work for bit strings. (Thank you Anonymonk + others.) by BrowserUk
in thread Why Boyer-Moore, Horspool, alpha-skip et.al don't work for bit strings. (And is there an alternative that does?) by BrowserUk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.