Boost logo

Boost :

Subject: Re: [boost] [uuids] On boost::uuids::uuid operator == performance.
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-16 11:37:35


on Mon Apr 16 2012, Michael Kochetkov <michael.kv-AT-gmail.com> wrote:

>> Don't forget alignment. Those DWORD comparisons/copies may only work
>> well for aligned memory but when you call memcmp, you erase alignment
>> information and the compiler may assume it's only char-aligned.
>
> I did not forget it. My words about alignment was just skipped.

I didn't see your words about alignment, and I was responding to Peter.

> No doubt you can align uuid::data[16] almost any suitable way even for
> uint64_t. You can even start the comparison from the back if you feel
> that your uuids start to differ from the back to speed up the approach
> even more.
>
> I would also like to confirm and further elaborate the statement in the
> discussion (I will not quote it from another message) that memcmp is
> intrinsic in MSCV for many cases (I have enforced it with Oi compiler
> switch), it is alignment, underlying data type and array sizes aware. You
> may want to have a look at the following example:
> #include <cstdint>
> #include <cstring>
>
> int main() {
> uint8_t d1[16], d2[16];
> return memcmp(d1,d2,16);
> }
> Here is the result.
>
> $LL4_at_main:
> mov esi, DWORD PTR [edx]
> cmp esi, DWORD PTR [ecx]
> jne SHORT $LN5_at_main
> sub eax, 4
> add ecx, 4
> add edx, 4
> cmp eax, 4
> jae SHORT $LL4_at_main
> xor eax, eax
>
> Pretty neat. I wish the boost and C++ standard library to develop the
> same way.

Yeah, that's great. My point is that it may well be that

 int main() {
         uint8_t d1[16], d2[16];
         return memcmp((char*)d1,(char*)d2,16);
 }

(or something only a little more complex, like a call through another
layer of inline function) is enough to foil that optimization.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk