authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-21 23:00:49+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-22 11:31:41+03:00
log12a2ccfb459e89f6a59c14de36bf80bf51a0a517
tree4582e15c2be6b0b1d25176757eecaed7f24b5aea
parent031c768cc8399ccdf5440df87d37c03a238315d5

make C ABI tests compile on powerpc


2 files changed, 50 insertions(+), 10 deletions(-)

test/c_abi/cfuncs.c+23-8
......@@ -12,6 +12,10 @@ static void assert_or_panic(bool ok) {
1212 }
1313}
1414
15#if defined __powerpc__ && !defined _ARCH_PPC64
16# define ZIG_PPC32
17#endif
18
1519#ifdef __i386__
1620# define ZIG_NO_I128
1721#endif
......@@ -24,6 +28,10 @@ static void assert_or_panic(bool ok) {
2428# define ZIG_NO_I128
2529#endif
2630
31#ifdef ZIG_PPC32
32# define ZIG_NO_I128
33#endif
34
2735#ifdef __i386__
2836# define ZIG_NO_COMPLEX
2937#endif
......@@ -36,6 +44,10 @@ static void assert_or_panic(bool ok) {
3644# define ZIG_NO_COMPLEX
3745#endif
3846
47#ifdef __powerpc__
48# define ZIG_NO_COMPLEX
49#endif
50
3951#ifndef ZIG_NO_I128
4052struct i128 {
4153 __int128 value;
......@@ -253,14 +265,15 @@ void run_c_tests(void) {
253265 }
254266#endif
255267
256#if !defined __mips__ && !defined __riscv
268#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
257269 {
258270 struct BigStruct s = {1, 2, 3, 4, 5};
259271 zig_big_struct(s);
260272 }
261273#endif
262274
263#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
275#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
276 !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
264277 {
265278 struct SmallStructInts s = {1, 2, 3, 4};
266279 zig_small_struct_ints(s);
......@@ -285,28 +298,30 @@ void run_c_tests(void) {
285298 zig_small_packed_struct(s);
286299 }
287300
288#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
301#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
302 !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
289303 {
290304 struct SplitStructInts s = {1234, 100, 1337};
291305 zig_split_struct_ints(s);
292306 }
293307#endif
294308
295#if !defined __arm__ && !defined __riscv
309#if !defined __arm__ && !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
296310 {
297311 struct MedStructMixed s = {1234, 100.0f, 1337.0f};
298312 zig_med_struct_mixed(s);
299313 }
300314#endif
301315
302#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
316#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
317 !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
303318 {
304319 struct SplitStructMixed s = {1234, 100, 1337.0f};
305320 zig_split_struct_mixed(s);
306321 }
307322#endif
308323
309#if !defined __mips__ && !defined __riscv
324#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
310325 {
311326 struct BigStruct s = {30, 31, 32, 33, 34};
312327 struct BigStruct res = zig_big_struct_both(s);
......@@ -318,7 +333,7 @@ void run_c_tests(void) {
318333 }
319334#endif
320335
321#ifndef __riscv
336#if !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
322337 {
323338 struct Rect r1 = {1, 21, 16, 4};
324339 struct Rect r2 = {178, 189, 21, 15};
......@@ -326,7 +341,7 @@ void run_c_tests(void) {
326341 }
327342#endif
328343
329#if !defined __mips__ && !defined __riscv
344#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
330345 {
331346 struct FloatRect r1 = {1, 21, 16, 4};
332347 struct FloatRect r2 = {178, 189, 21, 15};
test/c_abi/main.zig+27-2
......@@ -3,7 +3,7 @@ const builtin = @import("builtin");
33const print = std.debug.print;
44const expect = std.testing.expect;
55const has_i128 = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isARM() and
6 !builtin.cpu.arch.isMIPS();
6 !builtin.cpu.arch.isMIPS() and !builtin.cpu.arch.isPPC();
77
88extern fn run_c_tests() void;
99
......@@ -112,6 +112,9 @@ test "C ABI floats" {
112112}
113113
114114test "C ABI long double" {
115 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
116 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
117
115118 c_long_double(12.34);
116119}
117120
......@@ -168,7 +171,7 @@ extern fn c_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat;
168171extern fn c_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble;
169172
170173const complex_abi_compatible = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isMIPS() and
171 !builtin.cpu.arch.isARM();
174 !builtin.cpu.arch.isARM() and !builtin.cpu.arch.isPPC();
172175
173176test "C ABI complex float" {
174177 if (!complex_abi_compatible) return error.SkipZigTest;
......@@ -263,6 +266,7 @@ extern fn c_big_struct(BigStruct) void;
263266test "C ABI big struct" {
264267 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
265268 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
269 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
266270
267271 var s = BigStruct{
268272 .a = 1,
......@@ -289,6 +293,7 @@ extern fn c_big_union(BigUnion) void;
289293
290294test "C ABI big union" {
291295 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
296 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
292297
293298 var x = BigUnion{
294299 .a = BigStruct{
......@@ -323,6 +328,8 @@ test "C ABI medium struct of ints and floats" {
323328 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
324329 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
325330 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
331 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
332 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
326333
327334 var s = MedStructMixed{
328335 .a = 1234,
......@@ -355,6 +362,8 @@ test "C ABI small struct of ints" {
355362 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
356363 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
357364 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
365 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
366 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
358367
359368 var s = SmallStructInts{
360369 .a = 1,
......@@ -436,6 +445,8 @@ test "C ABI split struct of ints" {
436445 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
437446 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
438447 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
448 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
449 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
439450
440451 var s = SplitStructInt{
441452 .a = 1234,
......@@ -463,6 +474,8 @@ test "C ABI split struct of ints and floats" {
463474 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
464475 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
465476 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
477 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
478 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
466479
467480 var s = SplitStructMixed{
468481 .a = 1234,
......@@ -490,6 +503,7 @@ extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;
490503test "C ABI sret and byval together" {
491504 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
492505 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
506 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
493507
494508 var s = BigStruct{
495509 .a = 1,
......@@ -542,6 +556,8 @@ extern fn c_big_struct_floats(Vector5) void;
542556test "C ABI structs of floats as parameter" {
543557 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
544558 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
559 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
560 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
545561
546562 var v3 = Vector3{
547563 .x = 3.0,
......@@ -581,6 +597,8 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {
581597
582598test "C ABI structs of ints as multiple parameters" {
583599 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
600 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
601 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
584602
585603 var r1 = Rect{
586604 .left = 1,
......@@ -618,6 +636,7 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
618636test "C ABI structs of floats as multiple parameters" {
619637 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
620638 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
639 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
621640
622641 var r1 = FloatRect{
623642 .left = 1,
......@@ -723,6 +742,8 @@ test "Struct with array as padding." {
723742 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
724743 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
725744 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
745 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
746 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
726747
727748 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
728749
......@@ -748,6 +769,7 @@ extern fn c_ret_float_array_struct() FloatArrayStruct;
748769test "Float array like struct" {
749770 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
750771 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
772 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
751773
752774 c_float_array_struct(.{
753775 .origin = .{
......@@ -775,6 +797,7 @@ extern fn c_ret_small_vec() SmallVec;
775797test "small simd vector" {
776798 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
777799 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
800 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
778801
779802 c_small_vec(.{ 1, 2 });
780803
......@@ -789,6 +812,8 @@ extern fn c_big_vec(BigVec) void;
789812extern fn c_ret_big_vec() BigVec;
790813
791814test "big simd vector" {
815 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
816
792817 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });
793818
794819 var x = c_ret_big_vec();