public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109029] New: std::signbit(double) generiert sehr ineffizienten code
@ 2023-03-05 12:08 g.peterhoff@t-online.de
  2023-03-05 12:11 ` [Bug c++/109029] " g.peterhoff@t-online.de
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: g.peterhoff@t-online.de @ 2023-03-05 12:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109029
           Summary: std::signbit(double) generiert sehr ineffizienten code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: g.peterhoff@t-online.de
  Target Milestone: ---

Hallo,
std::signbit(double) generiert sehr ineffizienten code und kann somit nicht
vektorisiert werden (https://godbolt.org/z/se6Ea8bo9).

thx
Gero

-std=c++20 -march=x86-64-v3 -O3 -mno-vzeroupper

#include <cmath>
#include <array>
#include <numbers>
#include <algorithm>

static constexpr size_t Size = 1024;

using float80_t = long double;
using float64_t = double;
using float32_t = float;

template <typename Type>
inline constexpr bool   foo(const Type x)   noexcept
{
    return std::signbit(x);
}

template <typename Type>
inline constexpr Type   bar(const Type x)   noexcept
{
   return std::signbit(x) ? std::numbers::pi_v<Type> : 0;
}

template <typename Container, typename Function>
inline constexpr void for_all(Container& cnt, Function&& f)     noexcept
{
        std::transform(cnt.begin(), cnt.end(), cnt.begin(), f);
}

template <typename ContainerRes, typename ContainerArg, typename Function>
inline constexpr void for_all(ContainerRes& res, const ContainerArg& arg,
Function&& f) noexcept
{
        std::transform(arg.begin(), arg.end(), res.begin(), f);
}

float64_t foo64(const float64_t x)   noexcept { return foo(x); }
float32_t foo32(const float32_t x)   noexcept { return foo(x); }

float64_t bar64(const float64_t x)   noexcept { return bar(x); }
float32_t bar32(const float32_t x)   noexcept { return bar(x); }

void foos64(std::array<bool, Size>& res, const std::array<float64_t, Size>&
arg)   noexcept { for_all(res, arg, foo<float64_t>); }
void foos32(std::array<bool, Size>& res, const std::array<float32_t, Size>&
arg)   noexcept { for_all(res, arg, foo<float32_t>); }

void bars64(std::array<float64_t, Size>& cnt)   noexcept { for_all(cnt,
bar<float64_t>); }
void bars32(std::array<float32_t, Size>& cnt)   noexcept { for_all(cnt,
bar<float32_t>); }

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-03-31  7:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-05 12:08 [Bug c++/109029] New: std::signbit(double) generiert sehr ineffizienten code g.peterhoff@t-online.de
2023-03-05 12:11 ` [Bug c++/109029] " g.peterhoff@t-online.de
2023-03-05 19:18 ` [Bug tree-optimization/109029] __builtin_signbit for 64bit fp does not vectorize pinskia at gcc dot gnu.org
2023-03-06  8:52 ` rguenth at gcc dot gnu.org
2023-03-31  3:37 ` crazylht at gmail dot com
2023-03-31  4:16 ` crazylht at gmail dot com
2023-03-31  5:47 ` crazylht at gmail dot com
2023-03-31  5:52 ` crazylht at gmail dot com
2023-03-31  6:22 ` crazylht at gmail dot com
2023-03-31  7:19 ` crazylht at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).