Skip to content

[Headers][X86] Add rounding and exception notes to conversions #83447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions clang/lib/Headers/avxintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,10 @@ _mm256_cvtpd_ps(__m256d __a)

/// Converts a vector of [8 x float] into a vector of [8 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTPS2DQ </c> instruction.
Expand Down Expand Up @@ -2242,9 +2246,13 @@ _mm256_cvtps_pd(__m128 __a)
return (__m256d)__builtin_convertvector((__v4sf)__a, __v4df);
}

/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of [4
/// x i32], truncating the result by rounding towards zero when it is
/// inexact.
/// Converts a 256-bit vector of [4 x double] into four signed truncated
/// (rounded toward zero) 32-bit integers returned in a 128-bit vector of
/// [4 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -2259,9 +2267,12 @@ _mm256_cvttpd_epi32(__m256d __a)
return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
}

/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of [4
/// x i32]. When a conversion is inexact, the value returned is rounded
/// according to the rounding control bits in the MXCSR register.
/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
/// [4 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -2276,8 +2287,12 @@ _mm256_cvtpd_epi32(__m256d __a)
return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a);
}

/// Converts a vector of [8 x float] into a vector of [8 x i32],
/// truncating the result by rounding towards zero when it is inexact.
/// Converts a vector of [8 x float] into eight signed truncated (rounded
/// toward zero) 32-bit integers returned in a vector of [8 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand Down
62 changes: 48 additions & 14 deletions clang/lib/Headers/emmintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,10 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtepi32_pd(__m128i __a) {
/// returned in the lower 64 bits of a 128-bit vector of [4 x i32]. The upper
/// 64 bits of the result vector are set to zero.
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTPD2DQ / CVTPD2DQ </c> instruction.
Expand All @@ -1319,6 +1323,10 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtpd_epi32(__m128d __a) {
/// Converts the low-order element of a 128-bit vector of [2 x double]
/// into a 32-bit signed integer value.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTSD2SI / CVTSD2SI </c> instruction.
Expand Down Expand Up @@ -1404,12 +1412,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtss_sd(__m128d __a,
}

/// Converts the two double-precision floating-point elements of a
/// 128-bit vector of [2 x double] into two signed 32-bit integer values,
/// returned in the lower 64 bits of a 128-bit vector of [4 x i32].
/// 128-bit vector of [2 x double] into two signed truncated (rounded
/// toward zero) 32-bit integer values, returned in the lower 64 bits
/// of a 128-bit vector of [4 x i32].
///
/// If the result of either conversion is inexact, the result is truncated
/// (rounded towards zero) regardless of the current MXCSR setting. The upper
/// 64 bits of the result vector are set to zero.
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -1425,7 +1434,11 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvttpd_epi32(__m128d __a) {
}

/// Converts the low-order element of a [2 x double] vector into a 32-bit
/// signed integer value, truncating the result when it is inexact.
/// signed truncated (rounded toward zero) integer value.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -1444,6 +1457,10 @@ static __inline__ int __DEFAULT_FN_ATTRS _mm_cvttsd_si32(__m128d __a) {
/// 128-bit vector of [2 x double] into two signed 32-bit integer values,
/// returned in a 64-bit vector of [2 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> CVTPD2PI </c> instruction.
Expand All @@ -1456,11 +1473,12 @@ static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX _mm_cvtpd_pi32(__m128d __a) {
}

/// Converts the two double-precision floating-point elements of a
/// 128-bit vector of [2 x double] into two signed 32-bit integer values,
/// returned in a 64-bit vector of [2 x i32].
/// 128-bit vector of [2 x double] into two signed truncated (rounded toward
/// zero) 32-bit integer values, returned in a 64-bit vector of [2 x i32].
///
/// If the result of either conversion is inexact, the result is truncated
/// (rounded towards zero) regardless of the current MXCSR setting.
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand Down Expand Up @@ -3207,7 +3225,11 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtsi64_sd(__m128d __a,
}

/// Converts the first (lower) element of a vector of [2 x double] into a
/// 64-bit signed integer value, according to the current rounding mode.
/// 64-bit signed integer value.
///
/// If the converted value does not fit in a 64-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -3222,7 +3244,11 @@ static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvtsd_si64(__m128d __a) {
}

/// Converts the first (lower) element of a vector of [2 x double] into a
/// 64-bit signed integer value, truncating the result when it is inexact.
/// 64-bit signed truncated (rounded toward zero) integer value.
///
/// If a converted value does not fit in a 64-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand Down Expand Up @@ -3253,6 +3279,10 @@ static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtepi32_ps(__m128i __a) {

/// Converts a vector of [4 x float] into a vector of [4 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTPS2DQ / CVTPS2DQ </c> instruction.
Expand All @@ -3265,8 +3295,12 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtps_epi32(__m128 __a) {
return (__m128i)__builtin_ia32_cvtps2dq((__v4sf)__a);
}

/// Converts a vector of [4 x float] into a vector of [4 x i32],
/// truncating the result when it is inexact.
/// Converts a vector of [4 x float] into four signed truncated (rounded toward
/// zero) 32-bit integers, returned in a vector of [4 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand Down
67 changes: 52 additions & 15 deletions clang/lib/Headers/xmmintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,10 @@ _mm_ucomineq_ss(__m128 __a, __m128 __b)
/// Converts a float value contained in the lower 32 bits of a vector of
/// [4 x float] into a 32-bit integer.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTSS2SI / CVTSS2SI </c>
Expand All @@ -1315,6 +1319,10 @@ _mm_cvtss_si32(__m128 __a)
/// Converts a float value contained in the lower 32 bits of a vector of
/// [4 x float] into a 32-bit integer.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTSS2SI / CVTSS2SI </c>
Expand All @@ -1335,6 +1343,10 @@ _mm_cvt_ss2si(__m128 __a)
/// Converts a float value contained in the lower 32 bits of a vector of
/// [4 x float] into a 64-bit integer.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> VCVTSS2SI / CVTSS2SI </c>
Expand All @@ -1355,6 +1367,10 @@ _mm_cvtss_si64(__m128 __a)
/// Converts two low-order float values in a 128-bit vector of
/// [4 x float] into a 64-bit vector of [2 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> CVTPS2PI </c> instruction.
Expand All @@ -1371,6 +1387,10 @@ _mm_cvtps_pi32(__m128 __a)
/// Converts two low-order float values in a 128-bit vector of
/// [4 x float] into a 64-bit vector of [2 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> CVTPS2PI </c> instruction.
Expand All @@ -1384,9 +1404,12 @@ _mm_cvt_ps2pi(__m128 __a)
return _mm_cvtps_pi32(__a);
}

