Issue 20041 - CTFE incorrect result with __vector
Summary: CTFE incorrect result with __vector
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 critical
Assignee: No Owner
URL:
Keywords: CTFE, pull, SIMD
Depends on:
Blocks:
 
Reported: 2019-07-10 19:48 UTC by thomas.bockman
Modified: 2020-12-28 17:57 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description thomas.bockman 2019-07-10 19:48:55 UTC
import std.stdio;

struct Vec3Fast {
    __vector(float[4]) raw;

    this(const(float[3]) value...) inout pure @safe nothrow @nogc {
        __vector(float[4]) raw;
        raw[0 .. 3] = value[];
        raw[3] = 0.0f;
        this.raw = raw;
    }
}

void main() {
    static immutable Vec3Fast v = Vec3Fast(  1.0f, 2.0f, 3.0f );

    static foreach(d; 0 .. 4)
    	write(v.raw[d], " ");
}

With CTFE, the above prints "nan nan nan nan ", which is wrong. If I remove the `static immutable`, it prints "1 2 3 0" as it should.
Comment 1 Walter Bright 2020-12-24 10:32:46 UTC
A simpler example:

  import core.stdc.stdio;
  import core.simd;

  immutable(float4) foo() {
    float4 raw;
    raw[0] = 1;
    return cast(immutable)raw;
  }

  void main() {
    static immutable float4 v = foo();

    foreach(d; 0 .. 4)
    	printf("%g ", v[d]);
    printf("\n");
  }
Comment 2 Dlang Bot 2020-12-27 09:11:54 UTC
@WalterBright created dlang/dmd pull request #12057 "fix Issue 20041 - CTFE incorrect result with __vector" fixing this issue:

- fix Issue 20041 - CTFE incorrect result with __vector

https://github.com/dlang/dmd/pull/12057
Comment 3 Dlang Bot 2020-12-28 17:57:18 UTC
dlang/dmd pull request #12057 "fix Issue 20041 - CTFE incorrect result with __vector" was merged into master:

- 716b3e0df17f568f31ffb264390d96ee28485db9 by Walter Bright:
  fix Issue 20041 - CTFE incorrect result with __vector

https://github.com/dlang/dmd/pull/12057