[clang] [X86][Headers] Specify result of NaN comparisons (PR #85862)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 19 13:22:53 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Paul T Robinson (pogo59)
<details>
<summary>Changes</summary>
Make sure all float/double comparison intrinsics specify what happens with a NaN input. Update some existing descriptions of comparison results to make them all consistent.
Also replace "yields" with "returns" throughout.
---
Patch is 44.79 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/85862.diff
3 Files Affected:
- (modified) clang/lib/Headers/avxintrin.h (+26-16)
- (modified) clang/lib/Headers/emmintrin.h (+93-61)
- (modified) clang/lib/Headers/xmmintrin.h (+68-30)
``````````diff
diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index ecd9bf18a41ca0..16f13a3fdfaf76 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -207,6 +207,8 @@ _mm256_div_ps(__m256 __a, __m256 __b)
/// Compares two 256-bit vectors of [4 x double] and returns the greater
/// of each pair of values.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMAXPD </c> instruction.
@@ -226,6 +228,8 @@ _mm256_max_pd(__m256d __a, __m256d __b)
/// Compares two 256-bit vectors of [8 x float] and returns the greater
/// of each pair of values.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMAXPS </c> instruction.
@@ -245,6 +249,8 @@ _mm256_max_ps(__m256 __a, __m256 __b)
/// Compares two 256-bit vectors of [4 x double] and returns the lesser
/// of each pair of values.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMINPD </c> instruction.
@@ -264,6 +270,8 @@ _mm256_min_pd(__m256d __a, __m256d __b)
/// Compares two 256-bit vectors of [8 x float] and returns the lesser
/// of each pair of values.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMINPS </c> instruction.
@@ -1604,9 +1612,9 @@ _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
/// 128-bit vectors of [2 x double], using the operation specified by the
/// immediate integer operand.
///
-/// Returns a [2 x double] vector consisting of two doubles corresponding to
-/// the two comparison results: zero if the comparison is false, and all 1's
-/// if the comparison is true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, comparisons marked as ordered
+/// return false, and comparisons marked as unordered return true.
///
/// \headerfile <x86intrin.h>
///
@@ -1663,9 +1671,9 @@ _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
/// [4 x float], using the operation specified by the immediate integer
/// operand.
///
-/// Returns a [4 x float] vector consisting of four floats corresponding to
-/// the four comparison results: zero if the comparison is false, and all 1's
-/// if the comparison is true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFF for true.
+/// If either value in a comparison is NaN, comparisons marked as ordered
+/// return false, and comparisons marked as unordered return true.
///
/// \headerfile <x86intrin.h>
///
@@ -1721,9 +1729,9 @@ _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
/// 256-bit vectors of [4 x double], using the operation specified by the
/// immediate integer operand.
///
-/// Returns a [4 x double] vector consisting of four doubles corresponding to
-/// the four comparison results: zero if the comparison is false, and all 1's
-/// if the comparison is true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, comparisons marked as ordered
+/// return false, and comparisons marked as unordered return true.
///
/// \headerfile <x86intrin.h>
///
@@ -1781,9 +1789,9 @@ _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
/// [8 x float], using the operation specified by the immediate integer
/// operand.
///
-/// Returns a [8 x float] vector consisting of eight floats corresponding to
-/// the eight comparison results: zero if the comparison is false, and all
-/// 1's if the comparison is true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFF for true.
+/// If either value in a comparison is NaN, comparisons marked as ordered
+/// return false, and comparisons marked as unordered return true.
///
/// \headerfile <x86intrin.h>
///
@@ -1842,8 +1850,9 @@ _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
/// two 128-bit vectors of [2 x double], using the operation specified by the
/// immediate integer operand.
///
-/// If the result is true, all 64 bits of the destination vector are set;
-/// otherwise they are cleared.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, comparisons marked as ordered
+/// return false, and comparisons marked as unordered return true.
///
/// \headerfile <x86intrin.h>
///
@@ -1900,8 +1909,9 @@ _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
/// vectors of [4 x float], using the operation specified by the immediate
/// integer operand.
///
-/// If the result is true, all 32 bits of the destination vector are set;
-/// otherwise they are cleared.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFF for true.
+/// If either value in a comparison is NaN, comparisons marked as ordered
+/// return false, and comparisons marked as unordered return true.
///
/// \headerfile <x86intrin.h>
///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 984f0cf917e99b..6908d6daebb841 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -259,6 +259,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_sqrt_pd(__m128d __a) {
/// result. The upper 64 bits of the result are copied from the upper
/// double-precision value of the first operand.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMINSD / MINSD </c> instruction.
@@ -278,9 +280,11 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_min_sd(__m128d __a,
}
/// Performs element-by-element comparison of the two 128-bit vectors of
-/// [2 x double] and returns the vector containing the lesser of each pair of
+/// [2 x double] and returns a vector containing the lesser of each pair of
/// values.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMINPD / MINPD </c> instruction.
@@ -301,6 +305,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_min_pd(__m128d __a,
/// result. The upper 64 bits of the result are copied from the upper
/// double-precision value of the first operand.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMAXSD / MAXSD </c> instruction.
@@ -320,9 +326,11 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_max_sd(__m128d __a,
}
/// Performs element-by-element comparison of the two 128-bit vectors of
-/// [2 x double] and returns the vector containing the greater of each pair
+/// [2 x double] and returns a vector containing the greater of each pair
/// of values.
///
+/// If either value in a comparison is NaN, returns the value from \a __b.
+///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VMAXPD / MAXPD </c> instruction.
@@ -412,7 +420,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_xor_pd(__m128d __a,
/// Compares each of the corresponding double-precision values of the
/// 128-bit vectors of [2 x double] for equality.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -432,7 +441,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpeq_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are less than those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -452,7 +462,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmplt_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are less than or equal to those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -472,7 +483,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmple_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are greater than those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -492,7 +504,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpgt_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are greater than or equal to those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -513,7 +526,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpge_pd(__m128d __a,
/// operand are ordered with respect to those in the second operand.
///
/// A pair of double-precision values are "ordered" with respect to each
-/// other if neither value is a NaN. Each comparison yields 0x0 for false,
+/// other if neither value is a NaN. Each comparison returns 0x0 for false,
/// 0xFFFFFFFFFFFFFFFF for true.
///
/// \headerfile <x86intrin.h>
@@ -535,7 +548,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpord_pd(__m128d __a,
/// operand are unordered with respect to those in the second operand.
///
/// A pair of double-precision values are "unordered" with respect to each
-/// other if one or both values are NaN. Each comparison yields 0x0 for
+/// other if one or both values are NaN. Each comparison returns 0x0 for
/// false, 0xFFFFFFFFFFFFFFFF for true.
///
/// \headerfile <x86intrin.h>
@@ -557,7 +570,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpunord_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are unequal to those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -577,7 +591,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpneq_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are not less than those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -597,7 +612,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnlt_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are not less than or equal to those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -617,7 +633,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnle_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are not greater than those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -637,7 +654,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpngt_pd(__m128d __a,
/// 128-bit vectors of [2 x double] to determine if the values in the first
/// operand are not greater than or equal to those in the second operand.
///
-/// Each comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -656,7 +674,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnge_pd(__m128d __a,
/// Compares the lower double-precision floating-point values in each of
/// the two 128-bit floating-point vectors of [2 x double] for equality.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -680,7 +699,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpeq_sd(__m128d __a,
/// the value in the first parameter is less than the corresponding value in
/// the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -704,7 +724,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmplt_sd(__m128d __a,
/// the value in the first parameter is less than or equal to the
/// corresponding value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -728,7 +749,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmple_sd(__m128d __a,
/// the value in the first parameter is greater than the corresponding value
/// in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -753,7 +775,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpgt_sd(__m128d __a,
/// the value in the first parameter is greater than or equal to the
/// corresponding value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns false.
///
/// \headerfile <x86intrin.h>
///
@@ -778,7 +801,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpge_sd(__m128d __a,
/// the value in the first parameter is "ordered" with respect to the
/// corresponding value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true. A pair
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true. A pair
/// of double-precision values are "ordered" with respect to each other if
/// neither value is a NaN.
///
@@ -804,7 +827,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpord_sd(__m128d __a,
/// the value in the first parameter is "unordered" with respect to the
/// corresponding value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true. A pair
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true. A pair
/// of double-precision values are "unordered" with respect to each other if
/// one or both values are NaN.
///
@@ -831,7 +854,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpunord_sd(__m128d __a,
/// the value in the first parameter is unequal to the corresponding value in
/// the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -855,7 +879,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpneq_sd(__m128d __a,
/// the value in the first parameter is not less than the corresponding
/// value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -879,7 +904,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnlt_sd(__m128d __a,
/// the value in the first parameter is not less than or equal to the
/// corresponding value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -903,7 +929,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnle_sd(__m128d __a,
/// the value in the first parameter is not greater than the corresponding
/// value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -928,7 +955,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpngt_sd(__m128d __a,
/// the value in the first parameter is not greater than or equal to the
/// corresponding value in the second parameter.
///
-/// The comparison yields 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// The comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
+/// If either value in a comparison is NaN, returns true.
///
/// \headerfile <x86intrin.h>
///
@@ -951,8 +979,8 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnge_sd(__m128d __a,
/// Compares the lower double-precision floating-point values in each of
/// the two 128-bit floating-point vectors of [2 x double] for equality.
///
-/// The comparison returns 0 for false, 1 for true. If either of the two
-/// lower double-precision values is NaN, returns 0.
+/// The comparison returns 0 for false, 1 for true. If either value in a
+/// comparison is NaN, returns 0.
///
/// \headerfile <x86intrin.h>
///
@@ -975,8 +1003,8 @@ static __inline__ int __DEFAULT_FN_ATTRS _mm_comieq_sd(__m128d __a,
/// the value in the first parameter is less than the corresponding value in
/// the second parameter.
///
-/// The comparison returns 0 for false, 1 for true. If either of the two
-/// lower double-precision values is NaN, returns 0.
+/// The comparison returns 0 for false, 1 for true. If either value in a
+/// comparison is NaN, returns 0.
///
/// \headerfile <x86intrin.h>
///
@@ -999,8 +1027,8 @@ static __inline__ int __DEFAULT_FN_ATTRS _mm_comilt_sd(__m128d __a,
/// the value in the first parameter is less than or equal to the
/// corresponding value in the second parameter.
///
-/// The comparison returns 0 for false, 1 for true. If either of the two
-/// lower double-precision values is NaN, re...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/85862
More information about the cfe-commits
mailing list