aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2024-02-27 18:42:12 +0100
committerGitHub <noreply@github.com>2024-02-27 18:42:12 +0100
commit27f589dea1dae6ec0033e1ad2902fb5dadfa562b (patch)
tree1869f9c6fb16320d7558bcae43463c621067a694 /test
parent085bde6889925b486291ddf1450b6bb6c8562a8f (diff)
parent885f40520e64b8a433ff437ba48ef7e87ad78e1b (diff)
downloadzig-27f589dea1dae6ec0033e1ad2902fb5dadfa562b.tar.gz
zig-27f589dea1dae6ec0033e1ad2902fb5dadfa562b.zip
Merge pull request #18538 from Pangoraw/wasm_vector_abi
wasm: allow non-int vectors
Diffstat (limited to 'test')
-rw-r--r--test/c_abi/cfuncs.c37
-rw-r--r--test/c_abi/main.zig36
2 files changed, 68 insertions, 5 deletions
diff --git a/test/c_abi/cfuncs.c b/test/c_abi/cfuncs.c
index aa7757d7ad..98540ed033 100644
--- a/test/c_abi/cfuncs.c
+++ b/test/c_abi/cfuncs.c
@@ -294,7 +294,37 @@ struct SplitStructMixed zig_ret_split_struct_mixed();
struct BigStruct zig_big_struct_both(struct BigStruct);
-#if defined(ZIG_BACKEND_STAGE2_X86_64) || defined(ZIG_PPC32)
+typedef float Vector2Float __attribute__((ext_vector_type(2)));
+typedef float Vector4Float __attribute__((ext_vector_type(4)));
+
+void c_vector_2_float(Vector2Float vec) {
+ assert_or_panic(vec[0] == 1.0);
+ assert_or_panic(vec[1] == 2.0);
+}
+
+void c_vector_4_float(Vector4Float vec) {
+ assert_or_panic(vec[0] == 1.0);
+ assert_or_panic(vec[1] == 2.0);
+ assert_or_panic(vec[2] == 3.0);
+ assert_or_panic(vec[3] == 4.0);
+}
+
+Vector2Float c_ret_vector_2_float(void) {
+ return (Vector2Float){
+ 1.0,
+ 2.0,
+ };
+}
+Vector4Float c_ret_vector_4_float(void) {
+ return (Vector4Float){
+ 1.0,
+ 2.0,
+ 3.0,
+ 4.0,
+ };
+}
+
+#if defined(ZIG_BACKEND_STAGE2_X86_64) || defined(ZIG_PPC32) || defined(__wasm__)
typedef bool Vector2Bool __attribute__((ext_vector_type(2)));
typedef bool Vector4Bool __attribute__((ext_vector_type(4)));
@@ -581,6 +611,9 @@ void c_vector_128_bool(Vector128Bool vec) {
assert_or_panic(vec[127] == true);
}
+// WASM: The following vector functions define too many Wasm locals for wasmtime in debug mode and are therefore disabled for the wasm target.
+#if !defined(__wasm__)
+
void c_vector_256_bool(Vector256Bool vec) {
assert_or_panic(vec[0] == false);
assert_or_panic(vec[1] == true);
@@ -1355,6 +1388,8 @@ void c_vector_512_bool(Vector512Bool vec) {
assert_or_panic(vec[511] == true);
}
+#endif
+
Vector2Bool c_ret_vector_2_bool(void) {
return (Vector2Bool){
true,
diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig
index 0e6ce8ab27..ffabf8147f 100644
--- a/test/c_abi/main.zig
+++ b/test/c_abi/main.zig
@@ -967,6 +967,34 @@ test "big simd vector" {
try expect(x[7] == 16);
}
+const Vector2Float = @Vector(2, f32);
+const Vector4Float = @Vector(4, f32);
+
+extern fn c_vector_2_float(Vector2Float) void;
+extern fn c_vector_4_float(Vector4Float) void;
+
+extern fn c_ret_vector_2_float() Vector2Float;
+extern fn c_ret_vector_4_float() Vector4Float;
+
+test "float simd vectors" {
+ if (builtin.cpu.arch == .powerpc or builtin.cpu.arch == .powerpc64le) return error.SkipZigTest;
+
+ {
+ c_vector_2_float(.{ 1.0, 2.0 });
+ const vec = c_ret_vector_2_float();
+ try expect(vec[0] == 1.0);
+ try expect(vec[1] == 2.0);
+ }
+ {
+ c_vector_4_float(.{ 1.0, 2.0, 3.0, 4.0 });
+ const vec = c_ret_vector_4_float();
+ try expect(vec[0] == 1.0);
+ try expect(vec[1] == 2.0);
+ try expect(vec[2] == 3.0);
+ try expect(vec[3] == 4.0);
+ }
+}
+
const Vector2Bool = @Vector(2, bool);
const Vector4Bool = @Vector(4, bool);
const Vector8Bool = @Vector(8, bool);
@@ -998,7 +1026,7 @@ extern fn c_ret_vector_256_bool() Vector256Bool;
extern fn c_ret_vector_512_bool() Vector512Bool;
test "bool simd vector" {
- if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch != .powerpc) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_llvm and (builtin.cpu.arch != .powerpc and builtin.cpu.arch != .wasm32)) return error.SkipZigTest;
{
c_vector_2_bool(.{
@@ -1550,8 +1578,9 @@ test "bool simd vector" {
try expect(vec[126] == false);
try expect(vec[127] == true);
}
+
{
- c_vector_256_bool(.{
+ if (builtin.target.cpu.arch != .wasm32) c_vector_256_bool(.{
false,
true,
true,
@@ -2069,7 +2098,7 @@ test "bool simd vector" {
try expect(vec[255] == false);
}
{
- c_vector_512_bool(.{
+ if (builtin.target.cpu.arch != .wasm32) c_vector_512_bool(.{
true,
true,
true,
@@ -3102,7 +3131,6 @@ test "bool simd vector" {
comptime {
skip: {
- if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) break :skip;
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .x86_64) break :skip;
_ = struct {