Skip to content

Commit 7c99975

Browse files
authored
Update Math::sincos and sincospi (#4575)
- Revert the change made to scalar types. They are now non-templates. - Use std::enable_if to restrict function templates to simd types. - Fix sincospi for simd types.
1 parent 4fb7103 commit 7c99975

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

Src/Base/AMReX_Math.H

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,22 @@ namespace detail {
133133
}
134134
}
135135

136+
#ifdef AMREX_USE_SIMD
136137
//! Return sine and cosine of given number
137-
template<typename T_Real
138-
#ifndef AMREX_USE_SIMD
139-
, std::enable_if_t<std::is_floating_point_v<T_Real>,int> = 0
140-
#endif
141-
>
138+
template<typename T_Real,
139+
std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,int> = 0>
142140
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
143141
std::pair<T_Real,T_Real> sincos (T_Real x)
144142
{
145-
#ifdef AMREX_USE_SIMD
146143
using namespace amrex::simd::stdx;
147-
#else
148-
using namespace std;
149-
#endif
150-
151144
std::pair<T_Real,T_Real> r;
152145
r.first = sin(x);
153146
r.second = cos(x);
154147
return r;
155148
}
149+
#endif
156150

157151
//! Return sine and cosine of given number
158-
template<>
159152
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
160153
std::pair<double,double> sincos (double x)
161154
{
@@ -170,7 +163,6 @@ std::pair<double,double> sincos (double x)
170163
}
171164

172165
//! Return sine and cosine of given number
173-
template<>
174166
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
175167
std::pair<float,float> sincos (float x)
176168
{
@@ -184,30 +176,23 @@ std::pair<float,float> sincos (float x)
184176
return r;
185177
}
186178

179+
#ifdef AMREX_USE_SIMD
187180
//! Return sin(pi*x) and cos(pi*x) given x
188-
template<typename T_Real
189-
#ifndef AMREX_USE_SIMD
190-
, std::enable_if_t<std::is_floating_point_v<T_Real>,int> = 0
191-
#endif
192-
>
181+
template<typename T_Real,
182+
std::enable_if_t<amrex::simd::stdx::is_simd_v<T_Real>,int> = 0>
193183
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
194184
std::pair<T_Real,T_Real> sincospi (T_Real x)
195185
{
196-
#ifdef AMREX_USE_SIMD
197186
using namespace amrex::simd::stdx;
198-
#else
199-
using namespace std;
200-
#endif
201-
202-
T_Real const px = pi<T_Real>() * x;
187+
T_Real const px = pi<typename T_Real::value_type>() * x;
203188
std::pair<T_Real,T_Real> r;
204189
r.first = sin(px);
205190
r.second = cos(px);
206191
return r;
207192
}
193+
#endif
208194

209195
//! Return sin(pi*x) and cos(pi*x) given x
210-
template<>
211196
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
212197
std::pair<double,double> sincospi (double x)
213198
{
@@ -222,7 +207,6 @@ std::pair<double,double> sincospi (double x)
222207
}
223208

224209
//! Return sin(pi*x) and cos(pi*x) given x
225-
template<>
226210
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
227211
std::pair<float,float> sincospi (float x)
228212
{

0 commit comments

Comments
 (0)