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

            Bug ID: 80857
           Summary: slow compare_exchange_weak with unintegral type
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sv_91 at inbox dot ru
  Target Milestone: ---

Created attachment 41403
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41403&action=edit
example

Compared to gcc 6.2.0, function func2 work slower:

gcc 6.2.0
Result 49999995000000. Time 110
Result 49999995000000. Time 110
gcc 7.1.0
Result 49999995000000. Time 98
Result 49999995000000. Time 154

Build options:
-m64 -Wextra -Wall -Werror -Wpedantic -Wformat-security -fno-builtin-malloc
-fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -pthread -std=c++17
-DNDEBUG -Ofast -funroll-loops -fomit-frame-pointer -Wno-misleading-indentation
-g -mfpmath=sse


Function func2 call function

template<typename T>
inline void atomic_fetch_add(std::atomic<T> &obj, const T& arg) noexcept {
    T current = obj;
    while (!obj.compare_exchange_weak(current, current + arg));
}

where T == std::chrono::milliseconds

Reply via email to