3#include <AMReX_Config.H>
17# include <sycl/sycl.hpp>
22inline namespace disabled {
68constexpr std::enable_if_t<std::is_floating_point_v<T>,T>
pi ()
70 return T(3.1415926535897932384626433832795029L);
77#if defined(AMREX_USE_SYCL)
78 return sycl::cospi(
x);
89#if defined(AMREX_USE_SYCL)
90 return sycl::cospi(
x);
101#if defined(AMREX_USE_SYCL)
102 return sycl::sinpi(
x);
113#if defined(AMREX_USE_SYCL)
114 return sycl::sinpi(
x);
124#if defined(_GNU_SOURCE) && !defined(__APPLE__)
125 ::sincos(x, sinx, cosx);
133#if defined(_GNU_SOURCE) && !defined(__APPLE__)
134 ::sincosf(x, sinx, cosx);
145template<
typename T_Real,
146 std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,
int> = 0>
148std::pair<T_Real,T_Real>
sincos (T_Real
x)
151 std::pair<T_Real,T_Real> r;
162 std::pair<double,double> r;
163#if defined(AMREX_USE_SYCL)
164 r.first = sycl::sincos(
x, sycl::private_ptr<double>(&r.second));
176 std::pair<float,float> r;
177#if defined(AMREX_USE_SYCL)
178 r.first = sycl::sincos(
x, sycl::private_ptr<float>(&r.second));
188template<
typename T_Real,
189 std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,
int> = 0>
191std::pair<T_Real,T_Real>
sincospi (T_Real
x)
194 T_Real
const px = pi<typename T_Real::value_type>() *
x;
195 std::pair<T_Real,T_Real> r;
206 std::pair<double,double> r;
207#if defined(AMREX_USE_SYCL)
220 std::pair<float,float> r;
221#if defined(AMREX_USE_SYCL)
231template <
int Power,
typename T,
232 typename = std::enable_if_t<!std::is_integral<T>() || Power>=0>>
236 if constexpr (Power < 0) {
237 return T(1)/
powi<-Power>(
x);
238 }
else if constexpr (Power == 0) {
241 }
else if constexpr (Power == 1) {
243 }
else if constexpr (Power == 2) {
245 }
else if constexpr (Power%2 == 0) {
246 return powi<2>(powi<Power/2>(
x));
248 return x*
powi<Power-1>(
x);
252#if defined(AMREX_INT128_SUPPORTED)
254std::uint64_t umulhi (std::uint64_t a, std::uint64_t b)
256#if defined(AMREX_USE_SYCL)
257 return sycl::mul_hi(a,b);
261 auto tmp = amrex::UInt128_t(a) * amrex::UInt128_t(b);
262 return std::uint64_t(tmp >> 64);
274 T tol = std::numeric_limits<T>::epsilon();
277 T g0 = std::sqrt(1.0 - k*k);
282 while(std::abs(a0 - g0) > tol) {
284 g = std::sqrt(a0 * g0);
290 return 0.5*pi<T>()/a;
299 T Kcomp = amrex::Math::comp_ellint_1<T>(k);
300 T tol = std::numeric_limits<T>::epsilon();
304 T g0 = std::sqrt(1.0 - k*k);
305 T cn = std::sqrt(a0*a0 - g0*g0);
309 T a = 0.5 * (a0 + g0);
310 T g = std::sqrt(a0*g0);
317 while(std::abs(cn*cn) > tol) {
320 g = std::sqrt(a0*g0);
324 sum_val -= std::pow(2,n-1)*cn*cn;
331 return Kcomp*sum_val;
339#if defined(AMREX_USE_SYCL)
353#if defined(AMREX_USE_SYCL)
367#if defined(AMREX_USE_SYCL)
381#if defined(AMREX_USE_SYCL)
441#ifdef AMREX_INT128_SUPPORTED
442 std::uint64_t multiplier = 1U;
443 unsigned int shift_right = 0;
444 unsigned int round_up = 0;
451 static std::uint32_t integer_log2 (std::uint64_t
x)
467 shift_right = integer_log2(
divisor);
473 std::uint64_t power_of_two = (std::uint64_t(1) << shift_right);
474 auto n = amrex::UInt128_t(power_of_two) << 64;
475 std::uint64_t multiplier_lo = n /
divisor;
478 round_up = (multiplier_lo == multiplier ? 1 : 0);
494 std::uint64_t
divide (std::uint64_t dividend)
const
496#if defined(AMREX_INT128_SUPPORTED)
499 x = amrex::Math::umulhi(dividend + round_up, multiplier);
501 return (
x >> shift_right);
509 std::uint64_t
modulus (std::uint64_t quotient, std::uint64_t dividend)
const
511 return dividend - quotient *
divisor;
516 std::uint64_t
divmod (std::uint64_t &remainder, std::uint64_t dividend)
const
518 auto quotient =
divide(dividend);
519 remainder =
modulus(quotient, dividend);
526 void operator() (std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend)
const
528 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
Definition AMReX_Math.H:39
__host__ __device__ double sinpi(double x)
Return sin(x*pi) given x.
Definition AMReX_Math.H:99
constexpr std::enable_if_t< std::is_floating_point_v< T >, T > pi()
Definition AMReX_Math.H:68
__host__ __device__ std::pair< double, double > sincospi(double x)
Return sin(pi*x) and cos(pi*x) given x.
Definition AMReX_Math.H:204
__host__ __device__ double cospi(double x)
Return cos(x*pi) given x.
Definition AMReX_Math.H:75
__host__ __device__ double exp10(double x)
Return 10**x.
Definition AMReX_Math.H:364
__host__ __device__ T comp_ellint_1(T k)
Definition AMReX_Math.H:270
__host__ __device__ std::pair< double, double > sincos(double x)
Return sine and cosine of given number.
Definition AMReX_Math.H:160
__host__ __device__ T comp_ellint_2(T k)
Definition AMReX_Math.H:295
__host__ __device__ double rsqrt(double x)
Return inverse square root of x.
Definition AMReX_Math.H:336
constexpr T powi(T x) noexcept
Return pow(x, Power), where Power is an integer known at compile time.
Definition AMReX_Math.H:234
Definition AMReX_SIMD.H:24
Definition AMReX_Amr.cpp:49
__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:438
__host__ __device__ std::uint64_t divide(std::uint64_t dividend) const
Returns the quotient of floor(dividend / divisor)
Definition AMReX_Math.H:494
__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:516
__host__ __device__ void operator()(std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend) const
Definition AMReX_Math.H:526
__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:509
std::uint64_t divisor
Definition AMReX_Math.H:439
FastDivmodU64(std::uint64_t divisor_)
Definition AMReX_Math.H:485
FastDivmodU64()=default
Default construct an invalid FastDivmodU64.