Skip to content

Conversation

pogo59
Copy link
Collaborator

@pogo59 pogo59 commented Feb 28, 2024

Comparison intrinsics were described as returning the "result" without specifying how. The "cmp" intrinsics return zero or all 1's in the corresponding elements of a returned vector; the "com" intrinsics return an integer 0 or 1.

Also removed some redundant information.

Comparison intrinsics were described as returning the "result" without
specifying how. The "cmp" intrinsics return zero or all 1's in the
corresponding elements of a returned vector; the "com" intrinsics return
an integer 0 or 1.

Also removed some redundant information.
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Feb 28, 2024
@pogo59
Copy link
Collaborator Author

pogo59 commented Feb 28, 2024

Also tag @cflores for your review.

@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Paul T Robinson (pogo59)

Changes

Comparison intrinsics were described as returning the "result" without specifying how. The "cmp" intrinsics return zero or all 1's in the corresponding elements of a returned vector; the "com" intrinsics return an integer 0 or 1.

Also removed some redundant information.


Patch is 23.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/83316.diff

2 Files Affected:

  • (modified) clang/lib/Headers/smmintrin.h (+4-2)
  • (modified) clang/lib/Headers/xmmintrin.h (+81-65)
diff --git a/clang/lib/Headers/smmintrin.h b/clang/lib/Headers/smmintrin.h
index 005d7db9c3c308..ba593835b9b3dc 100644
--- a/clang/lib/Headers/smmintrin.h
+++ b/clang/lib/Headers/smmintrin.h
@@ -1186,7 +1186,8 @@ static __inline__ int __DEFAULT_FN_ATTRS _mm_testnzc_si128(__m128i __M,
 
 /* SSE4 64-bit Packed Integer Comparisons.  */
 /// Compares each of the corresponding 64-bit values of the 128-bit
-///    integer vectors for equality.
+///    integer vectors for equality. Returns zero for false and all 1's for
+///    true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -2303,7 +2304,8 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_minpos_epu16(__m128i __V) {
 /* SSE4.2 Compare Packed Data -- Greater Than.  */
 /// Compares each of the corresponding 64-bit values of the 128-bit
 ///    integer vectors to determine if the values in the first operand are
-///    greater than those in the second operand.
+///    greater than those in the second operand. Returns zero for false and
+///    all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
diff --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 47368f3c23d2d6..d8ad5ae526a45f 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -474,8 +474,8 @@ _mm_xor_ps(__m128 __a, __m128 __b)
 }
 
 /// Compares two 32-bit float values in the low-order bits of both
-///    operands for equality and returns the result of the comparison in the
-///    low-order bits of a vector [4 x float].
+///    operands for equality and returns the result of the comparison (zero for
+///    false, all 1's for true) in the low-order bits of a vector [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -496,7 +496,8 @@ _mm_cmpeq_ss(__m128 __a, __m128 __b)
 }
 
 /// Compares each of the corresponding 32-bit float values of the
-///    128-bit vectors of [4 x float] for equality.
+///    128-bit vectors of [4 x float] for equality. Returns zero for false and
+///    all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -516,7 +517,8 @@ _mm_cmpeq_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is less than the
 ///    corresponding value in the second operand and returns the result of the
-///    comparison in the low-order bits of a vector of [4 x float].
+///    comparison (zero for false, all 1's for true) in the low-order bits of a
+///    vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -538,7 +540,8 @@ _mm_cmplt_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
-///    operand are less than those in the second operand.
+///    operand are less than those in the second operand. Returns zero for
+///    false and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -558,8 +561,8 @@ _mm_cmplt_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is less than or
 ///    equal to the corresponding value in the second operand and returns the
-///    result of the comparison in the low-order bits of a vector of
-///    [4 x float].
+///    result of the comparison (zero for false, all 1's for true) in the
+///    low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -581,7 +584,9 @@ _mm_cmple_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
-///    operand are less than or equal to those in the second operand.
+///    operand are less than or equal to those in the second operand. Returns
+///    zero for false and all 1's for true in corresponding elements of the
+///    result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -601,7 +606,8 @@ _mm_cmple_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is greater than
 ///    the corresponding value in the second operand and returns the result of
-///    the comparison in the low-order bits of a vector of [4 x float].
+///    the comparison (zero for false, all 1's for true) in the low-order bits
+///    of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -625,7 +631,8 @@ _mm_cmpgt_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
-///    operand are greater than those in the second operand.
+///    operand are greater than those in the second operand. Returns zero for
+///    false and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -645,8 +652,8 @@ _mm_cmpgt_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is greater than
 ///    or equal to the corresponding value in the second operand and returns
-///    the result of the comparison in the low-order bits of a vector of
-///    [4 x float].
+///    the result of the comparison (zero for false, all 1's for true) in the
+///    low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -671,6 +678,8 @@ _mm_cmpge_ss(__m128 __a, __m128 __b)
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
 ///    operand are greater than or equal to those in the second operand.
