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
20namespace simdpp {
21namespace SIMDPP_ARCH_NAMESPACE {
22namespace detail {
23
24template<class Int> SIMDPP_INL void scalar_convert(Int& d, uint64_t x) { d = static_cast<Int>(x); }
25static SIMDPP_INL
26void scalar_convert(float& d, uint64_t x) { d = bit_cast<float>(uint32_t(x)); }
27static SIMDPP_INL
28void scalar_convert(double& d, uint64_t x) { d = bit_cast<double>(x); }
29
30static SIMDPP_INL
31uint64_t cast_int(const int& x) { return (unsigned int) x; }
32static SIMDPP_INL
33uint64_t cast_int(const long& x) { return (unsigned long) x; }
34static SIMDPP_INL
35uint64_t cast_int(const long long& x) { return (unsigned long long) x; }
36static SIMDPP_INL
37uint64_t cast_int(const unsigned& x) { return x; }
38static SIMDPP_INL
39uint64_t cast_int(const unsigned long& x) { return x; }
40static SIMDPP_INL
41uint64_t cast_int(const unsigned long long& x) { return x; }
42
43template<class V> SIMDPP_INL
44V 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
53template<class R, class EL> SIMDPP_INL
54R 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
63template<class R, class EL> SIMDPP_INL
64R 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