/// Converts a float value contained in the lower 32 bits of a vector of
/// [4 x float] into a 32-bit integer, truncating the result when it is
/// inexact.
/// Converts the lower (first) element of a vector of [4 x float] into a signed
/// truncated (rounded toward zero) 32-bit integer.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -1403,9 +1426,12 @@ _mm_cvttss_si32(__m128 __a)
return __builtin_ia32_cvttss2si((__v4sf)__a);
}

/// Converts a float value contained in the lower 32 bits of a vector of
/// [4 x float] into a 32-bit integer, truncating the result when it is
/// inexact.
/// Converts the lower (first) element of a vector of [4 x float] into a signed
/// truncated (rounded toward zero) 32-bit integer.
///
/// If the converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -1423,9 +1449,12 @@ _mm_cvtt_ss2si(__m128 __a)
}

#ifdef __x86_64__
/// Converts a float value contained in the lower 32 bits of a vector of
/// [4 x float] into a 64-bit integer, truncating the result when it is
/// inexact.
/// Converts the lower (first) element of a vector of [4 x float] into a signed
/// truncated (rounded toward zero) 64-bit integer.
///
/// If the converted value does not fit in a 64-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -1443,9 +1472,13 @@ _mm_cvttss_si64(__m128 __a)
}
#endif

/// Converts two low-order float values in a 128-bit vector of
/// [4 x float] into a 64-bit vector of [2 x i32], truncating the result
/// when it is inexact.
/// Converts the lower (first) two elements of a 128-bit vector of [4 x float]
/// into two signed truncated (rounded toward zero) 32-bit integers,
/// returned in a 64-bit vector of [2 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand All @@ -1461,9 +1494,13 @@ _mm_cvttps_pi32(__m128 __a)
return (__m64)__builtin_ia32_cvttps2pi((__v4sf)__a);
}

/// Converts two low-order float values in a 128-bit vector of [4 x
/// float] into a 64-bit vector of [2 x i32], truncating the result when it
/// is inexact.
/// Converts the lower (first) two elements of a 128-bit vector of [4 x float]
/// into two signed truncated (rounded toward zero) 64-bit integers,
/// returned in a 64-bit vector of [2 x i32].
///
/// If a converted value does not fit in a 32-bit integer, raises a
/// floating-point invalid exception. If the exception is masked, returns
/// the most negative integer.
///
/// \headerfile <x86intrin.h>
///
Expand Down