develooper Front page | perl.perl5.porters | Postings from January 2018

Re: regrepeat()

Thread Previous
Karl Williamson
January 20, 2018 23:02
Re: regrepeat()
Message ID:
On 01/20/2018 11:52 AM, Karl Williamson wrote:
> As I write this, I realize that there is a way for the 2nd loop to 
> figure out which byte it is without conditionals.  The fastest way is to 
> use xor and ffs(), if available (which on modern computers becomes a 
> single machine instruction), but there are other ways, using shift, mask 
> and integer multiply, similar to what S__variant_byte_number() in 
> inline.h currently does.

It turned out to be easy to do this, and the result is at

So the third loop only gets executed if there are bytes past the end of 
the final full word, and that word is completely spanned.  The 
parallelization more than makes up for this.

The real issue these days is adding conditionals, and in particular ones 
where the prediction fails.  This code adds one in all cases, and a 
second where the parallelization gets invoked (because of the loop to 
get to the word boundary)  But the parallelization cuts 3 or 7 
conditionals for each loop iteration, so that more than balances that 
2nd conditional.  So, I'm now thinking the WORTH_IT value can be pretty 

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About