Boost logo

Boost :

Subject: Re: [boost] [uuids] On boost::uuids::uuid operator == performance.
From: Michael Kochetkov (michael.kv_at_[hidden])
Date: 2012-04-16 10:37:54


> 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. 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.

--
Michael Kochetkov

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