3#include <AMReX_Config.H>
17# include <sycl/sycl.hpp>
20namespace amrex {
inline namespace disabled {
64constexpr std::enable_if_t<std::is_floating_point_v<T>,T>
pi ()
66 return T(3.1415926535897932384626433832795029L);
73#if defined(AMREX_USE_SYCL)
74 return sycl::cospi(
x);
85#if defined(AMREX_USE_SYCL)
86 return sycl::cospi(
x);
97#if defined(AMREX_USE_SYCL)
98 return sycl::sinpi(
x);
109#if defined(AMREX_USE_SYCL)
110 return sycl::sinpi(
x);
119#if defined(_GNU_SOURCE) && !defined(__APPLE__)
128#if defined(_GNU_SOURCE) && !defined(__APPLE__)
139template<
typename T_Real,
140 std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,
int> = 0>
142std::pair<T_Real,T_Real>
sincos (T_Real
x)
145 std::pair<T_Real,T_Real>
r;
156 std::pair<double,double>
r;
157#if defined(AMREX_USE_SYCL)
158 r.first = sycl::sincos(
x, sycl::private_ptr<double>(&
r.second));
170 std::pair<float,float>
r;
171#if defined(AMREX_USE_SYCL)
172 r.first = sycl::sincos(
x, sycl::private_ptr<float>(&
r.second));
182template<
typename T_Real,
183 std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,
int> = 0>
185std::pair<T_Real,T_Real>
sincospi (T_Real
x)
188 T_Real
const px = pi<typename T_Real::value_type>() *
x;
189 std::pair<T_Real,T_Real>
r;
200 std::pair<double,double>
r;
201#if defined(AMREX_USE_SYCL)
214 std::pair<float,float>
r;
215#if defined(AMREX_USE_SYCL)
225template <
int Power,
typename T,
226 typename = std::enable_if_t<!std::is_integral<T>() || Power>=0>>
230 if constexpr (Power < 0) {
231 return T(1)/
powi<-Power>(
x);
232 }
else if constexpr (Power == 0) {
235 }
else if constexpr (Power == 1) {
237 }
else if constexpr (Power == 2) {
239 }
else if constexpr (Power%2 == 0) {
240 return powi<2>(powi<Power/2>(
x));
242 return x*
powi<Power-1>(
x);
246#if defined(AMREX_INT128_SUPPORTED)
248std::uint64_t umulhi (std::uint64_t a, std::uint64_t
b)
250#if defined(AMREX_USE_SYCL)
251 return sycl::mul_hi(a,
b);
255 auto tmp = amrex::UInt128_t(a) * amrex::UInt128_t(
b);
256 return std::uint64_t(tmp >> 64);
268 T tol = std::numeric_limits<T>::epsilon();
271 T g0 = std::sqrt(1.0 - k*k);
276 while(std::abs(a0 - g0) > tol) {
278 g = std::sqrt(a0 * g0);
284 return 0.5*pi<T>()/a;
293 T Kcomp = amrex::Math::comp_ellint_1<T>(k);
294 T tol = std::numeric_limits<T>::epsilon();
298 T g0 = std::sqrt(1.0 - k*k);
299 T cn = std::sqrt(a0*a0 - g0*g0);
303 T a = 0.5 * (a0 + g0);
304 T g = std::sqrt(a0*g0);
311 while(std::abs(cn*cn) > tol) {
314 g = std::sqrt(a0*g0);
318 sum_val -= std::pow(2,n-1)*cn*cn;
325 return Kcomp*sum_val;
333#if defined(AMREX_USE_SYCL)
347#if defined(AMREX_USE_SYCL)
407#ifdef AMREX_INT128_SUPPORTED
408 std::uint64_t multiplier = 1U;
409 unsigned int shift_right = 0;
410 unsigned int round_up = 0;
417 static std::uint32_t integer_log2 (std::uint64_t
x)
433 shift_right = integer_log2(
divisor);
439 std::uint64_t power_of_two = (std::uint64_t(1) << shift_right);
440 auto n = amrex::UInt128_t(power_of_two) << 64;
441 std::uint64_t multiplier_lo = n /
divisor;
444 round_up = (multiplier_lo == multiplier ? 1 : 0);
460 std::uint64_t
divide (std::uint64_t dividend)
const
462#if defined(AMREX_INT128_SUPPORTED)
465 x = amrex::Math::umulhi(dividend + round_up, multiplier);
467 return (
x >> shift_right);
475 std::uint64_t
modulus (std::uint64_t quotient, std::uint64_t dividend)
const
477 return dividend - quotient *
divisor;
482 std::uint64_t
divmod (std::uint64_t &remainder, std::uint64_t dividend)
const
484 auto quotient =
divide(dividend);
485 remainder =
modulus(quotient, dividend);
492 void operator() (std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend)
const
494 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
void sincosf(float x, float *sinx, float *cosx)
Definition AMReX_Math.H:127
void sincos(double x, double *sinx, double *cosx)
Definition AMReX_Math.H:118
Definition AMReX_Math.H:35
__host__ __device__ double sinpi(double x)
Return sin(x*pi) given x.
Definition AMReX_Math.H:95
constexpr std::enable_if_t< std::is_floating_point_v< T >, T > pi()
Definition AMReX_Math.H:64
__host__ __device__ std::pair< double, double > sincospi(double x)
Return sin(pi*x) and cos(pi*x) given x.
Definition AMReX_Math.H:198
__host__ __device__ double cospi(double x)
Return cos(x*pi) given x.
Definition AMReX_Math.H:71
__host__ __device__ T comp_ellint_1(T k)
Definition AMReX_Math.H:264
__host__ __device__ std::pair< double, double > sincos(double x)
Return sine and cosine of given number.
Definition AMReX_Math.H:154
__host__ __device__ T comp_ellint_2(T k)
Definition AMReX_Math.H:289
__host__ __device__ double rsqrt(double x)
Return inverse square root of x.
Definition AMReX_Math.H:330
constexpr T powi(T x) noexcept
Return pow(x, Power), where Power is an integer known at compile time.
Definition AMReX_Math.H:228
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:360
Definition AMReX_FabArrayCommI.H:1000
Definition AMReX_Math.H:404
__host__ __device__ std::uint64_t divide(std::uint64_t dividend) const
Returns the quotient of floor(dividend / divisor)
Definition AMReX_Math.H:460
__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:482
__host__ __device__ void operator()(std::uint64_t "ient, std::uint64_t &remainder, std::uint64_t dividend) const
Definition AMReX_Math.H:492
__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:475
std::uint64_t divisor
Definition AMReX_Math.H:405
FastDivmodU64(std::uint64_t divisor_)
Definition AMReX_Math.H:451
FastDivmodU64()=default
Default construct an invalid FastDivmodU64.