Bug 15956 – Incorrect value inside enum using simd vectors, weird tym errors, and weird if(true) {} partial solution.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-25T18:35:22Z
Last change time
2018-10-12T23:10:55Z
Keywords
SIMD
Assigned to
No Owner
Creator
Lass Safin

Comments

Comment #0 by lasssafin — 2016-04-25T18:35:22Z
Consider this piece of code: import std.stdio : writeln; struct vec4 { import core.simd; string toString() const { import std.format : format; return "%s\t%s\t%s\t%s".format(vec.array[0], vec.array[1], vec.array[2], vec.array[3]); } float4 vec; this(in float[4] arr) { vec.array = arr; } // Switching the constructor out with this removes the if(true) error and corrects the value inside the enum. /+ this(in float4 arr) { vec = arr; } +/ } void main(string[] _ARGS) { enum vec4 enm = [1, 0.4, 0.6, 1]; enm.writeln; vec4 rntime = [1, 0.4, 0.6, 1]; rntime.writeln; // When uncommented causes error: incompatible types for ((rntime.vec) == (vec4([1.00000F, 0.4F, 0.6F, 1.00000F]).vec)): '__vector(float[4])' and '__vector(float[4])' // writeln(rntime == enm); Comparing only vec explicitly doesn't work either. // When commented causes error: // tym = x1d // Internal error: backend/cgxmm.c 547 if(true) {} // Condition can really be anything. } Output: 1 0 0 0 // enm 1 0.4 0.6 1 // rntime Output with -O: 1 0.4 0.6 1 // enm 1 0.4 0.6 1 // rntime As you can see, the value inside the enum is not the value one would expect there to be. There is also the error in comparing the two struct and the weird if(true) clause.
Comment #1 by joeks — 2018-10-01T17:08:56Z
As far as I can tell this problem stems from the fact, that some of the types in core.simd are not working AT ALL. Consider this simple example: double4 f; f[0] = 1.0; f[1] = 2.0; f[2] = 3.0; f[3] = 4.0; writeln(f); This outputs: [1, 2, 0, 6.95325e-310] I wonder has noone ever tried to use this type in any program or did not notice this obviously completely wrong result?
Comment #2 by joeks — 2018-10-01T17:09:51Z
As far as I can tell this problem stems from the fact, that some of the types in core.simd are not working AT ALL. Consider this simple example: double4 f; f[0] = 1.0; f[1] = 2.0; f[2] = 3.0; f[3] = 4.0; writeln(f); This outputs: [1, 2, 0, 6.95325e-310] I wonder has noone ever tried to use this type in any program or did not notice this obviously completely wrong result? Edit: Does work correctly with gdc.
Comment #3 by joeks — 2018-10-12T22:59:45Z
My example seems to be working now, could be that this has been fixed in 2.082.1. But I have not yet tested the original example.
Comment #4 by joeks — 2018-10-12T23:10:55Z
Tried it now, seems to work, too. with the constructor: this(in float4 arr) { vec = arr; } the output is correct for both variables. However the compile error with the float[4] accepting constructor is is still there. Also it did not matter if the 'if anything' was present or not. I suppose this is a different issue (or a feature?) and should therefore be addressed in a different thread. -> This can be closed?