[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-19 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 closed https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-19 Thread via cfe-commits

https://github.com/craigflores approved this pull request.


https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-14 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang approved this pull request.

Looks great, thanks!

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-13 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 updated 
https://github.com/llvm/llvm-project/pull/83447

>From 64cdd358d0bf359383a5dd3d1da236a219644c9e Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Thu, 29 Feb 2024 08:59:26 -0800
Subject: [PATCH 1/4] [Headers][X86] Add rounding and exception notes to
 conversions

Consistently describe rounding/truncating on convert intrinsics.
Add notes where an out-of-range result can raise an exception.
---
 clang/lib/Headers/avxintrin.h |  36 +++---
 clang/lib/Headers/emmintrin.h |  91 ++---
 clang/lib/Headers/xmmintrin.h | 125 --
 3 files changed, 182 insertions(+), 70 deletions(-)

diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index f116d8bc3a94c7..51c7d76e75ca1a 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2196,7 +2197,8 @@ _mm256_cvtepi32_ps(__m256i __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
-///[4 x float].
+///[4 x float]. Rounds inexact results according to the rounding control
+///bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2243,8 +2250,11 @@ _mm256_cvtps_pd(__m128 __a)
 }
 
 /// 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.
+///x i32], truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2259,9 +2269,13 @@ _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]. Rounds inexact results according to the rounding control bits
+///in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2277,7 +2291,11 @@ _mm256_cvtpd_epi32(__m256d __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.
+///truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 96e3ebdecbdf83..9ae7fe2c809ac6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1245,7 +1245,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomineq_sd(__m128d __a,
 /// Converts the two double-precision floating-point elements of a
 ///128-bit vector of [2 x double] into two single-precision floating-point
 ///values, returned in the lower 64 bits of a 128-bit vector of [4 x 
float].
-///The upper 64 bits of the result vector are set to zero.
+///Rounds inexact results according to the rounding control bits in the
+///MXCSR register. The upper 64 bits of the result vector are set to zero.
 ///
 /// \headerfile 
 ///
@@ -1300,9 +1301,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cvtepi32_pd(__m128i __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]. The 
upper
-///64 bits of the result vector are set to zero.
+///128-bit vector of [2 

[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-13 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

Reworded the parts about truncating results.

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-13 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 updated 
https://github.com/llvm/llvm-project/pull/83447

>From 64cdd358d0bf359383a5dd3d1da236a219644c9e Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Thu, 29 Feb 2024 08:59:26 -0800
Subject: [PATCH 1/3] [Headers][X86] Add rounding and exception notes to
 conversions

Consistently describe rounding/truncating on convert intrinsics.
Add notes where an out-of-range result can raise an exception.
---
 clang/lib/Headers/avxintrin.h |  36 +++---
 clang/lib/Headers/emmintrin.h |  91 ++---
 clang/lib/Headers/xmmintrin.h | 125 --
 3 files changed, 182 insertions(+), 70 deletions(-)

diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index f116d8bc3a94c7..51c7d76e75ca1a 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2196,7 +2197,8 @@ _mm256_cvtepi32_ps(__m256i __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
-///[4 x float].
+///[4 x float]. Rounds inexact results according to the rounding control
+///bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2243,8 +2250,11 @@ _mm256_cvtps_pd(__m128 __a)
 }
 
 /// 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.
+///x i32], truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2259,9 +2269,13 @@ _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]. Rounds inexact results according to the rounding control bits
+///in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2277,7 +2291,11 @@ _mm256_cvtpd_epi32(__m256d __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.
+///truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 96e3ebdecbdf83..9ae7fe2c809ac6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1245,7 +1245,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomineq_sd(__m128d __a,
 /// Converts the two double-precision floating-point elements of a
 ///128-bit vector of [2 x double] into two single-precision floating-point
 ///values, returned in the lower 64 bits of a 128-bit vector of [4 x 
float].
-///The upper 64 bits of the result vector are set to zero.
+///Rounds inexact results according to the rounding control bits in the
+///MXCSR register. The upper 64 bits of the result vector are set to zero.
 ///
 /// \headerfile 
 ///
@@ -1300,9 +1301,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cvtepi32_pd(__m128i __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]. The 
upper
-///64 bits of the result vector are set to zero.
+///128-bit vector of [2 

[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-12 Thread via cfe-commits

craigflores wrote:

Test from "craig.flo...@sony.com".

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-08 Thread Phoebe Wang via cfe-commits


@@ -1405,11 +1413,12 @@ 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].
+///returned in the lower 64 bits of a 128-bit vector of [4 x i32],
+///truncating inexact results.

