Research Article
Inastemp: A Novel Intrinsics-as-Template Library for Portable SIMD-Vectorization
Code 13
Inastemp testing the Boolean vector to avoid computing all branches.
(1) InaVecBestType<double> aKernel(const InaVecBestType<double> v1, const InaVecBestType<double> v2) | (2) // Same as: | (3) // return InaVecBestType<double>::IfElse(v1 < v2, (v1 − v2).exp(), (v2 − v1).exp()); | (4) // Both (v1−v2).exp() and (v2−v1).exp() are computed | (5) return InaVecBestType<double>::If(v1 < v2) | (6) .Then((v1−v2).exp()) | (7) .Else((v2−v1).exp()); | (8) | (9) | (10) InaVecBestType<double> aKernelWithTest(const InaVecBestType<double> v1, const … | InaVecBestType<double> v2) | (11) const InaVecBestType<double>::MaskType v1lowerv2 = (v1 < v2); | (12) // Similar to v1lowerv2 == InaVecBestType<double>::MaskType(true) | (13) if( v1lowerv2.isAllTrue() ) | (14) return (v1−v2).exp(); | (15) | (16) return InaVecBestType<double>::If(v1lowerv2) | (17) .Then((v1−v2).exp()) | (18) .Else((v2−v1).exp()); | (19) |
|