ppc64le: mlas: fix both MaximumFloat and MinimumFloat to return NAN (#12628)

Avoid using vec_max/vec_min because their behaviors are undefined if one
of
the elements is NAN. The Power Vector Intrinsic Programming Reference
says:

"For floating-point types, if both source elements contain signed
zeros, or if either source element contains a NaN, it is
undefined which of the two source elements is copied into
the corresponding result element."

As the unittest Activation.ShortExecute expects NAN, this patch uses
vec_sel and vec_cmpgt to return NAN if one of the elements is NAN.


https://git.openpower.foundation/systemsoftware/Programming-Guides/src/branch/master/Intrinsics_Reference/ch_vec_reference.xml#L26808
This commit is contained in:
Maxiwell S. Garcia 2022-10-14 17:43:58 -04:00 committed by GitHub
parent 4fe6b23699
commit 1ab11a111c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1804,7 +1804,8 @@ MlasMaximumFloat32x4(MLAS_FLOAT32X4 Vector1, MLAS_FLOAT32X4 Vector2)
#elif defined(MLAS_SSE2_INTRINSICS)
return _mm_max_ps(Vector1, Vector2);
#elif defined(MLAS_VSX_INTRINSICS)
return vec_max(Vector1, Vector2);
// Don't use vec_max to avoid undefined behavior if NAN
return vec_sel(Vector2, Vector1, vec_cmpgt(Vector1, Vector2));
#elif defined(MLAS_WASM_SIMD_INTRINSICS)
return wasm_f32x4_max(Vector1, Vector2);
#else
@ -1821,7 +1822,8 @@ MlasMinimumFloat32x4(MLAS_FLOAT32X4 Vector1, MLAS_FLOAT32X4 Vector2)
#elif defined(MLAS_SSE2_INTRINSICS)
return _mm_min_ps(Vector1, Vector2);
#elif defined(MLAS_VSX_INTRINSICS)
return vec_min(Vector1, Vector2);
// Don't use vec_min to avoid undefined behavior if NAN
return vec_sel(Vector2, Vector1, vec_cmpgt(Vector2, Vector1));
#elif defined(MLAS_WASM_SIMD_INTRINSICS)
return wasm_f32x4_min(Vector1, Vector2);
#else