authorgravatar for paul@plutojl.orgPaul Berg <paul@plutojl.org> 2024-02-14 10:40:19+01:00
committergravatar for paul@plutojl.orgPaul Berg <paul@plutojl.org> 2024-02-15 13:17:46+01:00
log885f40520e64b8a433ff437ba48ef7e87ad78e1b
tree04eaf144b53b11ffe31371d3bb10b375ee2e2714
parent42446e6bf9cd224125fbbf334dd5a0712c94e8c5

c_abi: add vector tests for floats


2 files changed, 58 insertions(+), 0 deletions(-)

test/c_abi/cfuncs.c+30
......@@ -236,6 +236,36 @@ struct SplitStructMixed zig_ret_split_struct_mixed();
236236
237237struct BigStruct zig_big_struct_both(struct BigStruct);
238238
239typedef float Vector2Float __attribute__((ext_vector_type(2)));
240typedef float Vector4Float __attribute__((ext_vector_type(4)));
241
242void c_vector_2_float(Vector2Float vec) {
243 assert_or_panic(vec[0] == 1.0);
244 assert_or_panic(vec[1] == 2.0);
245}
246
247void 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
254Vector2Float c_ret_vector_2_float(void) {
255 return (Vector2Float){
256 1.0,
257 2.0,
258 };
259}
260Vector4Float c_ret_vector_4_float(void) {
261 return (Vector4Float){
262 1.0,
263 2.0,
264 3.0,
265 4.0,
266 };
267}
268
239269#if defined(ZIG_BACKEND_STAGE2_X86_64) || defined(ZIG_PPC32) || defined(__wasm__)
240270
241271typedef bool Vector2Bool __attribute__((ext_vector_type(2)));
test/c_abi/main.zig+28
......@@ -890,6 +890,34 @@ test "big simd vector" {
890890 try expect(x[7] == 16);
891891}
892892
893const Vector2Float = @Vector(2, f32);
894const Vector4Float = @Vector(4, f32);
895
896extern fn c_vector_2_float(Vector2Float) void;
897extern fn c_vector_4_float(Vector4Float) void;
898
899extern fn c_ret_vector_2_float() Vector2Float;
900extern fn c_ret_vector_4_float() Vector4Float;
901
902test "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
893921const Vector2Bool = @Vector(2, bool);
894922const Vector4Bool = @Vector(4, bool);
895923const Vector8Bool = @Vector(8, bool);