On Thursday, 12 April 2018 at 07:25:27 UTC, Per Nordlöw wrote:
Neither GCC, LLVM nor ICC can auto-vectorize (and use SIMD) the seemly simple function

bool is_sorted(const int32_t* input, size_t n) {
    if (n < 2) {
        return true;

    for (size_t i=0; i < n - 1; i++) {
        if (input[i] > input[i + 1])
            return false;

    return true;

Can D's compilers do better?

See http://0x80.pl/notesen/2018-04-11-simd-is-sorted.html

I highly doubt it.
this cannot be auto-vectorized.
There is no way to proof the loop dimensions.

I'd be a different story if you unrolled the loop by hand.
I guess then you'd see gcc and clang putting some simd in there maybe.

Reply via email to