File tree Expand file tree Collapse file tree 3 files changed +21
-18
lines changed
crates/intrinsic-test/src Expand file tree Collapse file tree 3 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ pub const POLY128_OSTREAM_DECL: &str = r#"
8
8
std::ostream& operator<<(std::ostream& os, poly128_t value);
9
9
std::ostream& operator<<(std::ostream& os, float16_t value);
10
10
#endif
11
+
12
+ // T1 is the `To` type, T2 is the `From` type
13
+ template<typename T1, typename T2> T1 cast(T2 x) {{
14
+ static_assert(sizeof(T1) == sizeof(T2), "sizeof T1 and T2 must be the same");
15
+ T1 ret{{}};
16
+ memcpy(&ret, &x, sizeof(T1));
17
+ return ret;
18
+ }}
11
19
"# ;
12
20
13
21
pub const POLY128_OSTREAM_DEF : & str = r#"
Original file line number Diff line number Diff line change @@ -122,24 +122,6 @@ pub fn write_mod_cpp<T: IntrinsicTypeDefinition>(
122
122
123
123
writeln ! ( w, "{}" , forward_declarations) ?;
124
124
125
- writeln ! (
126
- w,
127
- r#"
128
- // T1 is the `To` type, T2 is the `From` type
129
- template<typename T1, typename T2> T1 cast(T2 x) {{
130
- if (std::is_convertible<T2, T1>::value) {{
131
- return x;
132
- }} else if (sizeof(T1) == sizeof(T2)) {{
133
- T1 ret{{}};
134
- memcpy(&ret, &x, sizeof(T1));
135
- return ret;
136
- }} else {{
137
- assert("T2 must either be convertable to T1, or have the same size as T1!");
138
- }}
139
- }}
140
- "#
141
- ) ?;
142
-
143
125
for intrinsic in intrinsics {
144
126
create_c_test_function ( w, intrinsic) ?;
145
127
}
Original file line number Diff line number Diff line change @@ -269,6 +269,19 @@ std::ostream& operator<<(std::ostream& os, __m512i value) {
269
269
return os;
270
270
}
271
271
272
+ // T1 is the `To` type, T2 is the `From` type
273
+ template<typename T1, typename T2> T1 cast(T2 x) {{
274
+ if (std::is_convertible<T2, T1>::value) {{
275
+ return x;
276
+ }} else if (sizeof(T1) == sizeof(T2)) {{
277
+ T1 ret{{}};
278
+ memcpy(&ret, &x, sizeof(T1));
279
+ return ret;
280
+ }} else {{
281
+ assert("T2 must either be convertable to T1, or have the same size as T1!");
282
+ }}
283
+ }}
284
+
272
285
#define _mm512_extract_intrinsic_test_epi8(m, lane) \
273
286
_mm_extract_epi8(_mm512_extracti64x2_epi64((m), (lane) / 16), (lane) % 16)
274
287
You can’t perform that action at this time.
0 commit comments