x86 intrinsics act weird in boost::uuids::operator <

112 Views Asked by At

I'm using boost::uuids inside maps (labeled_graph, actually), so I need a properly working operator <. Unfortunately it isn't, if BOOST_UUID_USE_SSE2 is enabled (and thus, uuid_x86.hpp is used).

Here is example code:

#include <boost/uuid/nil_generator.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <string>
#include <sstream>
#include <iostream>

#include <assert.h>

#define CHECK(x)  do { if(x) { std::cout << #x << "\n"; } } while(0)

static inline boost::uuids::uuid StringToUuid(const std::string &str)
{
    boost::uuids::uuid u = boost::uuids::nil_uuid();
    std::stringstream uuidstring(str);
    uuidstring >> u;
    return u;
}

int main() {
    boost::uuids::uuid vmi_uuid = StringToUuid("00000000-0000-0000-0000-000000000001");
    boost::uuids::uuid vmi2_uuid = StringToUuid("00000000-0000-0000-0000-000000000002");

    CHECK(vmi_uuid != vmi2_uuid);
    CHECK(vmi_uuid < vmi2_uuid);
    CHECK(vmi2_uuid < vmi_uuid);

    return 0;
}

When uuid_x86.hpp is used, operator< is incosistent -- returns false in both cases:

vmi_uuid != vmi2_uuid

Disabling intrinsic-based header returns things back to normal:

vmi_uuid != vmi2_uuid
vmi_uuid < vmi2_uuid

This is reproducable only with special UUIDs (1 and 2), having totally random ids doesn't reveal this problem.

I have Ubuntu Xenial with libboost 1.58. CPU is i7-6600U if it matters. Am I missing something?

0

There are 0 best solutions below