memcpy: hide some memory latencies
[nova-simd.git] / simd_math.hpp
blobfe0120d28dd31ce83b24ba00a1f61076bc6df966
1 // simdfied mathematical functions
2 // Copyright (C) 2009 Tim Blechmann
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; see the file COPYING. If not, write to
16 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 // Boston, MA 02111-1307, USA.
19 #ifndef SIMD_MATH_HPP
20 #define SIMD_MATH_HPP
22 #include "vec.hpp"
24 #include "detail/math.hpp"
25 #include "detail/unroll_helpers.hpp"
26 #include "detail/define_macros.hpp"
28 #if defined(__GNUC__) && defined(NDEBUG)
29 #define always_inline inline __attribute__((always_inline))
30 #else
31 #define always_inline inline
32 #endif
35 namespace nova {
37 #define DEFINE_UNARY_FUNCTOR(NAME) \
38 namespace detail { \
39 struct NAME##_ \
40 { \
41 template <typename FloatType> \
42 always_inline FloatType operator()(FloatType arg) const \
43 { \
44 return NAME(arg); \
45 } \
46 }; \
47 } // namespace detail
50 #define DEFINE_UNARY_MATH_FUNCTIONS(NAME) \
51 DEFINE_UNARY_FUNCTOR(NAME) \
52 NOVA_SIMD_DEFINE_UNARY_WRAPPER(NAME, detail::NAME##_)
55 DEFINE_UNARY_MATH_FUNCTIONS(sin)
56 DEFINE_UNARY_MATH_FUNCTIONS(cos)
57 DEFINE_UNARY_MATH_FUNCTIONS(tan)
58 DEFINE_UNARY_MATH_FUNCTIONS(asin)
59 DEFINE_UNARY_MATH_FUNCTIONS(acos)
60 DEFINE_UNARY_MATH_FUNCTIONS(atan)
62 DEFINE_UNARY_MATH_FUNCTIONS(tanh)
64 DEFINE_UNARY_MATH_FUNCTIONS(log)
65 DEFINE_UNARY_MATH_FUNCTIONS(log2)
66 DEFINE_UNARY_MATH_FUNCTIONS(log10)
67 DEFINE_UNARY_MATH_FUNCTIONS(exp)
69 DEFINE_UNARY_MATH_FUNCTIONS(signed_sqrt)
73 #define DEFINE_BINARY_MATH_FUNCTOR(NAME) \
74 namespace detail { \
75 struct NAME##_ \
76 { \
77 template <typename FloatType> \
78 always_inline FloatType operator()(FloatType lhs, FloatType rhs) const \
79 { \
80 return NAME(lhs, rhs); \
81 } \
82 }; \
87 DEFINE_BINARY_MATH_FUNCTOR(pow)
88 DEFINE_BINARY_MATH_FUNCTOR(signed_pow)
90 NOVA_SIMD_DEFINE_BINARY_WRAPPER(pow, detail::pow_)
91 NOVA_SIMD_DEFINE_BINARY_WRAPPER(spow, detail::signed_pow_)
95 #undef DEFINE_UNARY_FUNCTOR
96 #undef DEFINE_BINARY_MATH_FUNCTOR
97 #undef DEFINE_UNARY_MATH_FUNCTIONS
98 #undef DEFINE_BINARY_MATH_FUNCTIONS
99 #undef always_inline
101 #endif /* SIMD_MATH_HPP */