1 // unary arithmetic simd functions
2 // Copyright (C) 2010 Tim Blechmann
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.
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_UNARY_ARITHMETIC_HPP
20 #define SIMD_UNARY_ARITHMETIC_HPP
24 #include "detail/define_macros.hpp"
26 #if defined(__GNUC__) && defined(NDEBUG)
27 #define always_inline inline __attribute__((always_inline))
29 #define always_inline inline
36 #define DEFINE_UNARY_FUNCTOR(NAME, VEC_NAME) \
39 template <typename FloatType> \
40 always_inline FloatType operator()(FloatType arg) const \
44 template <typename FloatType> \
45 always_inline vec<FloatType> operator()(vec<FloatType> arg) const \
47 return VEC_NAME(arg); \
52 DEFINE_UNARY_FUNCTOR(fabs
, abs
)
53 DEFINE_UNARY_FUNCTOR(sign
, sign
)
54 DEFINE_UNARY_FUNCTOR(square
, square
)
55 DEFINE_UNARY_FUNCTOR(cube
, cube
)
56 DEFINE_UNARY_FUNCTOR(reciprocal
, reciprocal
)
58 DEFINE_UNARY_FUNCTOR(round
, round
)
59 DEFINE_UNARY_FUNCTOR(frac
, frac
)
60 DEFINE_UNARY_FUNCTOR(ceil
, ceil
)
61 DEFINE_UNARY_FUNCTOR(floor
, floor
)
62 DEFINE_UNARY_FUNCTOR(trunc
, trunc
)
63 DEFINE_UNARY_FUNCTOR(undenormalize
, undenormalize
)
65 } /* namespace detail */
67 NOVA_SIMD_DEFINE_UNARY_WRAPPER(abs
, detail::fabs_
)
68 NOVA_SIMD_DEFINE_UNARY_WRAPPER(sgn
, detail::sign_
)
69 NOVA_SIMD_DEFINE_UNARY_WRAPPER(square
, detail::square_
)
70 NOVA_SIMD_DEFINE_UNARY_WRAPPER(cube
, detail::cube_
)
72 NOVA_SIMD_DEFINE_UNARY_WRAPPER(round
, detail::round_
)
73 NOVA_SIMD_DEFINE_UNARY_WRAPPER(frac
, detail::frac_
)
74 NOVA_SIMD_DEFINE_UNARY_WRAPPER(ceil
, detail::ceil_
)
75 NOVA_SIMD_DEFINE_UNARY_WRAPPER(floor
, detail::floor_
)
76 NOVA_SIMD_DEFINE_UNARY_WRAPPER(trunc
, detail::trunc_
)
78 NOVA_SIMD_DEFINE_UNARY_WRAPPER(undenormalize
, detail::undenormalize_
)
79 NOVA_SIMD_DEFINE_UNARY_WRAPPER(reciprocal
, detail::reciprocal_
)
80 } /* namespace nova */
83 #undef DEFINE_UNARY_FUNCTOR
85 #endif /* SIMD_UNARY_ARITHMETIC_HPP */