1 | /* Copyright (C) 2014 Povilas Kanapickas <povilas@radix.lt> |
2 | |
3 | Distributed under the Boost Software License, Version 1.0. |
4 | (See accompanying file LICENSE_1_0.txt or copy at |
5 | http://www.boost.org/LICENSE_1_0.txt) |
6 | */ |
7 | |
8 | #ifndef LIBSIMDPP_SIMDPP_DETAIL_EXPR_SCALAR_H |
9 | #define LIBSIMDPP_SIMDPP_DETAIL_EXPR_SCALAR_H |
10 | |
11 | #ifndef LIBSIMDPP_SIMD_H |
12 | #error "This file must be included through simd.h" |
13 | #endif |
14 | |
15 | #include <simdpp/types.h> |
16 | #include <simdpp/expr.h> |
17 | #include <simdpp/detail/insn/make_const.h> |
18 | #include <simdpp/core/detail/scalar_arg_impl.h> |
19 | |
20 | namespace simdpp { |
21 | namespace SIMDPP_ARCH_NAMESPACE { |
22 | namespace detail { |
23 | |
24 | template<class Int> SIMDPP_INL void scalar_convert(Int& d, uint64_t x) { d = static_cast<Int>(x); } |
25 | static SIMDPP_INL |
26 | void scalar_convert(float& d, uint64_t x) { d = bit_cast<float>(uint32_t(x)); } |
27 | static SIMDPP_INL |
28 | void scalar_convert(double& d, uint64_t x) { d = bit_cast<double>(x); } |
29 | |
30 | static SIMDPP_INL |
31 | uint64_t cast_int(const int& x) { return (unsigned int) x; } |
32 | static SIMDPP_INL |
33 | uint64_t cast_int(const long& x) { return (unsigned long) x; } |
34 | static SIMDPP_INL |
35 | uint64_t cast_int(const long long& x) { return (unsigned long long) x; } |
36 | static SIMDPP_INL |
37 | uint64_t cast_int(const unsigned& x) { return x; } |
38 | static SIMDPP_INL |
39 | uint64_t cast_int(const unsigned long& x) { return x; } |
40 | static SIMDPP_INL |
41 | uint64_t cast_int(const unsigned long long& x) { return x; } |
42 | |
43 | template<class V> SIMDPP_INL |
44 | V make_const_bitwise(uint64_t t) |
45 | { |
46 | typename detail::remove_sign<V>::type r; |
47 | expr_vec_make_const<typename V::element_type, 1> e; |
48 | scalar_convert(e.a[0], t); |
49 | insn::i_make_const(r, e, 0); |
50 | return V(r); |
51 | } |
52 | |
53 | template<class R, class EL> SIMDPP_INL |
54 | R expr_eval_scalar(const EL& q) |
55 | { |
56 | typename detail::remove_sign<R>::type r; |
57 | expr_vec_make_const<typename R::element_type, 1> e; |
58 | e.a[0] = static_cast<typename R::element_type>(q); |
59 | insn::i_make_const(r, e, 0); |
60 | return R(r); |
61 | } |
62 | |
63 | template<class R, class EL> SIMDPP_INL |
64 | R expr_eval_scalar_bitwise(const EL& q) |
65 | { |
66 | return make_const_bitwise<R>(cast_int(q)); |
67 | } |
68 | |
69 | } // namespace detail |
70 | } // namespace SIMDPP_ARCH_NAMESPACE |
71 | } // namespace simdpp |
72 | |
73 | #endif |
74 | |