3 #include <AMReX_Config.H>
11 #include <type_traits>
15 # include <sycl/sycl.hpp>
18 namespace amrex {
inline namespace disabled {
62 constexpr std::enable_if_t<std::is_floating_point_v<T>,T>
pi ()
64 return T(3.1415926535897932384626433832795029L);
71 #if defined(AMREX_USE_SYCL)
83 #if defined(AMREX_USE_SYCL)
95 #if defined(AMREX_USE_SYCL)
107 #if defined(AMREX_USE_SYCL)
117 #if defined(_GNU_SOURCE) && !defined(__APPLE__)
126 #if defined(_GNU_SOURCE) && !defined(__APPLE__)
137 std::pair<double,double>
sincos (
double x)
139 std::pair<double,double>
r;
140 #if defined(AMREX_USE_SYCL)
153 std::pair<float,float>
r;
154 #if defined(AMREX_USE_SYCL)
167 std::pair<double,double>
r;
168 #if defined(AMREX_USE_SYCL)
181 std::pair<float,float>
r;
182 #if defined(AMREX_USE_SYCL)
192 template <
int Power,
typename T,
193 typename = std::enable_if_t<!std::is_integral<T>() || Power>=0>>
195 constexpr T
powi (T x) noexcept
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)
215 std::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);
229 template <
typename T>
235 T tol = std::numeric_limits<T>::epsilon();
251 return 0.5*pi<T>()/a;
254 template <
typename T>
260 T Kcomp = amrex::Math::comp_ellint_1<T>(k);
261 T tol = std::numeric_limits<T>::epsilon();
270 T a = 0.5 * (a0 + g0);
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_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool isinf(T m) noexcept
Definition: AMReX_GpuUtility.H:161
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::pair< float, float > sincos(float x)
Return sine and cosine of given number.
Definition: AMReX_Math.H:151
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE float sinpi(float x)
Return sin(x*pi) given x.
Definition: AMReX_Math.H:105
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T comp_ellint_2(T k)
Definition: AMReX_Math.H:256
constexpr AMREX_FORCE_INLINE T powi(T x) noexcept
Return pow(x, Power), where Power is an integer known at compile time.
Definition: AMReX_Math.H:195
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_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 float cospi(float x)
Return cos(x*pi) given x.
Definition: AMReX_Math.H:81
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 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 long long abs(long long)
AMREX_GPU_HOST_DEVICE double abs(double)
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
Raise a complex number to a (real) power.
Definition: AMReX_GpuComplex.H:418
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373
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.