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) {...@@ -12,6 +12,10 @@ static void assert_or_panic(bool ok) {
12 }12 }
13}13}
1414
15#if defined __powerpc__ && !defined _ARCH_PPC64
16# define ZIG_PPC32
17#endif
18
15#ifdef __i386__19#ifdef __i386__
16# define ZIG_NO_I12820# define ZIG_NO_I128
17#endif21#endif
...@@ -24,6 +28,10 @@ static void assert_or_panic(bool ok) {...@@ -24,6 +28,10 @@ static void assert_or_panic(bool ok) {
24# define ZIG_NO_I12828# define ZIG_NO_I128
25#endif29#endif
2630
31#ifdef ZIG_PPC32
32# define ZIG_NO_I128
33#endif
34
27#ifdef __i386__35#ifdef __i386__
28# define ZIG_NO_COMPLEX36# define ZIG_NO_COMPLEX
29#endif37#endif
...@@ -36,6 +44,10 @@ static void assert_or_panic(bool ok) {...@@ -36,6 +44,10 @@ static void assert_or_panic(bool ok) {
36# define ZIG_NO_COMPLEX44# define ZIG_NO_COMPLEX
37#endif45#endif
3846
47#ifdef __powerpc__
48# define ZIG_NO_COMPLEX
49#endif
50
39#ifndef ZIG_NO_I12851#ifndef ZIG_NO_I128
40struct i128 {52struct i128 {
41 __int128 value;53 __int128 value;
...@@ -253,14 +265,15 @@ void run_c_tests(void) {...@@ -253,14 +265,15 @@ void run_c_tests(void) {
253 }265 }
254#endif266#endif
255267
256#if !defined __mips__ && !defined __riscv268#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
257 {269 {
258 struct BigStruct s = {1, 2, 3, 4, 5};270 struct BigStruct s = {1, 2, 3, 4, 5};
259 zig_big_struct(s);271 zig_big_struct(s);
260 }272 }
261#endif273#endif
262274
263#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv275#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
276 !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
264 {277 {
265 struct SmallStructInts s = {1, 2, 3, 4};278 struct SmallStructInts s = {1, 2, 3, 4};
266 zig_small_struct_ints(s);279 zig_small_struct_ints(s);
...@@ -285,28 +298,30 @@ void run_c_tests(void) {...@@ -285,28 +298,30 @@ void run_c_tests(void) {
285 zig_small_packed_struct(s);298 zig_small_packed_struct(s);
286 }299 }
287300
288#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv301#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
302 !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
289 {303 {
290 struct SplitStructInts s = {1234, 100, 1337};304 struct SplitStructInts s = {1234, 100, 1337};
291 zig_split_struct_ints(s);305 zig_split_struct_ints(s);
292 }306 }
293#endif307#endif
294308
295#if !defined __arm__ && !defined __riscv309#if !defined __arm__ && !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
296 {310 {
297 struct MedStructMixed s = {1234, 100.0f, 1337.0f};311 struct MedStructMixed s = {1234, 100.0f, 1337.0f};
298 zig_med_struct_mixed(s);312 zig_med_struct_mixed(s);
299 }313 }
300#endif314#endif
301315
302#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv316#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
317 !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
303 {318 {
304 struct SplitStructMixed s = {1234, 100, 1337.0f};319 struct SplitStructMixed s = {1234, 100, 1337.0f};
305 zig_split_struct_mixed(s);320 zig_split_struct_mixed(s);
306 }321 }
307#endif322#endif
308323
309#if !defined __mips__ && !defined __riscv324#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
310 {325 {
311 struct BigStruct s = {30, 31, 32, 33, 34};326 struct BigStruct s = {30, 31, 32, 33, 34};
312 struct BigStruct res = zig_big_struct_both(s);327 struct BigStruct res = zig_big_struct_both(s);
...@@ -318,7 +333,7 @@ void run_c_tests(void) {...@@ -318,7 +333,7 @@ void run_c_tests(void) {
318 }333 }
319#endif334#endif
320335
321#ifndef __riscv336#if !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
322 {337 {
323 struct Rect r1 = {1, 21, 16, 4};338 struct Rect r1 = {1, 21, 16, 4};
324 struct Rect r2 = {178, 189, 21, 15};339 struct Rect r2 = {178, 189, 21, 15};
...@@ -326,7 +341,7 @@ void run_c_tests(void) {...@@ -326,7 +341,7 @@ void run_c_tests(void) {
326 }341 }
327#endif342#endif
328343
329#if !defined __mips__ && !defined __riscv344#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
330 {345 {
331 struct FloatRect r1 = {1, 21, 16, 4};346 struct FloatRect r1 = {1, 21, 16, 4};
332 struct FloatRect r2 = {178, 189, 21, 15};347 struct FloatRect r2 = {178, 189, 21, 15};
test/c_abi/main.zig+27-2
...@@ -3,7 +3,7 @@ const builtin = @import("builtin");...@@ -3,7 +3,7 @@ const builtin = @import("builtin");
3const print = std.debug.print;3const print = std.debug.print;
4const expect = std.testing.expect;4const expect = std.testing.expect;
5const has_i128 = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isARM() and5const 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
8extern fn run_c_tests() void;8extern fn run_c_tests() void;
99
...@@ -112,6 +112,9 @@ test "C ABI floats" {...@@ -112,6 +112,9 @@ test "C ABI floats" {
112}112}
113113
114test "C ABI long double" {114test "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
115 c_long_double(12.34);118 c_long_double(12.34);
116}119}
117120
...@@ -168,7 +171,7 @@ extern fn c_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat;...@@ -168,7 +171,7 @@ extern fn c_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat;
168extern fn c_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble;171extern fn c_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble;
169172
170const complex_abi_compatible = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isMIPS() and173const 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
173test "C ABI complex float" {176test "C ABI complex float" {
174 if (!complex_abi_compatible) return error.SkipZigTest;177 if (!complex_abi_compatible) return error.SkipZigTest;
...@@ -263,6 +266,7 @@ extern fn c_big_struct(BigStruct) void;...@@ -263,6 +266,7 @@ extern fn c_big_struct(BigStruct) void;
263test "C ABI big struct" {266test "C ABI big struct" {
264 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;267 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
265 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;268 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
269 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
266270
267 var s = BigStruct{271 var s = BigStruct{
268 .a = 1,272 .a = 1,
...@@ -289,6 +293,7 @@ extern fn c_big_union(BigUnion) void;...@@ -289,6 +293,7 @@ extern fn c_big_union(BigUnion) void;
289293
290test "C ABI big union" {294test "C ABI big union" {
291 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;295 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
296 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
292297
293 var x = BigUnion{298 var x = BigUnion{
294 .a = BigStruct{299 .a = BigStruct{
...@@ -323,6 +328,8 @@ test "C ABI medium struct of ints and floats" {...@@ -323,6 +328,8 @@ test "C ABI medium struct of ints and floats" {
323 if (builtin.cpu.arch == .i386) return error.SkipZigTest;328 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
324 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;329 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
325 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;330 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
327 var s = MedStructMixed{334 var s = MedStructMixed{
328 .a = 1234,335 .a = 1234,
...@@ -355,6 +362,8 @@ test "C ABI small struct of ints" {...@@ -355,6 +362,8 @@ test "C ABI small struct of ints" {
355 if (builtin.cpu.arch == .i386) return error.SkipZigTest;362 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
356 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;363 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
357 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;364 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
359 var s = SmallStructInts{368 var s = SmallStructInts{
360 .a = 1,369 .a = 1,
...@@ -436,6 +445,8 @@ test "C ABI split struct of ints" {...@@ -436,6 +445,8 @@ test "C ABI split struct of ints" {
436 if (builtin.cpu.arch == .i386) return error.SkipZigTest;445 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
437 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;446 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
438 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;447 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
440 var s = SplitStructInt{451 var s = SplitStructInt{
441 .a = 1234,452 .a = 1234,
...@@ -463,6 +474,8 @@ test "C ABI split struct of ints and floats" {...@@ -463,6 +474,8 @@ test "C ABI split struct of ints and floats" {
463 if (builtin.cpu.arch == .i386) return error.SkipZigTest;474 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
464 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;475 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
465 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;476 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
467 var s = SplitStructMixed{480 var s = SplitStructMixed{
468 .a = 1234,481 .a = 1234,
...@@ -490,6 +503,7 @@ extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;...@@ -490,6 +503,7 @@ extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;
490test "C ABI sret and byval together" {503test "C ABI sret and byval together" {
491 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;504 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
492 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;505 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
506 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
493507
494 var s = BigStruct{508 var s = BigStruct{
495 .a = 1,509 .a = 1,
...@@ -542,6 +556,8 @@ extern fn c_big_struct_floats(Vector5) void;...@@ -542,6 +556,8 @@ extern fn c_big_struct_floats(Vector5) void;
542test "C ABI structs of floats as parameter" {556test "C ABI structs of floats as parameter" {
543 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;557 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
544 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;558 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
546 var v3 = Vector3{562 var v3 = Vector3{
547 .x = 3.0,563 .x = 3.0,
...@@ -581,6 +597,8 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {...@@ -581,6 +597,8 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {
581597
582test "C ABI structs of ints as multiple parameters" {598test "C ABI structs of ints as multiple parameters" {
583 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;599 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
585 var r1 = Rect{603 var r1 = Rect{
586 .left = 1,604 .left = 1,
...@@ -618,6 +636,7 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {...@@ -618,6 +636,7 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
618test "C ABI structs of floats as multiple parameters" {636test "C ABI structs of floats as multiple parameters" {
619 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;637 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
620 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;638 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
639 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
621640
622 var r1 = FloatRect{641 var r1 = FloatRect{
623 .left = 1,642 .left = 1,
...@@ -723,6 +742,8 @@ test "Struct with array as padding." {...@@ -723,6 +742,8 @@ test "Struct with array as padding." {
723 if (builtin.cpu.arch == .i386) return error.SkipZigTest;742 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
724 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;743 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
725 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;744 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
727 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });748 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
728749
...@@ -748,6 +769,7 @@ extern fn c_ret_float_array_struct() FloatArrayStruct;...@@ -748,6 +769,7 @@ extern fn c_ret_float_array_struct() FloatArrayStruct;
748test "Float array like struct" {769test "Float array like struct" {
749 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;770 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
750 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;771 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
772 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
751773
752 c_float_array_struct(.{774 c_float_array_struct(.{
753 .origin = .{775 .origin = .{
...@@ -775,6 +797,7 @@ extern fn c_ret_small_vec() SmallVec;...@@ -775,6 +797,7 @@ extern fn c_ret_small_vec() SmallVec;
775test "small simd vector" {797test "small simd vector" {
776 if (builtin.cpu.arch == .i386) return error.SkipZigTest;798 if (builtin.cpu.arch == .i386) return error.SkipZigTest;
777 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;799 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
800 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
778801
779 c_small_vec(.{ 1, 2 });802 c_small_vec(.{ 1, 2 });
780803
...@@ -789,6 +812,8 @@ extern fn c_big_vec(BigVec) void;...@@ -789,6 +812,8 @@ extern fn c_big_vec(BigVec) void;
789extern fn c_ret_big_vec() BigVec;812extern fn c_ret_big_vec() BigVec;
790813
791test "big simd vector" {814test "big simd vector" {
815 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
816
792 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });817 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });
793818
794 var x = c_ret_big_vec();819 var x = c_ret_big_vec();