On sábado, 11 de fevereiro de 2017 10:43:53 PST Gonzalo BG wrote:
> @Thiago:
> > We used to have this problem with Clang: for example,
> > qCountTrailingZeroBits wasn't constexpr with Clang until 3.8, because we
> > couldn't use __builtin_ctz in a constexpr context.
>
> Given that you have run into the issue, I cannot find the logic in the
>
> following statement:
> > But in our experience, any algorithm that can be complex enough to
> > warrant SIMD optimisation is too complex for a constexpr inline function.
>
> You seem to be arguing that using __builtin_ctz in a constexpr function is
> reasonable, but using any other intrinsics while solving problems in any
> other domain is not. Care to elaborate on which experience makes you say so?
It was a problem, but it's now fixed and we now can use the builtin that is
constexpr.
> 1) The post C++11 standard library. Before C++11 I rarely saw people
> reimplementing pow, log, exp, sin, ... After C++11 almost every single
> project had its own pow constexpr implementation because neither the math
> functions from the standard library nor the builtins provided by the
> compilers worked inside constant expressions for years after C++11. The
> run-time performance of these functions was, and still is, horrible. The
> fix for this was to make the math functions in the standard constexpr, but
> this did not solve the underlying issue (which is being discussed here).
That's an interesting example, but it doesn't match my experience. I haven't
seen a lot of people need exponentiation and logarithm in constexpr constexts.
In regular code, you simply rely on the optimiser propagating constants,
something compilers have done for a decade.
> 2) Math/Linear algebra libraries like Eigen3, Blaze, ... which have used
> expression template hacks for compile-time computations for the last 20
> years _cannot_ use constexpr anywhere in their API (and don't really use it
> almost anywhere) because somewhere down the pipeline they do use intrinsics
> (and pragmas and what not) for run-time performance reasons.
Same as above: I've never seen the need for those operations to appear in a
constexpr context in the first place. It is as I said: the majority of the
operations that benefit from non-constexpr'able code is too complex for
constexpr anyway.
> Do you consider using a log function (which is implemented using intrinsics
> in most standard libraries) or multiplying two 4x4 matrices "too complex"
> for constexpr functions?
Yes, in my experience.
Or, put another way, what use-case warrants storing the result of such an
operation in a constexpr variable? This is a real question, you probably know
more cases than I do.