https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95286

            Bug ID: 95286
           Summary: -march=native causes mt19937_64 +
                    uniform_real_distribution generating wrong result.
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: euloanty at live dot com
  Target Milestone: ---

#include<random>
#include<iostream>

int main()
{
        std::mt19937_64 eng;
        std::uniform_real_distribution dis(-10000.0f,10000.0f);
        float v{};
        for(std::size_t i(0);i!=36;++i)
                v=dis(eng);
        static_assert(sizeof(float)==sizeof(std::uint32_t));
        std::uint32_t puned;
        memcpy(std::addressof(puned),std::addressof(v),sizeof(std::uint32_t));
        std::cout<<puned<<'\n';
}

First one is correct I believe since MSVC also generates the same result.
D:\hg\fast_io\helpers\fp>g++ -o dontagree dontagree.cc -Ofast -std=c++20 -s
-Ofast

D:\hg\fast_io\helpers\fp>dontagree
3298476032

D:\hg\fast_io\helpers\fp>g++ -o dontagree dontagree.cc -Ofast -std=c++20 -s
-march=native

D:\hg\fast_io\helpers\fp>dontagree
3298476035

I test the same thing under Linux. Same problem here.

Reply via email to