@@ -502,6 +502,136 @@ ESIMD_NODEBUG ESIMD_INLINE T exp(T src0, Sat sat = {}) {
502
502
503
503
// / @} sycl_esimd_math
504
504
505
+ // / @addtogroup sycl_esimd_conv
506
+ // / @{
507
+
508
+ // //////////////////////////////////////////////////////////////////////////////
509
+ // Rounding intrinsics.
510
+ // //////////////////////////////////////////////////////////////////////////////
511
+
512
+ #define __ESIMD_INTRINSIC_DEF (name ) \
513
+ /* * @tparam T Element type. */ \
514
+ /* * @tparam SZ Number of elements in the input vector. */ \
515
+ /* * @tparam Sat Saturation control. Default is \c \
516
+ * __ESIMD_NS::saturation_off_tag */ \
517
+ /* * @param src0 The argument to perform rounding on. */ \
518
+ /* * @param sat The type tag object to auto-deduce saturation control. */ \
519
+ /* * can be \c saturation_off or \c saturation_on */ \
520
+ template <typename T, int SZ, class Sat = __ESIMD_NS::saturation_off_tag> \
521
+ __ESIMD_API __ESIMD_NS::simd<T, SZ> name (__ESIMD_NS::simd<float , SZ> src0, \
522
+ Sat sat = {}) { \
523
+ __ESIMD_NS::simd<float , SZ> Result = __esimd_##name<SZ>(src0.data ()); \
524
+ if constexpr (std::is_same_v<Sat, __ESIMD_NS::saturation_off_tag>) \
525
+ return Result; \
526
+ else if constexpr (!std::is_same_v<float , T>) { \
527
+ auto RawRes = __ESIMD_NS::saturate<float >(Result).data (); \
528
+ return __ESIMD_DNS::convert_vector<T, float , SZ>(std::move (RawRes)); \
529
+ } else { \
530
+ return __ESIMD_NS::saturate<T>(Result); \
531
+ } \
532
+ } \
533
+ /* * Scalar version. */ \
534
+ template <typename T, class Sat = __ESIMD_NS::saturation_off_tag> \
535
+ __ESIMD_API T name (float src0, Sat sat = {}) { \
536
+ __ESIMD_NS::simd<float , 1 > Src0 = src0; \
537
+ __ESIMD_NS::simd<T, 1 > Result = name<T>(Src0, sat); \
538
+ return Result[0 ]; \
539
+ }
540
+
541
+ // / Round-down (also known as \c floor). Supports only \c float.
542
+ // / Corner cases:
543
+ // / | _ | _ | _ | _ | _ | _ | _ | _
544
+ // / |----------|------|---------|----|----|---------|------|----
545
+ // / | **src0** | -inf | -denorm | -0 | +0 | +denorm | +inf | NaN
546
+ // / | **dst** | -inf | \* | -0 | +0 | +0 | +inf | NaN
547
+ // / - \* \c -1 or \c -0 depending on the Single Precision Denorm Mode.
548
+ __ESIMD_INTRINSIC_DEF (rndd)
549
+
550
+ // / Round-up (also known as \c ceil). Supports only \c float.
551
+ // / Corner cases:
552
+ // / | _ | _ | _ | _ | _ | _ | _ | _
553
+ // / |----------|------|---------|----|----|---------|------|----
554
+ // / | **src0** | -inf | -denorm | -0 | +0 | +denorm | +inf | NaN
555
+ // / | **dst** | -inf | -0 | -0 | +0 | \* | +inf | NaN
556
+ // / - \* \c +1 or \c +0 depending on the Single Precision Denorm Mode.
557
+ __ESIMD_INTRINSIC_DEF (rndu)
558
+
559
+ // / Round-to-even (also known as \c round). Supports only \c float.
560
+ // / Corner cases:
561
+ // / | _ | _ | _ | _ | _ | _ | _ | _
562
+ // / |----------|------|---------|----|----|---------|------|----
563
+ // / | **src0** | -inf | -denorm | -0 | +0 | +denorm | +inf | NaN
564
+ // / | **dst** | -inf | -0 | -0 | +0 | +0 | +inf | NaN
565
+ __ESIMD_INTRINSIC_DEF (rnde)
566
+
567
+ // / Round-to-zero (also known as \c trunc). Supports only \c float.
568
+ // / Corner cases:
569
+ // / | _ | _ | _ | _ | _ | _ | _ | _
570
+ // / |----------|------|---------|----|----|---------|------|----
571
+ // / | **src0** | -inf | -denorm | -0 | +0 | +denorm | +inf | NaN
572
+ // / | **dst** | -inf | -0 | -0 | +0 | +0 | +inf | NaN
573
+ __ESIMD_INTRINSIC_DEF (rndz)
574
+
575
+ #undef __ESIMD_INTRINSIC_DEF
576
+ // / @} sycl_esimd_conv
577
+
578
+ // / @addtogroup sycl_esimd_conv
579
+ // / @{
580
+
581
+ // / "Floor" operation, vector version - alias of \c rndd.
582
+ template <typename RT, int SZ, class Sat = __ESIMD_NS::saturation_off_tag>
583
+ ESIMD_INLINE __ESIMD_NS::simd<RT, SZ>
584
+ floor (const __ESIMD_NS::simd<float , SZ> src0, Sat sat = {}) {
585
+ return esimd::rndd<RT, SZ>(src0, sat);
586
+ }
587
+
588
+ // / "Floor" operation, scalar version - alias of \c rndd.
589
+ template <typename RT, class Sat = __ESIMD_NS::saturation_off_tag>
590
+ ESIMD_INLINE RT floor (float src0, Sat sat = {}) {
591
+ return esimd::rndd<RT, 1U >(src0, sat)[0 ];
592
+ }
593
+
594
+ // / "Ceiling" operation, vector version - alias of \c rndu.
595
+ template <typename RT, int SZ, class Sat = __ESIMD_NS::saturation_off_tag>
596
+ ESIMD_INLINE __ESIMD_NS::simd<RT, SZ>
597
+ ceil (const __ESIMD_NS::simd<float , SZ> src0, Sat sat = {}) {
598
+ return esimd::rndu<RT, SZ>(src0, sat);
599
+ }
600
+
601
+ // / "Ceiling" operation, scalar version - alias of \c rndu.
602
+ template <typename RT, class Sat = __ESIMD_NS::saturation_off_tag>
603
+ ESIMD_INLINE RT ceil (float src0, Sat sat = {}) {
604
+ return esimd::rndu<RT, 1U >(src0, sat);
605
+ }
606
+
607
+ // / Round to integral value using the round to zero rounding mode (vector
608
+ // / version). Alias of \c rndz.
609
+ // / @tparam RT element type of the return vector.
610
+ // / @tparam SZ size of the input and returned vectors.
611
+ // / @param src0 the input vector.
612
+ // / @param sat enables/disables the saturation (off by default). Possible
613
+ // / values: saturation_on/saturation_off.
614
+ // / @return vector of rounded values.
615
+ template <typename RT, int SZ, class Sat = __ESIMD_NS::saturation_off_tag>
616
+ __ESIMD_API __ESIMD_NS::simd<RT, SZ>
617
+ trunc (const __ESIMD_NS::simd<float , SZ> &src0, Sat sat = {}) {
618
+ return esimd::rndz<RT, SZ>(src0, sat);
619
+ }
620
+
621
+ // / Round to integral value using the round to zero rounding mode (scalar
622
+ // / version). Alias of \c rndz.
623
+ // / @tparam RT type of the return value.
624
+ // / @param src0 the input operand.
625
+ // / @param sat enables/disables the saturation (off by default). Possible
626
+ // / values: saturation_on/saturation_off.
627
+ // / @return rounded value.
628
+ template <typename RT, class Sat = __ESIMD_NS::saturation_off_tag>
629
+ __ESIMD_API RT trunc (float src0, Sat sat = {}) {
630
+ return esimd::rndz<RT, 1U >(src0, sat)[0 ];
631
+ }
632
+
633
+ // / @} sycl_esimd_conv
634
+
505
635
// / @addtogroup sycl_esimd_bitmanip
506
636
// / @{
507
637
0 commit comments