phoebewang wrote:

Oh, I took that simply as wrong infromation.

> Do you have a different suggestion for how to organize this information?

Not ideal, something like

```
/// Converts the two double-precision floating-point elements of a
///128-bit vector of [2 x double] into two signed truncated
///(rounded towards zero) 32-bit integer values,returned in the
///most negative integer.
```

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-08 Thread Paul T Robinson via cfe-commits


@@ -1405,11 +1413,12 @@ 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].
+///returned in the lower 64 bits of a 128-bit vector of [4 x i32],
+///truncating inexact results.

pogo59 wrote:

Truncation is what distinguishes this from `_mm_cvtpd_epi32` so I think it is 
necessary? That information used to be in the second paragraph, I shortened it 
and moved it up to the first paragraph, to make that difference more obvious.
Behavior on overflow was added to the second paragraph.

Do you have a different suggestion for how to organize this information?

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-08 Thread Phoebe Wang via cfe-commits


@@ -1405,11 +1413,12 @@ 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].
+///returned in the lower 64 bits of a 128-bit vector of [4 x i32],
+///truncating inexact results.

phoebewang wrote:

The last sentence is not necessary and has ambiguity in truncating the 
fractional part or truncating higher bits to 32-bit.

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-07 Thread Paul T Robinson via cfe-commits


@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.

pogo59 wrote:

Discussed this internally and agreed that it is not necessary.

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-07 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 updated 
https://github.com/llvm/llvm-project/pull/83447

>From 64cdd358d0bf359383a5dd3d1da236a219644c9e Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Thu, 29 Feb 2024 08:59:26 -0800
Subject: [PATCH 1/2] [Headers][X86] Add rounding and exception notes to
 conversions

Consistently describe rounding/truncating on convert intrinsics.
Add notes where an out-of-range result can raise an exception.
---
 clang/lib/Headers/avxintrin.h |  36 +++---
 clang/lib/Headers/emmintrin.h |  91 ++---
 clang/lib/Headers/xmmintrin.h | 125 --
 3 files changed, 182 insertions(+), 70 deletions(-)

diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index f116d8bc3a94c7..51c7d76e75ca1a 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2196,7 +2197,8 @@ _mm256_cvtepi32_ps(__m256i __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
-///[4 x float].
+///[4 x float]. Rounds inexact results according to the rounding control
+///bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2243,8 +2250,11 @@ _mm256_cvtps_pd(__m128 __a)
 }
 
 /// 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.
+///x i32], truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2259,9 +2269,13 @@ _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]. Rounds inexact results according to the rounding control bits
+///in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2277,7 +2291,11 @@ _mm256_cvtpd_epi32(__m256d __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.
+///truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 96e3ebdecbdf83..9ae7fe2c809ac6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1245,7 +1245,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomineq_sd(__m128d __a,
 /// Converts the two double-precision floating-point elements of a
 ///128-bit vector of [2 x double] into two single-precision floating-point
 ///values, returned in the lower 64 bits of a 128-bit vector of [4 x 
float].
-///The upper 64 bits of the result vector are set to zero.
+///Rounds inexact results according to the rounding control bits in the
+///MXCSR register. The upper 64 bits of the result vector are set to zero.
 ///
 /// \headerfile 
 ///
@@ -1300,9 +1301,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cvtepi32_pd(__m128i __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]. The 
upper
-///64 bits of the result vector are set to zero.
+///128-bit vector of [2 

[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-01 Thread Phoebe Wang via cfe-commits


@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,

phoebewang wrote:

Not only larger than, considering the negative number.

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-01 Thread Phoebe Wang via cfe-commits


@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.

phoebewang wrote:

I think we don't need to mention it. This is the default behavior if not 
mentioned otherwise.

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-02-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul T Robinson (pogo59)


Changes

Consistently describe rounding/truncating on convert intrinsics. Add notes 
where an out-of-range result can raise an exception.

---

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


3 Files Affected:

- (modified) clang/lib/Headers/avxintrin.h (+27-9) 
- (modified) clang/lib/Headers/emmintrin.h (+66-25) 
- (modified) clang/lib/Headers/xmmintrin.h (+89-36) 


``diff
diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index f116d8bc3a94c7..51c7d76e75ca1a 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2196,7 +2197,8 @@ _mm256_cvtepi32_ps(__m256i __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
-///[4 x float].
+///[4 x float]. Rounds inexact results according to the rounding control
+///bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2243,8 +2250,11 @@ _mm256_cvtps_pd(__m128 __a)
 }
 
 /// 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.
+///x i32], truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2259,9 +2269,13 @@ _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]. Rounds inexact results according to the rounding control bits
+///in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2277,7 +2291,11 @@ _mm256_cvtpd_epi32(__m256d __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.
+///truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 96e3ebdecbdf83..9ae7fe2c809ac6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1245,7 +1245,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomineq_sd(__m128d __a,
 /// Converts the two double-precision floating-point elements of a
 ///128-bit vector of [2 x double] into two single-precision floating-point
 ///values, returned in the lower 64 bits of a 128-bit vector of [4 x 
float].
-///The upper 64 bits of the result vector are set to zero.
+///Rounds inexact results according to the rounding control bits in the
+///MXCSR register. The upper 64 bits of the result vector are set to zero.
 ///
 /// \headerfile 
 ///
@@ -1300,9 +1301,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cvtepi32_pd(__m128i __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]. The 
upper
-///64 bits of the result vector are set to zero.
+///128-bit vector of [2 x double] into two signed 32-bit integer values.
+///Rounds inexact results according to the rounding control bits in the

[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-02-29 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

FYI @cflores 

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-02-29 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 created 
https://github.com/llvm/llvm-project/pull/83447

Consistently describe rounding/truncating on convert intrinsics. Add notes 
where an out-of-range result can raise an exception.

>From 64cdd358d0bf359383a5dd3d1da236a219644c9e Mon Sep 17 00:00:00 2001
From: Paul Robinson 
Date: Thu, 29 Feb 2024 08:59:26 -0800
Subject: [PATCH] [Headers][X86] Add rounding and exception notes to
 conversions

Consistently describe rounding/truncating on convert intrinsics.
Add notes where an out-of-range result can raise an exception.
---
 clang/lib/Headers/avxintrin.h |  36 +++---
 clang/lib/Headers/emmintrin.h |  91 ++---
 clang/lib/Headers/xmmintrin.h | 125 --
 3 files changed, 182 insertions(+), 70 deletions(-)

diff --git a/clang/lib/Headers/avxintrin.h b/clang/lib/Headers/avxintrin.h
index f116d8bc3a94c7..51c7d76e75ca1a 100644
--- a/clang/lib/Headers/avxintrin.h
+++ b/clang/lib/Headers/avxintrin.h
@@ -2180,7 +2180,8 @@ _mm256_cvtepi32_pd(__m128i __a)
   return (__m256d)__builtin_convertvector((__v4si)__a, __v4df);
 }
 
-/// Converts a vector of [8 x i32] into a vector of [8 x float].
+/// Converts a vector of [8 x i32] into a vector of [8 x float]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2196,7 +2197,8 @@ _mm256_cvtepi32_ps(__m256i __a)
 }
 
 /// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
-///[4 x float].
+///[4 x float]. Rounds inexact results according to the rounding control
+///bits in the MXCSR register.
 ///
 /// \headerfile 
 ///
@@ -2211,7 +2213,12 @@ _mm256_cvtpd_ps(__m256d __a)
   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
 }
 
-/// Converts a vector of [8 x float] into a vector of [8 x i32].
+/// Converts a vector of [8 x float] into a vector of [8 x i32]. Rounds inexact
+///results according to the rounding control bits in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2243,8 +2250,11 @@ _mm256_cvtps_pd(__m128 __a)
 }
 
 /// 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.
+///x i32], truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2259,9 +2269,13 @@ _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]. Rounds inexact results according to the rounding control bits
+///in the MXCSR register.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
@@ -2277,7 +2291,11 @@ _mm256_cvtpd_epi32(__m256d __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.
+///truncating inexact results.
+///
+///If a converted value is larger than the maximum possible result,
+///raises a floating-point invalid exception. If the exception is
+///masked, returns the most negative integer.
 ///
 /// \headerfile 
 ///
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 96e3ebdecbdf83..9ae7fe2c809ac6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1245,7 +1245,8 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_ucomineq_sd(__m128d __a,
 /// Converts the two double-precision floating-point elements of a
 ///128-bit vector of [2 x double] into two single-precision floating-point
 ///values, returned in the lower 64 bits of a 128-bit vector of [4 x 
float].
-///The upper 64 bits of the result vector are set to zero.
+///Rounds inexact results according to the rounding control bits in the
+///MXCSR register. The upper 64 bits of the result vector are set to zero.
 ///
 /// \headerfile 
 ///
@@ -1300,9 +1301,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cvtepi32_pd(__m128i __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