3#include <AMReX_Config.H>
15# include <sycl/sycl.hpp>
18namespace amrex {
inline namespace disabled {
62constexpr std::enable_if_t<std::is_floating_point_v<T>,T>
pi ()
64 return T(3.1415926535897932384626433832795029L);
71#if defined(AMREX_USE_SYCL)
72 return sycl::cospi(
x);
83#if defined(AMREX_USE_SYCL)
84 return sycl::cospi(
x);
95#if defined(AMREX_USE_SYCL)
96 return sycl::sinpi(
x);
107#if defined(AMREX_USE_SYCL)
108 return sycl::sinpi(
x);
117#if defined(_GNU_SOURCE) && !defined(__APPLE__)
126#if defined(_GNU_SOURCE) && !defined(__APPLE__)
139 std::pair<double,double>
r;
140#if defined(AMREX_USE_SYCL)
141 r.first = sycl::sincos(
x, sycl::private_ptr<double>(&
r.second));
153 std::pair<float,float>
r;
154#if defined(AMREX_USE_SYCL)
155 r.first = sycl::sincos(
x, sycl::private_ptr<float>(&
r.second));
167 std::pair<double,double>
r;
168#if defined(AMREX_USE_SYCL)
181 std::pair<float,float>
r;
182#if defined(AMREX_USE_SYCL)
192template <
int Power,
typename T,
193 typename = std::enable_if_t<!std::is_integral<T>() || Power>=0>>
197 if constexpr (Power < 0) {
198 return T(1)/
powi<-Power>(
x);
199 }
else if constexpr (Power == 0) {
202 }
else if constexpr (Power == 1) {
204 }
else if constexpr (Power == 2) {
206 }
else if constexpr (Power%2 == 0) {
207 return powi<2>(powi<Power/2>(
x));
209 return x*
powi<Power-1>(
x);
213#if defined(AMREX_INT128_SUPPORTED)
215std::uint64_t umulhi (std::uint64_t a, std::uint64_t
b)
217#if defined(AMREX_USE_SYCL)
218 return sycl::mul_hi(a,
b);
222 auto tmp = amrex::UInt128_t(a) * amrex::UInt128_t(
b);
223 return std::uint64_t(tmp >> 64);
235 T tol = std::numeric_limits<T>::epsilon();
238 T g0 = std::sqrt(1.0 - k*k);
243 while(std::abs(a0 - g0) > tol) {
245 g = std::sqrt(a0 * g0);
251 return 0.5*pi<T>()/a;
260 T Kcomp = amrex::Math::comp_ellint_1<T>(k);
261 T tol = std::numeric_limits<T>::epsilon();
265 T g0 = std::sqrt(1.0 - k*k);
266 T cn = std::sqrt(a0*a0 - g0*g0);
270 T a = 0.5 * (a0 + g0);
271 T g = std::sqrt(a0*g0);
278 while(std::abs(cn*cn) > tol) {
281 g = std::sqrt(a0*g0);
285 sum_val -= std::pow(2,n-1)*cn*cn;
292 return Kcomp*sum_val;
346#ifdef AMREX_INT128_SUPPORTED
347 std::uint64_t multiplier = 1U;
348 unsigned int shift_right = 0;
349 unsigned int round_up = 0;
356 static std::uint32_t integer_log2 (std::uint64_t
x)
372 shift_right = integer_log2(
divisor);
378 std::uint64_t power_of_two = (std::uint64_t(1) << shift_right);
379 auto n = amrex::UInt128_t(power_of_two) << 64;
380 std::uint64_t multiplier_lo = n /
divisor;
383 round_up = (multiplier_lo == multiplier ? 1 : 0);
399 std::uint64_t
divide (std::uint64_t dividend)
const
401#if defined(AMREX_INT128_SUPPORTED)
404 x = amrex::Math::umulhi(dividend + round_up, multiplier);
406 return (
x >> shift_right);
414 std::uint64_t
modulus (std::uint64_t quotient, std::uint64_t dividend)
const
416 return dividend - quotient *
divisor;
421 std::uint64_t
divmod (std::uint64_t &remainder, std::uint64_t dividend)
const
423 auto quotient =
divide(dividend);
424 remainder =
modulus(quotient, dividend);
431 void operator() (std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend)
const
433 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
AMREX_FORCE_INLINE void sincos(double x, double *sinx, double *cosx)
Definition AMReX_Math.H:116
AMREX_FORCE_INLINE void sincosf(float x, float *sinx, float *cosx)
Definition AMReX_Math.H:125
Definition AMReX_Math.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T comp_ellint_1(T k)
Definition AMReX_Math.H:231
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double sinpi(double x)
Return sin(x*pi) given x.
Definition AMReX_Math.H:93
constexpr std::enable_if_t< std::is_floating_point_v< T >, T > pi()
Definition AMReX_Math.H:62
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T comp_ellint_2(T k)
Definition AMReX_Math.H:256
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::pair< double, double > sincospi(double x)
Return sin(pi*x) and cos(pi*x) given x.
Definition AMReX_Math.H:165
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double cospi(double x)
Return cos(x*pi) given x.
Definition AMReX_Math.H:69
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::pair< double, double > sincos(double x)
Return sine and cosine of given number.
Definition AMReX_Math.H:137
AMREX_FORCE_INLINE constexpr T powi(T x) noexcept
Return pow(x, Power), where Power is an integer known at compile time.
Definition AMReX_Math.H:195
Definition AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition AMReX_GpuComplex.H:356
Definition AMReX_FabArrayCommI.H:896
Definition AMReX_Math.H:343
AMREX_GPU_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:421
AMREX_GPU_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:414
std::uint64_t divisor
Definition AMReX_Math.H:344
AMREX_GPU_HOST_DEVICE void operator()(std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend) const
Definition AMReX_Math.H:431
AMREX_GPU_HOST_DEVICE std::uint64_t divide(std::uint64_t dividend) const
Returns the quotient of floor(dividend / divisor)
Definition AMReX_Math.H:399
FastDivmodU64(std::uint64_t divisor_)
Definition AMReX_Math.H:390
FastDivmodU64()=default
Default construct an invalid FastDivmodU64.