Good vectorized comparisons
bearophile
bearophileHUGS at lycos.com
Sat Jul 13 03:46:15 PDT 2013
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
More information about the Digitalmars-d
mailing list