Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use faster scalar version for trigo function #1073

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pythran/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def parse_define(define):
extension['define_macros'].append(
'__PYTHRAN__={}'.format(sys.version_info.major))

extension['define_macros'].append('XSIMD_ENABLE_FALLBACK')

here = os.path.dirname(os.path.dirname(__file__)) or '.'
# using / as separator as advised in the distutils doc
extension["include_dirs"].append(here + '/pythran')
Expand Down
5 changes: 4 additions & 1 deletion pythran/pythonic/include/numpy/arcsin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ PYTHONIC_NS_BEGIN
namespace numpy
{

#define TRIGO_FUN asin
#include "pythonic/include/numpy/trigo.hpp"

#define NUMPY_NARY_FUNC_NAME arcsin
#define NUMPY_NARY_FUNC_SYM xsimd::asin
#define NUMPY_NARY_FUNC_SYM wrapper::asin
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
6 changes: 5 additions & 1 deletion pythran/pythonic/include/numpy/arctan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

#define TRIGO_FUN atan
#include "pythonic/include/numpy/trigo.hpp"

#define NUMPY_NARY_FUNC_NAME arctan
#define NUMPY_NARY_FUNC_SYM xsimd::atan
#define NUMPY_NARY_FUNC_SYM wrapper::atan
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
5 changes: 4 additions & 1 deletion pythran/pythonic/include/numpy/arctan2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ PYTHONIC_NS_BEGIN
namespace numpy
{

#define TRIGO_FUN atan2
#include "pythonic/include/numpy/trigo2.hpp"

#define NUMPY_NARY_FUNC_NAME arctan2
#define NUMPY_NARY_FUNC_SYM xsimd::atan2
#define NUMPY_NARY_FUNC_SYM wrapper::atan2
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
5 changes: 4 additions & 1 deletion pythran/pythonic/include/numpy/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ PYTHONIC_NS_BEGIN

namespace numpy
{
#define TRIGO_FUN cos
#include "pythonic/include/numpy/trigo.hpp"

#define NUMPY_NARY_FUNC_NAME cos
#define NUMPY_NARY_FUNC_SYM xsimd::cos
#define NUMPY_NARY_FUNC_SYM wrapper::cos
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
1 change: 1 addition & 0 deletions pythran/pythonic/include/numpy/cosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

#define NUMPY_NARY_FUNC_NAME cosh
#define NUMPY_NARY_FUNC_SYM xsimd::cosh
#include "pythonic/include/types/numpy_nary_expr.hpp"
Expand Down
6 changes: 5 additions & 1 deletion pythran/pythonic/include/numpy/sin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

#define TRIGO_FUN sin
#include "pythonic/include/numpy/trigo.hpp"

#define NUMPY_NARY_FUNC_NAME sin
#define NUMPY_NARY_FUNC_SYM xsimd::sin
#define NUMPY_NARY_FUNC_SYM wrapper::sin
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
1 change: 1 addition & 0 deletions pythran/pythonic/include/numpy/sinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

#define NUMPY_NARY_FUNC_NAME sinh
#define NUMPY_NARY_FUNC_SYM xsimd::sinh
#include "pythonic/include/types/numpy_nary_expr.hpp"
Expand Down
6 changes: 5 additions & 1 deletion pythran/pythonic/include/numpy/tan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

#define TRIGO_FUN tan
#include "pythonic/include/numpy/trigo.hpp"

#define NUMPY_NARY_FUNC_NAME tan
#define NUMPY_NARY_FUNC_SYM xsimd::tan
#define NUMPY_NARY_FUNC_SYM wrapper::tan
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
1 change: 1 addition & 0 deletions pythran/pythonic/include/numpy/tanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

#define NUMPY_NARY_FUNC_NAME tanh
#define NUMPY_NARY_FUNC_SYM xsimd::tanh
#include "pythonic/include/types/numpy_nary_expr.hpp"
Expand Down
24 changes: 24 additions & 0 deletions pythran/pythonic/include/numpy/trigo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef TRIGO_FUN
#error missing TRIGO_FUN
#endif

namespace wrapper
{
template <class T>

inline float TRIGO_FUN(float x)
{
return xsimd::TRIGO_FUN(xsimd::simd_type<float>{x})[0];
}
inline double TRIGO_FUN(double x)
{
return xsimd::TRIGO_FUN(xsimd::simd_type<double>{x})[0];
}

template <class OtherType>
auto TRIGO_FUN(OtherType x) -> decltype(xsimd::TRIGO_FUN(x))
{
return xsimd::TRIGO_FUN(x);
}
}
#undef TRIGO_FUN
26 changes: 26 additions & 0 deletions pythran/pythonic/include/numpy/trigo2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef TRIGO_FUN
#error missing TRIGO_FUN
#endif

namespace wrapper
{
template <class T>

inline float TRIGO_FUN(float x, float y)
{
return xsimd::TRIGO_FUN(xsimd::simd_type<float>{x},
xsimd::simd_type<float>{y})[0];
}
inline double TRIGO_FUN(double x, double y)
{
return xsimd::TRIGO_FUN(xsimd::simd_type<double>{x},
xsimd::simd_type<double>{y})[0];
}

template <class OtherType>
auto TRIGO_FUN(OtherType x, OtherType y) -> decltype(xsimd::TRIGO_FUN(x, y))
{
return xsimd::TRIGO_FUN(x, y);
}
}
#undef TRIGO_FUN
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/arcsin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PYTHONIC_NS_BEGIN
namespace numpy
{
#define NUMPY_NARY_FUNC_NAME arcsin
#define NUMPY_NARY_FUNC_SYM xsimd::asin
#define NUMPY_NARY_FUNC_SYM wrapper::asin
#include "pythonic/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/arctan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PYTHONIC_NS_BEGIN
namespace numpy
{
#define NUMPY_NARY_FUNC_NAME arctan
#define NUMPY_NARY_FUNC_SYM xsimd::atan
#define NUMPY_NARY_FUNC_SYM wrapper::atan
#include "pythonic/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/arctan2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace numpy
{

#define NUMPY_NARY_FUNC_NAME arctan2
#define NUMPY_NARY_FUNC_SYM xsimd::atan2
#define NUMPY_NARY_FUNC_SYM wrapper::atan2
#include "pythonic/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace numpy
{

#define NUMPY_NARY_FUNC_NAME cos
#define NUMPY_NARY_FUNC_SYM xsimd::cos
#define NUMPY_NARY_FUNC_SYM wrapper::cos
#include "pythonic/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/sin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PYTHONIC_NS_BEGIN
namespace numpy
{
#define NUMPY_NARY_FUNC_NAME sin
#define NUMPY_NARY_FUNC_SYM xsimd::sin
#define NUMPY_NARY_FUNC_SYM wrapper::sin
#include "pythonic/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/tan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PYTHONIC_NS_BEGIN
namespace numpy
{
#define NUMPY_NARY_FUNC_NAME tan
#define NUMPY_NARY_FUNC_SYM xsimd::tan
#define NUMPY_NARY_FUNC_SYM wrapper::tan
#include "pythonic/types/numpy_nary_expr.hpp"
}
PYTHONIC_NS_END
Expand Down