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 
capabilities:

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 
situations.

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

http://en.wikipedia.org/wiki/Fortran_95_language_features#WHERE

http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/topic/com.ibm.xlf101l.doc/xlflr/where.htm

Bye,
bearophile
Jul 13 2013