+///    Returns zero for false and all 1's for true in corresponding elements of
+///    the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -687,9 +696,9 @@ _mm_cmpge_ps(__m128 __a, __m128 __b)
   return (__m128)__builtin_ia32_cmpleps((__v4sf)__b, (__v4sf)__a);
 }
 
-/// Compares two 32-bit float values in the low-order bits of both
-///    operands for inequality and returns the result of the comparison in the
-///    low-order bits of a vector of [4 x float].
+/// Compares two 32-bit float values in the low-order bits of both operands
+///    for inequality and returns the result of the comparison (zero for false,
+///    all 1's for true) in the low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -711,7 +720,8 @@ _mm_cmpneq_ss(__m128 __a, __m128 __b)
 }
 
 /// Compares each of the corresponding 32-bit float values of the
-///    128-bit vectors of [4 x float] for inequality.
+///    128-bit vectors of [4 x float] for inequality. Returns zero for false
+///    and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -732,7 +742,8 @@ _mm_cmpneq_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is not less than
 ///    the corresponding value in the second operand and returns the result of
-///    the comparison in the low-order bits of a vector of [4 x float].
+///    the comparison (zero for false, all 1's for true) in the low-order bits
+///    of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -755,7 +766,8 @@ _mm_cmpnlt_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
-///    operand are not less than those in the second operand.
+///    operand are not less than those in the second operand. Returns zero for
+///    false and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -776,8 +788,8 @@ _mm_cmpnlt_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is not less than
 ///    or equal to the corresponding value in the second operand and returns
-///    the result of the comparison in the low-order bits of a vector of
-///    [4 x float].
+///    the result of the comparison (zero for false, all 1's for true) in the
+///    low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -801,6 +813,8 @@ _mm_cmpnle_ss(__m128 __a, __m128 __b)
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
 ///    operand are not less than or equal to those in the second operand.
+///    Returns zero for false and all 1's for true in corresponding elements of
+///    the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -821,8 +835,8 @@ _mm_cmpnle_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is not greater
 ///    than the corresponding value in the second operand and returns the
-///    result of the comparison in the low-order bits of a vector of
-///    [4 x float].
+///    result of the comparison (zero for false, all 1's for true) in the
+///    low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -847,7 +861,8 @@ _mm_cmpngt_ss(__m128 __a, __m128 __b)
 
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
-///    operand are not greater than those in the second operand.
+///    operand are not greater than those in the second operand. Returns zero
+///    for false and all 1's for true in corresponding elements of the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -868,8 +883,8 @@ _mm_cmpngt_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is not greater
 ///    than or equal to the corresponding value in the second operand and
-///    returns the result of the comparison in the low-order bits of a vector
-///    of [4 x float].
+///    returns the result of the comparison (zero for false, all 1's for true)
+///    in the low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -895,6 +910,8 @@ _mm_cmpnge_ss(__m128 __a, __m128 __b)
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
 ///    operand are not greater than or equal to those in the second operand.
+///    Returns zero for false and all 1's for true in corresponding elements of
+///    the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -915,8 +932,8 @@ _mm_cmpnge_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is ordered with
 ///    respect to the corresponding value in the second operand and returns the
-///    result of the comparison in the low-order bits of a vector of
-///    [4 x float].
+///    result of the comparison (zero for false, all 1's for true) in the
+///    low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -940,6 +957,8 @@ _mm_cmpord_ss(__m128 __a, __m128 __b)
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
 ///    operand are ordered with respect to those in the second operand.
+///    Returns zero for false and all 1's for true in corresponding elements of
+///    the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -960,8 +979,8 @@ _mm_cmpord_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the value in the first operand is unordered
 ///    with respect to the corresponding value in the second operand and
-///    returns the result of the comparison in the low-order bits of a vector
-///    of [4 x float].
+///    returns the result of the comparison (zero for false, all 1's for true)
+///    in the low-order bits of a vector of [4 x float].
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -985,6 +1004,8 @@ _mm_cmpunord_ss(__m128 __a, __m128 __b)
 /// Compares each of the corresponding 32-bit float values of the
 ///    128-bit vectors of [4 x float] to determine if the values in the first
 ///    operand are unordered with respect to those in the second operand.
+///    Returns zero for false and all 1's for true in corresponding elements of
+///    the result.
 ///
 /// \headerfile <x86intrin.h>
 ///
@@ -1003,7 +1024,8 @@ _mm_cmpunord_ps(__m128 __a, __m128 __b)
 }
 
 /// Compares two 32-bit float values in the low-order bits of both
