1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include "opal_config.h"
19
20 #include <stddef.h>
21
22 #include "opal/datatype/opal_datatype.h"
23 #include "opal/datatype/opal_convertor.h"
24 #include "opal/datatype/opal_datatype_internal.h"
25 #include "opal/datatype/opal_datatype_checksum.h"
26 #include "opal/datatype/opal_convertor_internal.h"
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 #define COPY_TYPE( TYPENAME, TYPE, COUNT ) \
43 static int copy_##TYPENAME( opal_convertor_t *pConvertor, size_t count, \
44 char* from, size_t from_len, ptrdiff_t from_extent, \
45 char* to, size_t to_len, ptrdiff_t to_extent, \
46 ptrdiff_t *advance) \
47 { \
48 size_t remote_TYPE_size = sizeof(TYPE) * (COUNT); \
49 size_t local_TYPE_size = (COUNT) * sizeof(TYPE); \
50 \
51 \
52 if( (remote_TYPE_size * count) > from_len ) { \
53 count = from_len / remote_TYPE_size; \
54 if( (count * remote_TYPE_size) != from_len ) { \
55 DUMP( "oops should I keep this data somewhere (excedent %d bytes)?\n", \
56 from_len - (count * remote_TYPE_size) ); \
57 } \
58 DUMP( "correct: copy %s count %d from buffer %p with length %d to %p space %d\n", \
59 #TYPE, count, from, from_len, to, to_len ); \
60 } else \
61 DUMP( " copy %s count %d from buffer %p with length %d to %p space %d\n", \
62 #TYPE, count, from, from_len, to, to_len ); \
63 \
64 if( (from_extent == (ptrdiff_t)local_TYPE_size) && \
65 (to_extent == (ptrdiff_t)remote_TYPE_size) ) { \
66 \
67 MEMCPY( to, from, count * local_TYPE_size ); \
68 } else { \
69 \
70 for(size_t i = 0; i < count; i++ ) { \
71 MEMCPY( to, from, local_TYPE_size ); \
72 to += to_extent; \
73 from += from_extent; \
74 } \
75 } \
76 *advance = count * from_extent; \
77 return count; \
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 #define COPY_CONTIGUOUS_BYTES( TYPENAME, COUNT ) \
95 static size_t copy_##TYPENAME##_##COUNT( opal_convertor_t *pConvertor, size_t count, \
96 char* from, size_t from_len, ptrdiff_t from_extent, \
97 char* to, size_t to_len, ptrdiff_t to_extent, \
98 ptrdiff_t *advance ) \
99 { \
100 size_t remote_TYPE_size = (size_t)(COUNT); \
101 size_t local_TYPE_size = (size_t)(COUNT); \
102 \
103 if( (remote_TYPE_size * count) > from_len ) { \
104 count = from_len / remote_TYPE_size; \
105 if( (count * remote_TYPE_size) != from_len ) { \
106 DUMP( "oops should I keep this data somewhere (excedent %d bytes)?\n", \
107 from_len - (count * remote_TYPE_size) ); \
108 } \
109 DUMP( "correct: copy %s count %d from buffer %p with length %d to %p space %d\n", \
110 #TYPENAME, count, from, from_len, to, to_len ); \
111 } else \
112 DUMP( " copy %s count %d from buffer %p with length %d to %p space %d\n", \
113 #TYPENAME, count, from, from_len, to, to_len ); \
114 \
115 if( (from_extent == (ptrdiff_t)local_TYPE_size) && \
116 (to_extent == (ptrdiff_t)remote_TYPE_size) ) { \
117 MEMCPY( to, from, count * local_TYPE_size ); \
118 } else { \
119 for(size_t i = 0; i < count; i++ ) { \
120 MEMCPY( to, from, local_TYPE_size ); \
121 to += to_extent; \
122 from += from_extent; \
123 } \
124 } \
125 *advance = count * from_extent; \
126 return count; \
127 }
128
129
130
131 #define REQUIRE_COPY_BYTES_1 1
132 #define REQUIRE_COPY_BYTES_2 1
133 #define REQUIRE_COPY_BYTES_4 1
134 #define REQUIRE_COPY_BYTES_8 1
135 #define REQUIRE_COPY_BYTES_16 1
136
137 #if REQUIRE_COPY_BYTES_1
138 COPY_CONTIGUOUS_BYTES( bytes, 1 )
139 #endif
140 #if REQUIRE_COPY_BYTES_2
141 COPY_CONTIGUOUS_BYTES( bytes, 2 )
142 #endif
143 #if REQUIRE_COPY_BYTES_4
144 COPY_CONTIGUOUS_BYTES( bytes, 4 )
145 #endif
146 #if REQUIRE_COPY_BYTES_8
147 COPY_CONTIGUOUS_BYTES( bytes, 8 )
148 #endif
149 #if REQUIRE_COPY_BYTES_16
150 COPY_CONTIGUOUS_BYTES( bytes, 16 )
151 #endif
152
153 #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 2
154 COPY_TYPE( float_2, short float, 1 )
155 #elif SIZEOF_FLOAT == 2
156 COPY_TYPE( float_2, float, 1 )
157 #elif SIZEOF_DOUBLE == 2
158 COPY_TYPE( float_2, double, 1 )
159 #elif SIZEOF_LONG_DOUBLE == 2
160 COPY_TYPE( float_2, long double, 1 )
161 #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 2
162 COPY_TYPE( float_2, opal_short_float_t, 1 )
163 #else
164
165 #define copy_float_2 NULL
166 #endif
167
168 #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 4
169 COPY_TYPE( float_4, short float, 1 )
170 #elif SIZEOF_FLOAT == 4
171 COPY_TYPE( float_4, float, 1 )
172 #elif SIZEOF_DOUBLE == 4
173 COPY_TYPE( float_4, double, 1 )
174 #elif SIZEOF_LONG_DOUBLE == 4
175 COPY_TYPE( float_4, long double, 1 )
176 #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 4
177 COPY_TYPE( float_4, opal_short_float_t, 1 )
178 #else
179 #error No basic type for copy function for opal_datatype_float4 found
180 #endif
181
182 #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 8
183 COPY_TYPE( float_8, short float, 1 )
184 #elif SIZEOF_FLOAT == 8
185 COPY_TYPE( float_8, float, 1 )
186 #elif SIZEOF_DOUBLE == 8
187 COPY_TYPE( float_8, double, 1 )
188 #elif SIZEOF_LONG_DOUBLE == 8
189 COPY_TYPE( float_8, long double, 1 )
190 #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 8
191 COPY_TYPE( float_8, opal_short_float_t, 1 )
192 #else
193 #error No basic type for copy function for opal_datatype_float8 found
194 #endif
195
196 #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 12
197 COPY_TYPE( float_12, short float, 1 )
198 #elif SIZEOF_FLOAT == 12
199 COPY_TYPE( float_12, float, 1 )
200 #elif SIZEOF_DOUBLE == 12
201 COPY_TYPE( float_12, double, 1 )
202 #elif SIZEOF_LONG_DOUBLE == 12
203 COPY_TYPE( float_12, long double, 1 )
204 #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 12
205 COPY_TYPE( float_12, opal_short_float_t, 1 )
206 #else
207
208 #define copy_float_12 NULL
209 #endif
210
211 #if defined(HAVE_SHORT_FLOAT) && SIZEOF_SHORT_FLOAT == 16
212 COPY_TYPE( float_16, short float, 1 )
213 #elif SIZEOF_FLOAT == 16
214 COPY_TYPE( float_16, float, 1 )
215 #elif SIZEOF_DOUBLE == 16
216 COPY_TYPE( float_16, double, 1 )
217 #elif SIZEOF_LONG_DOUBLE == 16
218 COPY_TYPE( float_16, long double, 1 )
219 #elif defined(HAVE_OPAL_SHORT_FLOAT_T) && SIZEOF_OPAL_SHORT_FLOAT_T == 16
220 COPY_TYPE( float_16, opal_short_float_t, 1 )
221 #else
222
223 #define copy_float_16 NULL
224 #endif
225
226 #if defined(HAVE_SHORT_FLOAT__COMPLEX)
227 COPY_TYPE ( short_float_complex, short float _Complex, 1)
228 #elif defined(HAVE_OPAL_SHORT_FLOAT_COMPLEX_T)
229 COPY_TYPE ( short_float_complex, opal_short_float_complex_t, 1)
230 #else
231
232 #define copy_short_float_complex NULL
233 #endif
234
235 COPY_TYPE ( float_complex, float _Complex, 1)
236
237 COPY_TYPE ( double_complex, double _Complex, 1)
238
239 COPY_TYPE ( long_double_complex, long double _Complex, 1)
240
241 #if SIZEOF__BOOL == SIZEOF_CHAR
242 COPY_TYPE (bool, char, 1)
243 #elif SIZEOF__BOOL == SIZEOF_SHORT
244 COPY_TYPE (bool, short, 1)
245 #elif SIZEOF__BOOL == SIZEOF_INT
246 COPY_TYPE (bool, int, 1)
247 #elif SIZEOF__BOOL == SIZEOF_LONG
248 COPY_TYPE (bool, long, 1)
249 #else
250 #error No basic type for copy function for opal_datatype_bool found
251 #endif
252
253 COPY_TYPE (wchar, wchar_t, 1)
254
255
256
257
258 conversion_fct_t opal_datatype_copy_functions[OPAL_DATATYPE_MAX_PREDEFINED] = {
259 (conversion_fct_t)NULL,
260 (conversion_fct_t)NULL,
261 (conversion_fct_t)NULL,
262 (conversion_fct_t)NULL,
263 (conversion_fct_t)copy_bytes_1,
264 (conversion_fct_t)copy_bytes_2,
265 (conversion_fct_t)copy_bytes_4,
266 (conversion_fct_t)copy_bytes_8,
267 (conversion_fct_t)copy_bytes_16,
268 (conversion_fct_t)copy_bytes_1,
269 (conversion_fct_t)copy_bytes_2,
270 (conversion_fct_t)copy_bytes_4,
271 (conversion_fct_t)copy_bytes_8,
272 (conversion_fct_t)copy_bytes_16,
273 (conversion_fct_t)copy_float_2,
274 (conversion_fct_t)copy_float_4,
275 (conversion_fct_t)copy_float_8,
276 (conversion_fct_t)copy_float_12,
277 (conversion_fct_t)copy_float_16,
278 (conversion_fct_t)copy_short_float_complex,
279 (conversion_fct_t)copy_float_complex,
280 (conversion_fct_t)copy_double_complex,
281 (conversion_fct_t)copy_long_double_complex,
282 (conversion_fct_t)copy_bool,
283 (conversion_fct_t)copy_wchar,
284 (conversion_fct_t)NULL
285 };