3#include <AMReX_Config.H>
18# include <sycl/sycl.hpp>
23inline namespace disabled {
69constexpr std::enable_if_t<std::is_floating_point_v<T>,T>
pi ()
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,
147 std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,
int> = 0>
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,
190 std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,
int> = 0>
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,
233 typename = std::enable_if_t<!std::is_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);
253#if defined(AMREX_INT128_SUPPORTED)
255std::uint64_t umulhi (std::uint64_t a, std::uint64_t b)
257#if defined(AMREX_USE_SYCL)
258 return sycl::mul_hi(a,b);
262 auto tmp = amrex::UInt128_t(a) * amrex::UInt128_t(b);
263 return std::uint64_t(tmp >> 64);
275 T tol = std::numeric_limits<T>::epsilon();
278 T g0 = std::sqrt(1.0 - k*k);
283 while(std::abs(a0 - g0) > tol) {
285 g = std::sqrt(a0 * g0);
291 return 0.5*pi<T>()/a;
300 T Kcomp = amrex::Math::comp_ellint_1<T>(k);
301 T tol = std::numeric_limits<T>::epsilon();
305 T g0 = std::sqrt(1.0 - k*k);
306 T cn = std::sqrt(a0*a0 - g0*g0);
310 T a = 0.5 * (a0 + g0);
311 T g = std::sqrt(a0*g0);
318 while(std::abs(cn*cn) > tol) {
321 g = std::sqrt(a0*g0);
325 sum_val -= std::pow(2,n-1)*cn*cn;
332 return Kcomp*sum_val;
340#if defined(AMREX_USE_SYCL)
354#if defined(AMREX_USE_SYCL)
368#if defined(AMREX_USE_SYCL)
382#if defined(AMREX_USE_SYCL)
442#ifdef AMREX_INT128_SUPPORTED
443 std::uint64_t multiplier = 1U;
444 unsigned int shift_right = 0;
445 unsigned int round_up = 0;
452 static std::uint32_t integer_log2 (std::uint64_t
x)
468 shift_right = integer_log2(
divisor);
474 std::uint64_t power_of_two = (std::uint64_t(1) << shift_right);
475 auto n = amrex::UInt128_t(power_of_two) << 64;
476 std::uint64_t multiplier_lo = n /
divisor;
479 round_up = (multiplier_lo == multiplier ? 1 : 0);
495 std::uint64_t
divide (std::uint64_t dividend)
const
497#if defined(AMREX_INT128_SUPPORTED)
500 x = amrex::Math::umulhi(dividend + round_up, multiplier);
502 return (
x >> shift_right);
510 std::uint64_t
modulus (std::uint64_t quotient, std::uint64_t dividend)
const
512 return dividend - quotient *
divisor;
517 std::uint64_t
divmod (std::uint64_t &remainder, std::uint64_t dividend)
const
519 auto quotient =
divide(dividend);
520 remainder =
modulus(quotient, dividend);
527 void operator() (std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend)
const
529 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:40
__host__ __device__ double sinpi(double x)
Return sin(x*pi) given x.
Definition AMReX_Math.H:100
constexpr std::enable_if_t< std::is_floating_point_v< T >, T > pi()
Definition AMReX_Math.H:69
__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:365
__host__ __device__ T comp_ellint_1(T k)
Definition AMReX_Math.H:271
__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:296
__host__ __device__ double rsqrt(double x)
Return inverse square root of x.
Definition AMReX_Math.H:337
constexpr T powi(T x) noexcept
Return pow(x, Power), where Power is an integer known at compile time.
Definition AMReX_Math.H:235
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:439
__host__ __device__ std::uint64_t divide(std::uint64_t dividend) const
Returns the quotient of floor(dividend / divisor)
Definition AMReX_Math.H:495
__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:517
__host__ __device__ void operator()(std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend) const
Definition AMReX_Math.H:527
__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:510
std::uint64_t divisor
Definition AMReX_Math.H:440
FastDivmodU64(std::uint64_t divisor_)
Definition AMReX_Math.H:486
FastDivmodU64()=default
Default construct an invalid FastDivmodU64.