Re: Performance improvement to strnlen().

2013-05-27 Thread Lee Thomas
Hello Tim, Thank you for the review; replies inline. Note that all my performance discussion is for amd64, with a few tests of x86, and it's all on the machine described in my initial email (a Lynnfield Xeon), as I don't have any other FreeBSD platform to test on. Testing and performance meas

Re: Performance improvement to strnlen().

2013-05-27 Thread Tim Kientzle
> > Index: strnlen.c > === > diff --git a/head/lib/libc/string/strnlen.c b/head/lib/libc/string/strnlen.c > --- a/head/lib/libc/string/strnlen.c (revision 250951) > +++ b/head/lib/libc/string/strnlen.c (working copy) > @@ -1,5 +1,6

Re: Performance improvement to strnlen().

2013-05-27 Thread Václav Zeman
On 27 May 2013 12:20, Lee Thomas wrote: > On 2013-05-27 04:37, Václav Zeman wrote: >> >> On 26 May 2013 21:01, Lee Thomas wrote: >>> >>> On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: > > > + lp = (const unsigned long *)((uintptr_

Re: Performance improvement to strnlen().

2013-05-27 Thread Václav Zeman
On 27 May 2013 12:25, Adam Nowacki wrote: > On 2013-05-27 10:37, Václav Zeman wrote: >> >> On 26 May 2013 21:01, Lee Thomas wrote: >>> >>> On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: > > > + lp = (const unsigned long *)((uintpt

Re: Performance improvement to strnlen().

2013-05-27 Thread Adam Nowacki
On 2013-05-27 10:37, Václav Zeman wrote: On 26 May 2013 21:01, Lee Thomas wrote: On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); + va = (*lp - mask01); + vb = ((~*lp) & mask80

Re: Performance improvement to strnlen().

2013-05-27 Thread Lee Thomas
On 2013-05-27 04:37, Václav Zeman wrote: On 26 May 2013 21:01, Lee Thomas wrote: On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); + va = (*lp - mask01); + vb = ((~*lp) & mask

Re: Performance improvement to strnlen().

2013-05-27 Thread Florent Peterschmitt
Le 27/05/2013 10:37, Václav Zeman a écrit : > On 26 May 2013 21:01, Lee Thomas wrote: >> On 2013-05-26 08:00, Václav Zeman wrote: >>> >>> On 05/25/2013 10:27 PM, Lee Thomas wrote: + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); + va = (*lp - mask01);

Re: Performance improvement to strnlen().

2013-05-27 Thread Václav Zeman
On 26 May 2013 21:01, Lee Thomas wrote: > On 2013-05-26 08:00, Václav Zeman wrote: >> >> On 05/25/2013 10:27 PM, Lee Thomas wrote: >>> >>> + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); >>> + va = (*lp - mask01); >>> + vb = ((~*lp) & mask80); >> >> I do not think

Re: Performance improvement to strnlen().

2013-05-26 Thread Lee Thomas
On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); + va = (*lp - mask01); + vb = ((~*lp) & mask80); I do not think that this correct C. This is type punning violating the rules of

Re: Performance improvement to strnlen().

2013-05-26 Thread Lee Thomas
On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); + va = (*lp - mask01); + vb = ((~*lp) & mask80); I do not think that this correct C. This is type punning violating the rules of

Re: Performance improvement to strnlen().

2013-05-26 Thread Lee Thomas
On 2013-05-26 08:00, Václav Zeman wrote: On 05/25/2013 10:27 PM, Lee Thomas wrote: + lp = (const unsigned long *)((uintptr_t)str & ~LONGPTR_MASK); + va = (*lp - mask01); + vb = ((~*lp) & mask80); I do not think that this correct C. This is type punning violating the rules of

Re: Performance improvement to strnlen().

2013-05-25 Thread Václav Zeman
On 05/25/2013 10:27 PM, Lee Thomas wrote: > Hello FreeBSD devs, > > I have found a performance improvement to libc's strnlen(). > lib/libc/string/strnlen.c is a trivial byte-by-byte implementation, > where strlen.c has a smarter word-by-word implementation. I have > implemented strnlen similarly t

Performance improvement to strnlen().

2013-05-25 Thread Lee Thomas
Hello FreeBSD devs, I have found a performance improvement to libc's strnlen(). lib/libc/string/strnlen.c is a trivial byte-by-byte implementation, where strlen.c has a smarter word-by-word implementation. I have implemented strnlen similarly to strlen. It runs about 4x as fast, at the cost o