DUNE PDELab (git)

io.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3#ifndef DUNE_COMMON_SIMD_IO_HH
4#define DUNE_COMMON_SIMD_IO_HH
5
16#include <ios>
17#include <type_traits>
18
22
23namespace Dune {
24
25 namespace SimdImpl {
26
27 template<class T>
28 class Inserter {
29 T value_;
30
31 public:
32 Inserter(const T &value) : value_(value) {}
33
34 template<class Stream,
35 class = std::enable_if_t<std::is_base_of<std::ios_base,
36 Stream>::value> >
37 friend Stream& operator<<(Stream &out, const Inserter &ins)
38 {
39 const char *sep = "<";
40 for(auto l : range(Simd::lanes(ins.value_)))
41 {
42 out << sep << autoCopy(Simd::lane(l, ins.value_));
43 sep = ", ";
44 }
45 out << '>';
46 return out;
47 }
48 };
49
50 template<class V, class = std::enable_if_t<Simd::lanes<V>() != 1> >
51 Inserter<V> io(const V &v)
52 {
53 return { v };
54 }
55
56 template<class V, class = std::enable_if_t<Simd::lanes<V>() == 1> >
57 Simd::Scalar<V> io(const V &v)
58 {
59 return Simd::lane(0, v);
60 }
61
62 }
63
64 namespace Simd {
65
82
89 template<class V>
90 auto vio(const V &v)
91 {
92 return SimdImpl::Inserter<V>{ v };
93 }
94
96
105 template<class V>
106 auto io(const V &v)
107 {
108 return SimdImpl::io(v);
109 }
110
112
114
115 } // namespace Simd
116} // namespace Dune
117
118#endif // DUNE_COMMON_SIMD_IO_HH
Traits for type conversions and type information.
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition: interface.hh:305
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition: interface.hh:324
Dune namespace.
Definition: alignedallocator.hh:13
Utilities for reduction like operations on ranges.
Include file for users of the SIMD abstraction layer.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)