| author | |
| committer | |
| log | 27f589dea1dae6ec0033e1ad2902fb5dadfa562b |
| tree | 1869f9c6fb16320d7558bcae43463c621067a694 |
| parent | 085bde6889925b486291ddf1450b6bb6c8562a8f |
| parent | 885f40520e64b8a433ff437ba48ef7e87ad78e1b |
| signature |
wasm: allow non-int vectors3 files changed, 70 insertions(+), 6 deletions(-)
src/arch/wasm/abi.zig+2-1| ... | @@ -45,7 +45,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class { | ... | @@ -45,7 +45,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class { |
| 45 | } | 45 | } |
| 46 | return classifyType(field_ty, mod); | 46 | return classifyType(field_ty, mod); |
| 47 | }, | 47 | }, |
| 48 | .Int, .Enum, .ErrorSet, .Vector => { | 48 | .Int, .Enum, .ErrorSet => { |
| 49 | const int_bits = ty.intInfo(mod).bits; | 49 | const int_bits = ty.intInfo(mod).bits; |
| 50 | if (int_bits <= 64) return direct; | 50 | if (int_bits <= 64) return direct; |
| 51 | if (int_bits <= 128) return .{ .direct, .direct }; | 51 | if (int_bits <= 128) return .{ .direct, .direct }; |
| ... | @@ -58,6 +58,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class { | ... | @@ -58,6 +58,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class { |
| 58 | return memory; | 58 | return memory; |
| 59 | }, | 59 | }, |
| 60 | .Bool => return direct, | 60 | .Bool => return direct, |
| 61 | .Vector => return direct, | ||
| 61 | .Array => return memory, | 62 | .Array => return memory, |
| 62 | .Optional => { | 63 | .Optional => { |
| 63 | assert(ty.isPtrLikeOptional(mod)); | 64 | assert(ty.isPtrLikeOptional(mod)); |
test/c_abi/cfuncs.c+36-1| ... | @@ -294,7 +294,37 @@ struct SplitStructMixed zig_ret_split_struct_mixed(); | ... | @@ -294,7 +294,37 @@ struct SplitStructMixed zig_ret_split_struct_mixed(); |
| 294 | 294 | ||
| 295 | struct BigStruct zig_big_struct_both(struct BigStruct); | 295 | struct BigStruct zig_big_struct_both(struct BigStruct); |
| 296 | 296 | ||
| 297 | #if defined(ZIG_BACKEND_STAGE2_X86_64) || defined(ZIG_PPC32) | 297 | typedef float Vector2Float __attribute__((ext_vector_type(2))); |
| 298 | typedef float Vector4Float __attribute__((ext_vector_type(4))); | ||
| 299 | |||
| 300 | void c_vector_2_float(Vector2Float vec) { | ||
| 301 | assert_or_panic(vec[0] == 1.0); | ||
| 302 | assert_or_panic(vec[1] == 2.0); | ||
| 303 | } | ||
| 304 | |||
| 305 | void c_vector_4_float(Vector4Float vec) { | ||
| 306 | assert_or_panic(vec[0] == 1.0); | ||
| 307 | assert_or_panic(vec[1] == 2.0); | ||
| 308 | assert_or_panic(vec[2] == 3.0); | ||
| 309 | assert_or_panic(vec[3] == 4.0); | ||
| 310 | } | ||
| 311 | |||
| 312 | Vector2Float c_ret_vector_2_float(void) { | ||
| 313 | return (Vector2Float){ | ||
| 314 | 1.0, | ||
| 315 | 2.0, | ||
| 316 | }; | ||
| 317 | } | ||
| 318 | Vector4Float c_ret_vector_4_float(void) { | ||
| 319 | return (Vector4Float){ | ||
| 320 | 1.0, | ||
| 321 | 2.0, | ||
| 322 | 3.0, | ||
| 323 | 4.0, | ||
| 324 | }; | ||
| 325 | } | ||
| 326 | |||
| 327 | #if defined(ZIG_BACKEND_STAGE2_X86_64) || defined(ZIG_PPC32) || defined(__wasm__) | ||
| 298 | 328 | ||
| 299 | typedef bool Vector2Bool __attribute__((ext_vector_type(2))); | 329 | typedef bool Vector2Bool __attribute__((ext_vector_type(2))); |
| 300 | typedef bool Vector4Bool __attribute__((ext_vector_type(4))); | 330 | typedef bool Vector4Bool __attribute__((ext_vector_type(4))); |
| ... | @@ -581,6 +611,9 @@ void c_vector_128_bool(Vector128Bool vec) { | ... | @@ -581,6 +611,9 @@ void c_vector_128_bool(Vector128Bool vec) { |
| 581 | assert_or_panic(vec[127] == true); | 611 | assert_or_panic(vec[127] == true); |
| 582 | } | 612 | } |
| 583 | 613 | ||
| 614 | // WASM: The following vector functions define too many Wasm locals for wasmtime in debug mode and are therefore disabled for the wasm target. | ||
| 615 | #if !defined(__wasm__) | ||
| 616 | |||
| 584 | void c_vector_256_bool(Vector256Bool vec) { | 617 | void c_vector_256_bool(Vector256Bool vec) { |
| 585 | assert_or_panic(vec[0] == false); | 618 | assert_or_panic(vec[0] == false); |
| 586 | assert_or_panic(vec[1] == true); | 619 | assert_or_panic(vec[1] == true); |
| ... | @@ -1355,6 +1388,8 @@ void c_vector_512_bool(Vector512Bool vec) { | ... | @@ -1355,6 +1388,8 @@ void c_vector_512_bool(Vector512Bool vec) { |
| 1355 | assert_or_panic(vec[511] == true); | 1388 | assert_or_panic(vec[511] == true); |
| 1356 | } | 1389 | } |
| 1357 | 1390 | ||
| 1391 | #endif | ||
| 1392 | |||
| 1358 | Vector2Bool c_ret_vector_2_bool(void) { | 1393 | Vector2Bool c_ret_vector_2_bool(void) { |
| 1359 | return (Vector2Bool){ | 1394 | return (Vector2Bool){ |
| 1360 | true, | 1395 | true, |
test/c_abi/main.zig+32-4| ... | @@ -967,6 +967,34 @@ test "big simd vector" { | ... | @@ -967,6 +967,34 @@ test "big simd vector" { |
| 967 | try expect(x[7] == 16); | 967 | try expect(x[7] == 16); |
| 968 | } | 968 | } |
| 969 | 969 | ||
| 970 | const Vector2Float = @Vector(2, f32); | ||
| 971 | const Vector4Float = @Vector(4, f32); | ||
| 972 | |||
| 973 | extern fn c_vector_2_float(Vector2Float) void; | ||
| 974 | extern fn c_vector_4_float(Vector4Float) void; | ||
| 975 | |||
| 976 | extern fn c_ret_vector_2_float() Vector2Float; | ||
| 977 | extern fn c_ret_vector_4_float() Vector4Float; | ||
| 978 | |||
| 979 | test "float simd vectors" { | ||
| 980 | if (builtin.cpu.arch == .powerpc or builtin.cpu.arch == .powerpc64le) return error.SkipZigTest; | ||
| 981 | |||
| 982 | { | ||
| 983 | c_vector_2_float(.{ 1.0, 2.0 }); | ||
| 984 | const vec = c_ret_vector_2_float(); | ||
| 985 | try expect(vec[0] == 1.0); | ||
| 986 | try expect(vec[1] == 2.0); | ||
| 987 | } | ||
| 988 | { | ||
| 989 | c_vector_4_float(.{ 1.0, 2.0, 3.0, 4.0 }); | ||
| 990 | const vec = c_ret_vector_4_float(); | ||
| 991 | try expect(vec[0] == 1.0); | ||
| 992 | try expect(vec[1] == 2.0); | ||
| 993 | try expect(vec[2] == 3.0); | ||
| 994 | try expect(vec[3] == 4.0); | ||
| 995 | } | ||
| 996 | } | ||
| 997 | |||
| 970 | const Vector2Bool = @Vector(2, bool); | 998 | const Vector2Bool = @Vector(2, bool); |
| 971 | const Vector4Bool = @Vector(4, bool); | 999 | const Vector4Bool = @Vector(4, bool); |
| 972 | const Vector8Bool = @Vector(8, bool); | 1000 | const Vector8Bool = @Vector(8, bool); |
| ... | @@ -998,7 +1026,7 @@ extern fn c_ret_vector_256_bool() Vector256Bool; | ... | @@ -998,7 +1026,7 @@ extern fn c_ret_vector_256_bool() Vector256Bool; |
| 998 | extern fn c_ret_vector_512_bool() Vector512Bool; | 1026 | extern fn c_ret_vector_512_bool() Vector512Bool; |
| 999 | 1027 | ||
| 1000 | test "bool simd vector" { | 1028 | test "bool simd vector" { |
| 1001 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch != .powerpc) return error.SkipZigTest; | 1029 | if (builtin.zig_backend == .stage2_llvm and (builtin.cpu.arch != .powerpc and builtin.cpu.arch != .wasm32)) return error.SkipZigTest; |
| 1002 | 1030 | ||
| 1003 | { | 1031 | { |
| 1004 | c_vector_2_bool(.{ | 1032 | c_vector_2_bool(.{ |
| ... | @@ -1550,8 +1578,9 @@ test "bool simd vector" { | ... | @@ -1550,8 +1578,9 @@ test "bool simd vector" { |
| 1550 | try expect(vec[126] == false); | 1578 | try expect(vec[126] == false); |
| 1551 | try expect(vec[127] == true); | 1579 | try expect(vec[127] == true); |
| 1552 | } | 1580 | } |
| 1581 | |||
| 1553 | { | 1582 | { |
| 1554 | c_vector_256_bool(.{ | 1583 | if (builtin.target.cpu.arch != .wasm32) c_vector_256_bool(.{ |
| 1555 | false, | 1584 | false, |
| 1556 | true, | 1585 | true, |
| 1557 | true, | 1586 | true, |
| ... | @@ -2069,7 +2098,7 @@ test "bool simd vector" { | ... | @@ -2069,7 +2098,7 @@ test "bool simd vector" { |
| 2069 | try expect(vec[255] == false); | 2098 | try expect(vec[255] == false); |
| 2070 | } | 2099 | } |
| 2071 | { | 2100 | { |
| 2072 | c_vector_512_bool(.{ | 2101 | if (builtin.target.cpu.arch != .wasm32) c_vector_512_bool(.{ |
| 2073 | true, | 2102 | true, |
| 2074 | true, | 2103 | true, |
| 2075 | true, | 2104 | true, |
| ... | @@ -3102,7 +3131,6 @@ test "bool simd vector" { | ... | @@ -3102,7 +3131,6 @@ test "bool simd vector" { |
| 3102 | 3131 | ||
| 3103 | comptime { | 3132 | comptime { |
| 3104 | skip: { | 3133 | skip: { |
| 3105 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) break :skip; | ||
| 3106 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .x86_64) break :skip; | 3134 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .x86_64) break :skip; |
| 3107 | 3135 | ||
| 3108 | _ = struct { | 3136 | _ = struct { |