Skip to content

Erroneous sin value when passed an integer and using libmvec #138171

Open
@etiennemlb

Description

@etiennemlb

Given the following program:

#include <cmath>
#include <cstdio>
void fn5() {
    static constexpr int the_value_count = 64;

    float the_large_array_1[the_value_count]{};

    for (int ivalue = 0; ivalue < the_value_count; ++ivalue) {
        the_large_array_1[ivalue] = std::sin(ivalue);
    }

    for (int ivalue = 0; ivalue < the_value_count; ++ivalue) {
        float ref = std::sin(static_cast<float>(ivalue));
        if (ref != the_large_array_1[ivalue])
            printf("%d %f %f\n", ivalue, static_cast<double>(ref),
                   static_cast<double>(the_large_array_1[ivalue]));
    }
}
int main() { fn5(); }

I get the output:

ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0
2 0.909297 -0.166667
3 0.141120 -0.158529
6 -0.279415 -0.160633
7 0.656987 -0.153471
10 -0.544021 -0.150545
11 -0.999990 -0.165169
14 0.990607 -0.164014
15 0.650288 -0.165107
18 -0.750987 -0.165957
19 0.149877 -0.153296
22 -0.008851 -0.155979
23 -0.846220 -0.158669
26 0.762558 -0.156295
27 0.956376 -0.166520
30 -0.988032 -0.166041
31 -0.404038 -0.162333
34 0.529083 -0.163847
35 -0.428183 -0.147580
38 0.296369 -0.150162
39 0.963795 -0.162641
42 -0.916522 -0.160875
43 -0.831775 -0.166455
46 0.901788 -0.166664
47 0.123573 -0.158245
50 -0.262375 -0.160386
51 0.670229 -0.153819
54 -0.558789 -0.150925
55 -0.999755 -0.165291
58 0.992873 -0.164176
59 0.636738 -0.164977
62 -0.739181 -0.165869
63 0.167356 -0.152942

Check it out at:
https://godbolt.org/z/ad55fr3b1

The program output is erroneous, the sin value is completely wrong. The last two columns should be similar.
The behavior changes if we merge the two loops.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions