| author | |
| committer | |
| log | 885f40520e64b8a433ff437ba48ef7e87ad78e1b |
| tree | 04eaf144b53b11ffe31371d3bb10b375ee2e2714 |
| parent | 42446e6bf9cd224125fbbf334dd5a0712c94e8c5 |
2 files changed, 58 insertions(+), 0 deletions(-)
test/c_abi/cfuncs.c+30| ... | ... | @@ -236,6 +236,36 @@ struct SplitStructMixed zig_ret_split_struct_mixed(); |
| 236 | 236 | |
| 237 | 237 | struct BigStruct zig_big_struct_both(struct BigStruct); |
| 238 | 238 | |
| 239 | typedef float Vector2Float __attribute__((ext_vector_type(2))); | |
| 240 | typedef float Vector4Float __attribute__((ext_vector_type(4))); | |
| 241 | ||
| 242 | void c_vector_2_float(Vector2Float vec) { | |
| 243 | assert_or_panic(vec[0] == 1.0); | |
| 244 | assert_or_panic(vec[1] == 2.0); | |
| 245 | } | |
| 246 | ||
| 247 | void c_vector_4_float(Vector4Float vec) { | |
| 248 | assert_or_panic(vec[0] == 1.0); | |
| 249 | assert_or_panic(vec[1] == 2.0); | |
| 250 | assert_or_panic(vec[2] == 3.0); | |
| 251 | assert_or_panic(vec[3] == 4.0); | |
| 252 | } | |
| 253 | ||
| 254 | Vector2Float c_ret_vector_2_float(void) { | |
| 255 | return (Vector2Float){ | |
| 256 | 1.0, | |
| 257 | 2.0, | |
| 258 | }; | |
| 259 | } | |
| 260 | Vector4Float c_ret_vector_4_float(void) { | |
| 261 | return (Vector4Float){ | |
| 262 | 1.0, | |
| 263 | 2.0, | |
| 264 | 3.0, | |
| 265 | 4.0, | |
| 266 | }; | |
| 267 | } | |
| 268 | ||
| 239 | 269 | #if defined(ZIG_BACKEND_STAGE2_X86_64) || defined(ZIG_PPC32) || defined(__wasm__) |
| 240 | 270 | |
| 241 | 271 | typedef bool Vector2Bool __attribute__((ext_vector_type(2))); |
test/c_abi/main.zig+28| ... | ... | @@ -890,6 +890,34 @@ test "big simd vector" { |
| 890 | 890 | try expect(x[7] == 16); |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | const Vector2Float = @Vector(2, f32); | |
| 894 | const Vector4Float = @Vector(4, f32); | |
| 895 | ||
| 896 | extern fn c_vector_2_float(Vector2Float) void; | |
| 897 | extern fn c_vector_4_float(Vector4Float) void; | |
| 898 | ||
| 899 | extern fn c_ret_vector_2_float() Vector2Float; | |
| 900 | extern fn c_ret_vector_4_float() Vector4Float; | |
| 901 | ||
| 902 | test "float simd vectors" { | |
| 903 | if (builtin.cpu.arch == .powerpc or builtin.cpu.arch == .powerpc64le) return error.SkipZigTest; | |
| 904 | ||
| 905 | { | |
| 906 | c_vector_2_float(.{ 1.0, 2.0 }); | |
| 907 | const vec = c_ret_vector_2_float(); | |
| 908 | try expect(vec[0] == 1.0); | |
| 909 | try expect(vec[1] == 2.0); | |
| 910 | } | |
| 911 | { | |
| 912 | c_vector_4_float(.{ 1.0, 2.0, 3.0, 4.0 }); | |
| 913 | const vec = c_ret_vector_4_float(); | |
| 914 | try expect(vec[0] == 1.0); | |
| 915 | try expect(vec[1] == 2.0); | |
| 916 | try expect(vec[2] == 3.0); | |
| 917 | try expect(vec[3] == 4.0); | |
| 918 | } | |
| 919 | } | |
| 920 | ||
| 893 | 921 | const Vector2Bool = @Vector(2, bool); |
| 894 | 922 | const Vector4Bool = @Vector(4, bool); |
| 895 | 923 | const Vector8Bool = @Vector(8, bool); |