-///    operands for equality and returns the result of the comparison.
+///    operands for equality and returns the result of the comparison: 0 for
+///    false, 1 for true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1018,8 +1040,7 @@ _mm_cmpunord_ps(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the
-///    two lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comieq_ss(__m128 __a, __m128 __b)
 {
@@ -1028,7 +1049,8 @@ _mm_comieq_ss(__m128 __a, __m128 __b)
 
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the first operand is less than the second
-///    operand and returns the result of the comparison.
+///    operand and returns the result of the comparison: 0 for false, 1 for
+///    true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1043,8 +1065,7 @@ _mm_comieq_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the two
-///     lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comilt_ss(__m128 __a, __m128 __b)
 {
@@ -1053,7 +1074,8 @@ _mm_comilt_ss(__m128 __a, __m128 __b)
 
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the first operand is less than or equal to the
-///    second operand and returns the result of the comparison.
+///    second operand and returns the result of the comparison: 0 for false, 1
+///    for true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1067,8 +1089,7 @@ _mm_comilt_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the two
-///     lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comile_ss(__m128 __a, __m128 __b)
 {
@@ -1077,7 +1098,8 @@ _mm_comile_ss(__m128 __a, __m128 __b)
 
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the first operand is greater than the second
-///    operand and returns the result of the comparison.
+///    operand and returns the result of the comparison: 0 for false, 1 for
+///    true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1091,8 +1113,7 @@ _mm_comile_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the
-///     two lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comigt_ss(__m128 __a, __m128 __b)
 {
@@ -1101,7 +1122,8 @@ _mm_comigt_ss(__m128 __a, __m128 __b)
 
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the first operand is greater than or equal to
-///    the second operand and returns the result of the comparison.
+///    the second operand and returns the result of the comparison: 0 for
+///    false, 1 for true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1115,8 +1137,7 @@ _mm_comigt_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the two
-///    lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comige_ss(__m128 __a, __m128 __b)
 {
@@ -1125,7 +1146,8 @@ _mm_comige_ss(__m128 __a, __m128 __b)
 
 /// Compares two 32-bit float values in the low-order bits of both
 ///    operands to determine if the first operand is not equal to the second
-///    operand and returns the result of the comparison.
+///    operand and returns the result of the comparison: 0 for false, 1 for
+///    true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 1 is returned.
 ///
@@ -1139,8 +1161,7 @@ _mm_comige_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the
-///     two lower 32-bit values is NaN, 1 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comineq_ss(__m128 __a, __m128 __b)
 {
@@ -1149,7 +1170,7 @@ _mm_comineq_ss(__m128 __a, __m128 __b)
 
 /// Performs an unordered comparison of two 32-bit float values using
 ///    the low-order bits of both operands to determine equality and returns
-///    the result of the comparison.
+///    the result of the comparison: 0 for false, 1 for true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1163,8 +1184,7 @@ _mm_comineq_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the two
-///     lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_ucomieq_ss(__m128 __a, __m128 __b)
 {
@@ -1173,7 +1193,8 @@ _mm_ucomieq_ss(__m128 __a, __m128 __b)
 
 /// Performs an unordered comparison of two 32-bit float values using
 ///    the low-order bits of both operands to determine if the first operand is
-///    less than the second operand and returns the result of the comparison.
+///    less than the second operand and returns the result of the comparison:
+///    0 for false, 1 for true.
 ///
 ///    If either of the two lower 32-bit values is NaN, 0 is returned.
 ///
@@ -1187,8 +1208,7 @@ _mm_ucomieq_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///    A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///    used in the comparison.
-/// \returns An integer containing the comparison results. If either of the two
-///    lower 32-bit values is NaN, 0 is returned.
+/// \returns An integer containing the comparison results.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_ucomilt_ss(__m128 __a, __m128 __b)
 {
@@ -1198,7 +1218,7 @@ _mm_ucomilt_ss(__m128 __a, __m128 __b)
 /// Performs an unordered comparison of two 32-bit float values using
 ///    the low-order bits of both operands to determine if the first operand is
 ///    less than or equal to the second operand and returns the ...
[truncated]

Copy link
Contributor

@phoebewang phoebewang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 2, 2024

@pogo This doesn't match what we did for the various cmp intrinsics in emmintrin.h - should it?

/// Compares each of the corresponding signed 32-bit values of the
///    128-bit integer vectors to determine if the values in the first operand
///    are greater than those in the second operand.
///
///    Each comparison yields 0x0 for false, 0xFFFFFFFF for true.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VPCMPGTD / PCMPGTD </c> instruction.

@pogo59
Copy link
Collaborator Author

pogo59 commented Mar 8, 2024

@RKSimon I was not aware of the comparison intrinsics in emmintrin.h. I will follow that pattern.

@pogo59
Copy link
Collaborator Author

pogo59 commented Mar 8, 2024

@RKSimon note this will affect what the tooltips show. Is that okay?

Copy link

github-actions bot commented Mar 8, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 8, 2024

@RKSimon note this will affect what the tooltips show. Is that okay?

I think so - we're just losing the extra info about -1/0 or 1/0 result values?

@pogo59
Copy link
Collaborator Author

pogo59 commented Mar 8, 2024

I think so - we're just losing the extra info about -1/0 or 1/0 result values?

That's my understanding. I haven't actually tried regenerating the tooltips to check.

@pogo59 pogo59 merged commit 725a052 into llvm:main Mar 11, 2024
@pogo59 pogo59 deleted the intrin-compare branch October 3, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants