Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-43175

update mongo/platform/endian.h

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.1
    • Affects Version/s: None
    • Component/s: Internal Code
    • Labels:
      None
    • Fully Compatible
    • Dev Tools 2019-09-23, Dev Tools 2019-10-07

      This is a very low-level bare metal header, and should ideally #include only std headers.

      • Decimal128 doesn't need endian conversions, and makes endian.h transitively include several higher-level mongo specifics. Current conversions are underspecified and mathematically incorrect or at least ambiguous. They swap the order within each of the low64 and high64 fields, but don't swap them with each other. This is behavior needed only by one spot in db/pipeline/value.cpp to deserialize NumberDecimal, so we can just inline the behavior there and remove it from endian.h.
      • The running compiler holds the ultimate truth on what the target endianness is (available via _BYTE_ORDER_). We should not read it from a config header. The names exported into C++ code for the endian possibilities can be changed to line up with those in C++20's std::endian {big,little,native}

        enum. Remove MONGO_CONFIG_BYTE_ORDER from config.h. This eliminates the Scons<=>C++ bridge protocol of "1234" and "4321" magic numbers. Then Scons only talks to the compiler, not to the code.

      • Use enum expressions (including if constexpr) rather than #if for branching on endianness. This makes bit-rot of unexecuted paths less likely, and is just cleaner C++.
      • endian.h supports noisy old #if//#elif/... branches for getting compiler-builtin bswap operations. Can reduce to a simple MSVC vs GCC branching. All compilers have a builtin, so remove the bswap_slow" implementation.
      • Don't need all the push_macro / pop_macro stuff, or really any macros at all. Just rely on inline C++ functions. These optimize to the same thing. Don't need ByteOrderConverter or IntegralTypeMap either. Simpler metaprogramming will work fine. All in all we can utterly remove 400 lines of code there.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: