mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
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:
parent
4fe6b23699
commit
1ab11a111c
1 changed files with 4 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue