Skip to content

Commit 9187d82

Browse files
pogo59chencha3
authored andcommitted
[Headers][X86] Add rounding and exception notes to conversions (llvm#83447)
Consistently describe rounding/truncating on convert intrinsics. Add notes where an out-of-range result can raise an exception.
1 parent 0394f47 commit 9187d82

File tree

3 files changed

+123
-37
lines changed

3 files changed

+123
-37
lines changed

clang/lib/Headers/avxintrin.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,10 @@ _mm256_cvtpd_ps(__m256d __a)
22012201

22022202
/// Converts a vector of [8 x float] into a vector of [8 x i32].
22032203
///
2204+
/// If a converted value does not fit in a 32-bit integer, raises a
2205+
/// floating-point invalid exception. If the exception is masked, returns
2206+
/// the most negative integer.
2207+
///
22042208
/// \headerfile <x86intrin.h>
22052209
///
22062210
/// This intrinsic corresponds to the <c> VCVTPS2DQ </c> instruction.
@@ -2230,9 +2234,13 @@ _mm256_cvtps_pd(__m128 __a)
22302234
return (__m256d)__builtin_convertvector((__v4sf)__a, __v4df);
22312235
}
22322236

2233-
/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of [4
2234-
/// x i32], truncating the result by rounding towards zero when it is
2235-
/// inexact.
2237+
/// Converts a 256-bit vector of [4 x double] into four signed truncated
2238+
/// (rounded toward zero) 32-bit integers returned in a 128-bit vector of
2239+
/// [4 x i32].
2240+
///
2241+
/// If a converted value does not fit in a 32-bit integer, raises a
2242+
/// floating-point invalid exception. If the exception is masked, returns
2243+
/// the most negative integer.
22362244
///
22372245
/// \headerfile <x86intrin.h>
22382246
///
@@ -2247,9 +2255,12 @@ _mm256_cvttpd_epi32(__m256d __a)
22472255
return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
22482256
}
22492257

2250-
/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of [4
2251-
/// x i32]. When a conversion is inexact, the value returned is rounded
2252-
/// according to the rounding control bits in the MXCSR register.
2258+
/// Converts a 256-bit vector of [4 x double] into a 128-bit vector of
2259+
/// [4 x i32].
2260+
///
2261+
/// If a converted value does not fit in a 32-bit integer, raises a
2262+
/// floating-point invalid exception. If the exception is masked, returns
2263+
/// the most negative integer.
22532264
///
22542265
/// \headerfile <x86intrin.h>
22552266
///
@@ -2264,8 +2275,12 @@ _mm256_cvtpd_epi32(__m256d __a)
22642275
return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a);
22652276
}
22662277

2267-
/// Converts a vector of [8 x float] into a vector of [8 x i32],
2268-
/// truncating the result by rounding towards zero when it is inexact.
2278+
/// Converts a vector of [8 x float] into eight signed truncated (rounded
2279+
/// toward zero) 32-bit integers returned in a vector of [8 x i32].
2280+
///
2281+
/// If a converted value does not fit in a 32-bit integer, raises a
2282+
/// floating-point invalid exception. If the exception is masked, returns
2283+
/// the most negative integer.
22692284
///
22702285
/// \headerfile <x86intrin.h>
22712286
///

clang/lib/Headers/emmintrin.h

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,10 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtepi32_pd(__m128i __a) {
12941294
/// returned in the lower 64 bits of a 128-bit vector of [4 x i32]. The upper
12951295
/// 64 bits of the result vector are set to zero.
12961296
///
1297+
/// If a converted value does not fit in a 32-bit integer, raises a
1298+
/// floating-point invalid exception. If the exception is masked, returns
1299+
/// the most negative integer.
1300+
///
12971301
/// \headerfile <x86intrin.h>
12981302
///
12991303
/// This intrinsic corresponds to the <c> VCVTPD2DQ / CVTPD2DQ </c> instruction.
@@ -1309,6 +1313,10 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtpd_epi32(__m128d __a) {
13091313
/// Converts the low-order element of a 128-bit vector of [2 x double]
13101314
/// into a 32-bit signed integer value.
13111315
///
1316+
/// If the converted value does not fit in a 32-bit integer, raises a
1317+
/// floating-point invalid exception. If the exception is masked, returns
1318+
/// the most negative integer.
1319+
///
13121320
/// \headerfile <x86intrin.h>
13131321
///
13141322
/// This intrinsic corresponds to the <c> VCVTSD2SI / CVTSD2SI </c> instruction.
@@ -1394,12 +1402,13 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtss_sd(__m128d __a,
13941402
}
13951403

13961404
/// Converts the two double-precision floating-point elements of a
1397-
/// 128-bit vector of [2 x double] into two signed 32-bit integer values,
1398-
/// returned in the lower 64 bits of a 128-bit vector of [4 x i32].
1405+
/// 128-bit vector of [2 x double] into two signed truncated (rounded
1406+
/// toward zero) 32-bit integer values, returned in the lower 64 bits
1407+
/// of a 128-bit vector of [4 x i32].
13991408
///
1400-
/// If the result of either conversion is inexact, the result is truncated
1401-
/// (rounded towards zero) regardless of the current MXCSR setting. The upper
1402-
/// 64 bits of the result vector are set to zero.
1409+
/// If a converted value does not fit in a 32-bit integer, raises a
1410+
/// floating-point invalid exception. If the exception is masked, returns
1411+
/// the most negative integer.
14031412
///
14041413
/// \headerfile <x86intrin.h>
14051414
///
@@ -1415,7 +1424,11 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvttpd_epi32(__m128d __a) {
14151424
}
14161425

14171426
/// Converts the low-order element of a [2 x double] vector into a 32-bit
1418-
/// signed integer value, truncating the result when it is inexact.
1427+
/// signed truncated (rounded toward zero) integer value.
1428+
///
1429+
/// If the converted value does not fit in a 32-bit integer, raises a
1430+
/// floating-point invalid exception. If the exception is masked, returns
1431+
/// the most negative integer.
14191432
///
14201433
/// \headerfile <x86intrin.h>
14211434
///
@@ -1434,6 +1447,10 @@ static __inline__ int __DEFAULT_FN_ATTRS _mm_cvttsd_si32(__m128d __a) {
14341447
/// 128-bit vector of [2 x double] into two signed 32-bit integer values,
14351448
/// returned in a 64-bit vector of [2 x i32].
14361449
///
1450+
/// If a converted value does not fit in a 32-bit integer, raises a
1451+
/// floating-point invalid exception. If the exception is masked, returns
1452+
/// the most negative integer.
1453+
///
14371454
/// \headerfile <x86intrin.h>
14381455
///
14391456
/// This intrinsic corresponds to the <c> CVTPD2PI </c> instruction.
@@ -1446,11 +1463,12 @@ static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX _mm_cvtpd_pi32(__m128d __a) {
14461463
}
14471464

14481465
/// Converts the two double-precision floating-point elements of a
1449-
/// 128-bit vector of [2 x double] into two signed 32-bit integer values,
1450-
/// returned in a 64-bit vector of [2 x i32].
1466+
/// 128-bit vector of [2 x double] into two signed truncated (rounded toward
1467+
/// zero) 32-bit integer values, returned in a 64-bit vector of [2 x i32].
14511468
///
1452-
/// If the result of either conversion is inexact, the result is truncated
1453-
/// (rounded towards zero) regardless of the current MXCSR setting.
1469+
/// If a converted value does not fit in a 32-bit integer, raises a
1470+
/// floating-point invalid exception. If the exception is masked, returns
1471+
/// the most negative integer.
14541472
///
14551473
/// \headerfile <x86intrin.h>
14561474
///
@@ -3216,7 +3234,11 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtsi64_sd(__m128d __a,
32163234
}
32173235

32183236
/// Converts the first (lower) element of a vector of [2 x double] into a
3219-
/// 64-bit signed integer value, according to the current rounding mode.
3237+
/// 64-bit signed integer value.
3238+
///
3239+
/// If the converted value does not fit in a 64-bit integer, raises a
3240+
/// floating-point invalid exception. If the exception is masked, returns
3241+
/// the most negative integer.
32203242
///
32213243
/// \headerfile <x86intrin.h>
32223244
///
@@ -3231,7 +3253,11 @@ static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvtsd_si64(__m128d __a) {
32313253
}
32323254

32333255
/// Converts the first (lower) element of a vector of [2 x double] into a
3234-
/// 64-bit signed integer value, truncating the result when it is inexact.
3256+
/// 64-bit signed truncated (rounded toward zero) integer value.
3257+
///
3258+
/// If a converted value does not fit in a 64-bit integer, raises a
3259+
/// floating-point invalid exception. If the exception is masked, returns
3260+
/// the most negative integer.
32353261
///
32363262
/// \headerfile <x86intrin.h>
32373263
///
@@ -3262,6 +3288,10 @@ static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtepi32_ps(__m128i __a) {
32623288

32633289
/// Converts a vector of [4 x float] into a vector of [4 x i32].
32643290
///
3291+
/// If a converted value does not fit in a 32-bit integer, raises a
3292+
/// floating-point invalid exception. If the exception is masked, returns
3293+
/// the most negative integer.
3294+
///
32653295
/// \headerfile <x86intrin.h>
32663296
///
32673297
/// This intrinsic corresponds to the <c> VCVTPS2DQ / CVTPS2DQ </c> instruction.
@@ -3274,8 +3304,12 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtps_epi32(__m128 __a) {
32743304
return (__m128i)__builtin_ia32_cvtps2dq((__v4sf)__a);
32753305
}
32763306

3277-
/// Converts a vector of [4 x float] into a vector of [4 x i32],
3278-
/// truncating the result when it is inexact.
3307+
/// Converts a vector of [4 x float] into four signed truncated (rounded toward
3308+
/// zero) 32-bit integers, returned in a vector of [4 x i32].
3309+
///
3310+
/// If a converted value does not fit in a 32-bit integer, raises a
3311+
/// floating-point invalid exception. If the exception is masked, returns
3312+
/// the most negative integer.
32793313
///
32803314
/// \headerfile <x86intrin.h>
32813315
///

clang/lib/Headers/xmmintrin.h

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,10 @@ _mm_ucomineq_ss(__m128 __a, __m128 __b)
13331333
/// Converts a float value contained in the lower 32 bits of a vector of
13341334
/// [4 x float] into a 32-bit integer.
13351335
///
1336+
/// If the converted value does not fit in a 32-bit integer, raises a
1337+
/// floating-point invalid exception. If the exception is masked, returns
1338+
/// the most negative integer.
1339+
///
13361340
/// \headerfile <x86intrin.h>
13371341
///
13381342
/// This intrinsic corresponds to the <c> VCVTSS2SI / CVTSS2SI </c>
@@ -1351,6 +1355,10 @@ _mm_cvtss_si32(__m128 __a)
13511355
/// Converts a float value contained in the lower 32 bits of a vector of
13521356
/// [4 x float] into a 32-bit integer.
13531357
///
1358+
/// If the converted value does not fit in a 32-bit integer, raises a
1359+
/// floating-point invalid exception. If the exception is masked, returns
1360+
/// the most negative integer.
1361+
///
13541362
/// \headerfile <x86intrin.h>
13551363
///
13561364
/// This intrinsic corresponds to the <c> VCVTSS2SI / CVTSS2SI </c>
@@ -1371,6 +1379,10 @@ _mm_cvt_ss2si(__m128 __a)
13711379
/// Converts a float value contained in the lower 32 bits of a vector of
13721380
/// [4 x float] into a 64-bit integer.
13731381
///
1382+
/// If the converted value does not fit in a 32-bit integer, raises a
1383+
/// floating-point invalid exception. If the exception is masked, returns
1384+
/// the most negative integer.
1385+
///
13741386
/// \headerfile <x86intrin.h>
13751387
///
13761388
/// This intrinsic corresponds to the <c> VCVTSS2SI / CVTSS2SI </c>
@@ -1391,6 +1403,10 @@ _mm_cvtss_si64(__m128 __a)
13911403
/// Converts two low-order float values in a 128-bit vector of
13921404
/// [4 x float] into a 64-bit vector of [2 x i32].
13931405
///
1406+
/// If a converted value does not fit in a 32-bit integer, raises a
1407+
/// floating-point invalid exception. If the exception is masked, returns
1408+
/// the most negative integer.
1409+
///
13941410
/// \headerfile <x86intrin.h>
13951411
///
13961412
/// This intrinsic corresponds to the <c> CVTPS2PI </c> instruction.
@@ -1407,6 +1423,10 @@ _mm_cvtps_pi32(__m128 __a)
14071423
/// Converts two low-order float values in a 128-bit vector of
14081424
/// [4 x float] into a 64-bit vector of [2 x i32].
14091425
///
1426+
/// If a converted value does not fit in a 32-bit integer, raises a
1427+
/// floating-point invalid exception. If the exception is masked, returns
1428+
/// the most negative integer.
1429+
///
14101430
/// \headerfile <x86intrin.h>
14111431
///
14121432
/// This intrinsic corresponds to the <c> CVTPS2PI </c> instruction.
@@ -1420,9 +1440,12 @@ _mm_cvt_ps2pi(__m128 __a)
14201440
return _mm_cvtps_pi32(__a);
14211441
}
14221442

1423-
/// Converts a float value contained in the lower 32 bits of a vector of
1424-
/// [4 x float] into a 32-bit integer, truncating the result when it is
1425-
/// inexact.
1443+
/// Converts the lower (first) element of a vector of [4 x float] into a signed
1444+
/// truncated (rounded toward zero) 32-bit integer.
1445+
///
1446+
/// If the converted value does not fit in a 32-bit integer, raises a
1447+
/// floating-point invalid exception. If the exception is masked, returns
1448+
/// the most negative integer.
14261449
///
14271450
/// \headerfile <x86intrin.h>
14281451
///
@@ -1439,9 +1462,12 @@ _mm_cvttss_si32(__m128 __a)
14391462
return __builtin_ia32_cvttss2si((__v4sf)__a);
14401463
}
14411464

1442-
/// Converts a float value contained in the lower 32 bits of a vector of
1443-
/// [4 x float] into a 32-bit integer, truncating the result when it is
1444-
/// inexact.
1465+
/// Converts the lower (first) element of a vector of [4 x float] into a signed
1466+
/// truncated (rounded toward zero) 32-bit integer.
1467+
///
1468+
/// If the converted value does not fit in a 32-bit integer, raises a
1469+
/// floating-point invalid exception. If the exception is masked, returns
1470+
/// the most negative integer.
14451471
///
14461472
/// \headerfile <x86intrin.h>
14471473
///
@@ -1459,9 +1485,12 @@ _mm_cvtt_ss2si(__m128 __a)
14591485
}
14601486

14611487
#ifdef __x86_64__
1462-
/// Converts a float value contained in the lower 32 bits of a vector of
1463-
/// [4 x float] into a 64-bit integer, truncating the result when it is
1464-
/// inexact.
1488+
/// Converts the lower (first) element of a vector of [4 x float] into a signed
1489+
/// truncated (rounded toward zero) 64-bit integer.
1490+
///
1491+
/// If the converted value does not fit in a 64-bit integer, raises a
1492+
/// floating-point invalid exception. If the exception is masked, returns
1493+
/// the most negative integer.
14651494
///
14661495
/// \headerfile <x86intrin.h>
14671496
///
@@ -1479,9 +1508,13 @@ _mm_cvttss_si64(__m128 __a)
14791508
}
14801509
#endif
14811510

1482-
/// Converts two low-order float values in a 128-bit vector of
1483-
/// [4 x float] into a 64-bit vector of [2 x i32], truncating the result
1484-
/// when it is inexact.
1511+
/// Converts the lower (first) two elements of a 128-bit vector of [4 x float]
1512+
/// into two signed truncated (rounded toward zero) 32-bit integers,
1513+
/// returned in a 64-bit vector of [2 x i32].
1514+
///
1515+
/// If a converted value does not fit in a 32-bit integer, raises a
1516+
/// floating-point invalid exception. If the exception is masked, returns
1517+
/// the most negative integer.
14851518
///
14861519
/// \headerfile <x86intrin.h>
14871520
///
@@ -1497,9 +1530,13 @@ _mm_cvttps_pi32(__m128 __a)
14971530
return (__m64)__builtin_ia32_cvttps2pi((__v4sf)__a);
14981531
}
14991532

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

0 commit comments

Comments
 (0)