www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Good vectorized comparisons

Regarding comparisons in vectorized code, that are missing in D, 
it was discussed a bit a syntax like this, that has limited 

bool[8] flags1 = (a[] + b[]) <= x;
bool[8] flags2 = !isNan(a[]) && (a[] <= x);

But "recent" versions of the Fortran language support something 
similar to this (translated to D), that gets compiled with 
efficient SIMD instructions:

enum double x = 2.0;
double[8] a, b;
bool[8] flags;

if case ((a[] + b[]) > x)
     flags[] = false;

if case (isNan(a[]) || (a[] > x))
     flags[] = false;

double[] pressure, density, r;
double t;
if case (pressure[] >= 30.0) {
     density[] = pressure[] / (r[] * t);
} else {
     density[] = 30.0 / (r[] * t);

That syntax offers flexible code, it can be used in many 

What I have translated in D with a "if case" syntax is named 
"where" in Fortran90+:



Jul 13 2013