Skip to content

Calling sqrt builtin function for packed singles instead of packed doubles #9

@maximiliank

Description

@maximiliank

The following example code does not compile with g++ 14.2.0 (No specific -march parameter):

#include <simd>
#include <vector>

int main()
{
    std::vector<double> data(std::datapar::simd<double>::size(), 0.05);
    std::datapar::simd<double> x = std::datapar::unchecked_load(data);
    auto xSqrt = std::datapar::sqrt(x);

    return 0;
}

The error message:

bits/simd_x86.h:2424:42: error: cannot convert ‘__vector(2) double’ to ‘__vector(4) float’
[build]  2424 |             return __builtin_ia32_sqrtps(__x);
[build]       |                                          ^~~
[build]       |                                          |
[build]       |                                          __vector(2) double
[build] <built-in>: note:   initializing argument 1 of ‘__vector(4) float __builtin_ia32_sqrtps(__vector(4) float)’

The wrong builtin function for sqrt is called and should be replaced with __builtin_ia32_sqrtpd for packed doubles:

return __builtin_ia32_sqrtps(__x);

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