Giter Site home page Giter Site logo

Comments (8)

uecasm avatar uecasm commented on August 27, 2024

It looks like changing the definition of elsa to this fixes it for 32-bit MSVC. I assume that it would be more complicated for 64-bit, since it would have to do a 128-bit add. Unfortunately there doesn't appear to be any way to suppress the warning inside elsa itself, if it's called in a constexpr context, since the warning is raised at the point of use, not at its own code.

#if defined(_MSC_VER) && !defined(_WIN64)
  constexpr std::size_t operator()(T const &value, std::size_t seed) const {
      std::size_t key = seed ^ static_cast<std::size_t>(value);
      key = static_cast<std::size_t>(static_cast<uint64_t>(~key) + (key << 21));
      key = key ^ (key >> 24);
      key = static_cast<std::size_t>(static_cast<uint64_t>(key) + (key << 3) + (key << 8));
      key = key ^ (key >> 14);
      key = static_cast<std::size_t>(static_cast<uint64_t>(key) + (key << 2) + (key << 4));
      key = key ^ (key >> 28);
      key = static_cast<std::size_t>(static_cast<uint64_t>(key) + (key << 31));
      return key;
  }
#else
  constexpr std::size_t operator()(T const &value, std::size_t seed) const {
    std::size_t key = seed ^ static_cast<std::size_t>(value);
    key = (~key) + (key << 21); // key = (key << 21) - key - 1;
    key = key ^ (key >> 24);
    key = (key + (key << 3)) + (key << 8); // key * 265
    key = key ^ (key >> 14);
    key = (key + (key << 2)) + (key << 4); // key * 21
    key = key ^ (key >> 28);
    key = key + (key << 31);
    return key;
  }
#endif

from frozen.

serge-sans-paille avatar serge-sans-paille commented on August 27, 2024

I'd say overflow on a plus on unsigned type is not an issue because it's perfectly defined (unlike the signed version). What could be done instead of your cast is to apply a mask, as in (~key + (key << 21)) & ~std::size_t(0), does that silent the warning? or maybe static_caststd::size_t(~key + (key << 21)` ? If either of these work, feel free to open a PR!

from frozen.

uecasm avatar uecasm commented on August 27, 2024

No, those don't help; but I wouldn't really expect them to, since the warning is raised for the + operator itself, not the assignment back into key.

from frozen.

degski avatar degski commented on August 27, 2024

@serge-sans-paille clang-cl doesn't warn on this. Maybe just suppress the warning?

from frozen.

uecasm avatar uecasm commented on August 27, 2024

Sadly the warning is raised at point of constexpr variable use, not anywhere inside elsa itself, as I mentioned above. This makes it impossible to suppress the warning inside the library, except by changing the operand types of + as proposed above so that overflow can't occur.

I did file a bug with MS about the warning behaviour, so we can just sit on it and see if anything comes of that.

from frozen.

serge-sans-paille avatar serge-sans-paille commented on August 27, 2024

from frozen.

degski avatar degski commented on August 27, 2024

@serge-sans-paille Yes, something like this, there are various options, more or less portable.

from frozen.

uecasm avatar uecasm commented on August 27, 2024

@degski So, how many different ways do you want me to tell you that pragma suppressions don't work? Because this is the third time I've said that.

from frozen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.