Skip to content

Incorrect result for log() on AVX2 with -ffast-math #1264

@geraintluff

Description

@geraintluff

Here's the relevant code excerpt:

LOG_EXPR(Arch::name());
auto batch = getBatch(expr.a, index);
LOG_EXPR(batch);
LOG_EXPR(xsimd::log(batch));
LOG_EXPR(batch.size);

And the dodgy output:

Arch::name() = avx2
batch = (0.60455, 0.635409, 0.891392, 0.871854)
xsimd::log(batch) = (0.189876, 0.23966, -0.114971, -0.137133)
batch.size = 4

The first two results are pretty wrong (they should be -0.50327 and -0.453487).

This only happens for me when using xsimd::avx2 and compiling with -mavx2 -ffast-math. If it's just -mavx2 alone then I don't get the issue. It might happen for other architectures as well, AVX is just the one I have access to.

Any ideas? I had a look through the code for log(), but couldn't see how the fast-math-specific bits would give this result.


EDIT: I get correct results (with or without fast-math) if I ignore AVX2 and send it down the xsimd::avx / -mavx code path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions