3#include <AMReX_Config.H>
19# include <sycl/sycl.hpp>
24inline namespace disabled {
68template <std::
floating_po
int T>
71 return std::numbers::pi_v<T>;
78#if defined(AMREX_USE_SYCL)
79 return sycl::cospi(
x);
90#if defined(AMREX_USE_SYCL)
91 return sycl::cospi(
x);
102#if defined(AMREX_USE_SYCL)
103 return sycl::sinpi(
x);
114#if defined(AMREX_USE_SYCL)
115 return sycl::sinpi(
x);
125#if defined(_GNU_SOURCE) && !defined(__APPLE__)
126 ::sincos(x, sinx, cosx);
134#if defined(_GNU_SOURCE) && !defined(__APPLE__)
135 ::sincosf(x, sinx, cosx);
146template<
typename T_Real>
147requires (amrex::simd::stdx::is_simd_v<T_Real>)
149std::pair<T_Real,T_Real>
sincos (T_Real
x)
152 std::pair<T_Real,T_Real> r;
163 std::pair<double,double> r;
164#if defined(AMREX_USE_SYCL)
165 r.first = sycl::sincos(
x, sycl::private_ptr<double>(&r.second));
177 std::pair<float,float> r;
178#if defined(AMREX_USE_SYCL)
179 r.first = sycl::sincos(
x, sycl::private_ptr<float>(&r.second));
189template<
typename T_Real>
190requires (amrex::simd::stdx::is_simd_v<T_Real>)
192std::pair<T_Real,T_Real>
sincospi (T_Real
x)
195 T_Real
const px = pi<typename T_Real::value_type>() *
x;
196 std::pair<T_Real,T_Real> r;
207 std::pair<double,double> r;
208#if defined(AMREX_USE_SYCL)
221 std::pair<float,float> r;
222#if defined(AMREX_USE_SYCL)
232template <
int Power,
typename T>
233requires (!std::integral<T> || Power >= 0)
237 if constexpr (Power < 0) {
238 return T(1)/
powi<-Power>(
x);
239 }
else if constexpr (Power == 0) {
242 }
else if constexpr (Power == 1) {
244 }
else if constexpr (Power == 2) {
246 }
else if constexpr (Power%2 == 0) {
247 return powi<2>(powi<Power/2>(
x));
249 return x*
powi<Power-1>(
x);
255#if defined(AMREX_USE_CUDA)
278#if defined(AMREX_USE_SYCL)
279 return sycl::pown(
x, n);
280#elif defined(AMREX_USE_HIP)
283#elif defined(AMREX_USE_CUDA)
287 return std::pow(
x,
static_cast<float>(n));
292double powi (
double x,
int n)
noexcept
294#if defined(AMREX_USE_SYCL)
295 return sycl::pown(
x, n);
296#elif defined(AMREX_USE_HIP)
299#elif defined(AMREX_USE_CUDA)
303 return std::pow(
x, n);
307#if defined(AMREX_INT128_SUPPORTED)
309std::uint64_t umulhi (std::uint64_t a, std::uint64_t b)
311#if defined(AMREX_USE_SYCL)
312 return sycl::mul_hi(a,b);
316 auto tmp = amrex::UInt128_t(a) * amrex::UInt128_t(b);
317 return std::uint64_t(tmp >> 64);
329 T tol = std::numeric_limits<T>::epsilon();
332 T g0 = std::sqrt(1.0 - k*k);
337 while(std::abs(a0 - g0) > tol) {
339 g = std::sqrt(a0 * g0);
345 return 0.5*pi<T>()/a;
354 T Kcomp = amrex::Math::comp_ellint_1<T>(k);
355 T tol = std::numeric_limits<T>::epsilon();
359 T g0 = std::sqrt(1.0 - k*k);
360 T cn = std::sqrt(a0*a0 - g0*g0);
364 T a = 0.5 * (a0 + g0);
365 T g = std::sqrt(a0*g0);
372 while(std::abs(cn*cn) > tol) {
375 g = std::sqrt(a0*g0);
379 sum_val -= std::pow(2,n-1)*cn*cn;
386 return Kcomp*sum_val;
394#if defined(AMREX_USE_SYCL)
408#if defined(AMREX_USE_SYCL)
422#if defined(AMREX_USE_SYCL)
436#if defined(AMREX_USE_SYCL)
496#ifdef AMREX_INT128_SUPPORTED
497 std::uint64_t multiplier = 1U;
498 unsigned int shift_right = 0;
499 unsigned int round_up = 0;
506 static std::uint32_t integer_log2 (std::uint64_t
x)
522 shift_right = integer_log2(
divisor);
528 std::uint64_t power_of_two = (std::uint64_t(1) << shift_right);
529 auto n = amrex::UInt128_t(power_of_two) << 64;
530 std::uint64_t multiplier_lo = n /
divisor;
533 round_up = (multiplier_lo == multiplier ? 1 : 0);
549 std::uint64_t
divide (std::uint64_t dividend)
const
551#if defined(AMREX_INT128_SUPPORTED)
554 x = amrex::Math::umulhi(dividend + round_up, multiplier);
556 return (
x >> shift_right);
564 std::uint64_t
modulus (std::uint64_t quotient, std::uint64_t dividend)
const
566 return dividend - quotient *
divisor;
571 std::uint64_t
divmod (std::uint64_t &remainder, std::uint64_t dividend)
const
573 auto quotient =
divide(dividend);
574 remainder =
modulus(quotient, dividend);
581 void operator() (std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend)
const
583 quotient =
divmod(remainder, dividend);
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_IF_ON_DEVICE(CODE)
Definition AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
__device__ double __nv_powi(double, int)
__device__ float __nv_powif(float, int)
Definition AMReX_Math.H:40
constexpr T pi()
Definition AMReX_Math.H:69
constexpr T powi(T x) noexcept
Return pow(x, Power), where Power is an integer known at compile time.
Definition AMReX_Math.H:235
__host__ __device__ double sinpi(double x)
Return sin(x*pi) given x.
Definition AMReX_Math.H:100
__host__ __device__ std::pair< double, double > sincospi(double x)
Return sin(pi*x) and cos(pi*x) given x.
Definition AMReX_Math.H:205
__host__ __device__ double cospi(double x)
Return cos(x*pi) given x.
Definition AMReX_Math.H:76
__host__ __device__ double exp10(double x)
Return 10**x.
Definition AMReX_Math.H:419
__host__ __device__ T comp_ellint_1(T k)
Definition AMReX_Math.H:325
__host__ __device__ std::pair< double, double > sincos(double x)
Return sine and cosine of given number.
Definition AMReX_Math.H:161
__host__ __device__ T comp_ellint_2(T k)
Definition AMReX_Math.H:350
__host__ __device__ double rsqrt(double x)
Return inverse square root of x.
Definition AMReX_Math.H:391
Definition AMReX_SIMD.H:25
Definition AMReX_Amr.cpp:50
__host__ __device__ T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition AMReX_GpuComplex.H:361
Definition AMReX_Math.H:493
__host__ __device__ std::uint64_t divide(std::uint64_t dividend) const
Returns the quotient of floor(dividend / divisor)
Definition AMReX_Math.H:549
__host__ __device__ std::uint64_t divmod(std::uint64_t &remainder, std::uint64_t dividend) const
Returns the quotient of floor(dividend / divisor) and computes the remainder.
Definition AMReX_Math.H:571
__host__ __device__ void operator()(std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend) const
Definition AMReX_Math.H:581
__host__ __device__ std::uint64_t modulus(std::uint64_t quotient, std::uint64_t dividend) const
Computes the remainder given a computed quotient and dividend.
Definition AMReX_Math.H:564
std::uint64_t divisor
Definition AMReX_Math.H:494
FastDivmodU64(std::uint64_t divisor_)
Definition AMReX_Math.H:540
FastDivmodU64()=default
Default construct an invalid FastDivmodU64.