1 | /* Copyright (C) 2011-2012 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_DETAIL_NULL_MEMORY_H |
9 | #define LIBSIMDPP_DETAIL_NULL_MEMORY_H |
10 | #if SIMDPP_USE_NULL || SIMDPP_USE_NEON || SIMDPP_USE_ALTIVEC |
11 | |
12 | #ifndef LIBSIMDPP_SIMD_H |
13 | #error "This file must be included through simd.h" |
14 | #endif |
15 | |
16 | #include <simdpp/types.h> |
17 | |
18 | namespace simdpp { |
19 | namespace SIMDPP_ARCH_NAMESPACE { |
20 | namespace detail { |
21 | namespace null { |
22 | |
23 | template<class V> SIMDPP_INL |
24 | void load(V& a, const char* p) |
25 | { |
26 | using T = typename V::element_type; |
27 | const T* pt = reinterpret_cast<const T*>(p); |
28 | for (unsigned i = 0; i < V::length; i++) { |
29 | a.el(i) = *pt++; |
30 | } |
31 | } |
32 | |
33 | template<class V> SIMDPP_INL |
34 | void load_packed2(V& a, V& b, const char* p) |
35 | { |
36 | using T = typename V::element_type; |
37 | const T* pt = reinterpret_cast<const T*>(p); |
38 | for (unsigned i = 0; i < V::length; i++) { |
39 | a.el(i) = *pt++; |
40 | b.el(i) = *pt++; |
41 | } |
42 | } |
43 | |
44 | template<class V> SIMDPP_INL |
45 | void load_packed3(V& a, V& b, V& c, const char* p) |
46 | { |
47 | using T = typename V::element_type; |
48 | const T* pt = reinterpret_cast<const T*>(p); |
49 | for (unsigned i = 0; i < V::length; i++) { |
50 | a.el(i) = *pt++; |
51 | b.el(i) = *pt++; |
52 | c.el(i) = *pt++; |
53 | } |
54 | } |
55 | |
56 | template<class V> SIMDPP_INL |
57 | void load_packed4(V& a, V& b, V& c, V& d, const char* p) |
58 | { |
59 | using T = typename V::element_type; |
60 | const T* pt = reinterpret_cast<const T*>(p); |
61 | for (unsigned i = 0; i < V::length; i++) { |
62 | a.el(i) = *pt++; |
63 | b.el(i) = *pt++; |
64 | c.el(i) = *pt++; |
65 | d.el(i) = *pt++; |
66 | } |
67 | } |
68 | |
69 | template<class V> SIMDPP_INL |
70 | void store(char* p, const V& a) |
71 | { |
72 | using T = typename V::element_type; |
73 | T* pt = reinterpret_cast<T*>(p); |
74 | for (unsigned i = 0; i < V::length; i++) { |
75 | *pt++ = a.el(i); |
76 | } |
77 | } |
78 | |
79 | template<class V, class M> SIMDPP_INL |
80 | void store_masked(char* p, const V& a, const M& mask) |
81 | { |
82 | using T = typename V::element_type; |
83 | T* pt = reinterpret_cast<T*>(p); |
84 | for (unsigned i = 0; i < a.length; ++i) { |
85 | if (mask.el(i)) |
86 | *pt = a.el(i); |
87 | pt++; |
88 | } |
89 | } |
90 | |
91 | template<class V> SIMDPP_INL |
92 | void store_first(char* p, const V& a, unsigned n) |
93 | { |
94 | using T = typename V::element_type; |
95 | T* pt = reinterpret_cast<T*>(p); |
96 | for (unsigned i = 0; i < V::length && i < n; i++) { |
97 | *pt++ = a.el(i); |
98 | } |
99 | } |
100 | |
101 | template<class V> SIMDPP_INL |
102 | void store_last(char* p, const V& a, unsigned n) |
103 | { |
104 | using T = typename V::element_type; |
105 | T* pt = reinterpret_cast<T*>(p); |
106 | pt += V::length - n; |
107 | for (unsigned i = V::length - n; i < V::length; i++) { |
108 | *pt++ = a.el(i); |
109 | } |
110 | } |
111 | |
112 | template<class V> SIMDPP_INL |
113 | void store_packed2(char* p, const V& a, const V& b) |
114 | { |
115 | using T = typename V::element_type; |
116 | T* pt = reinterpret_cast<T*>(p); |
117 | for (unsigned i = 0; i < V::length; i++) { |
118 | *pt++ = a.el(i); |
119 | *pt++ = b.el(i); |
120 | } |
121 | } |
122 | |
123 | template<class V> SIMDPP_INL |
124 | void store_packed3(char* p, const V& a, const V& b, const V& c) |
125 | { |
126 | using T = typename V::element_type; |
127 | T* pt = reinterpret_cast<T*>(p); |
128 | for (unsigned i = 0; i < V::length; i++) { |
129 | *pt++ = a.el(i); |
130 | *pt++ = b.el(i); |
131 | *pt++ = c.el(i); |
132 | } |
133 | } |
134 | |
135 | template<class V> SIMDPP_INL |
136 | void store_packed4(char* p, const V& a, const V& b, const V& c, const V& d) |
137 | { |
138 | using T = typename V::element_type; |
139 | T* pt = reinterpret_cast<T*>(p); |
140 | for (unsigned i = 0; i < V::length; i++) { |
141 | *pt++ = a.el(i); |
142 | *pt++ = b.el(i); |
143 | *pt++ = c.el(i); |
144 | *pt++ = d.el(i); |
145 | } |
146 | } |
147 | |
148 | } // namespace null |
149 | } // namespace detail |
150 | } // namespace SIMDPP_ARCH_NAMESPACE |
151 | } // namespace simdpp |
152 | |
153 | #endif |
154 | #endif |
155 | |