From ea0b3b5a6242b3e56341680a2a333f944e6c1967 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 22 Sep 2025 14:47:49 +0200 Subject: [PATCH 21/23] C11 anonymous unions [testint128] --- src/test/modules/test_int128/test_int128.c | 108 ++++++++++----------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/test/modules/test_int128/test_int128.c b/src/test/modules/test_int128/test_int128.c index c9c17a73a4e..b6053efaf24 100644 --- a/src/test/modules/test_int128/test_int128.c +++ b/src/test/modules/test_int128/test_int128.c @@ -50,7 +50,7 @@ typedef union uint64 lo; int64 hi; #endif - } hl; + }; } test128; #define INT128_HEX_FORMAT "%016" PRIx64 "%016" PRIx64 @@ -102,140 +102,140 @@ main(int argc, char **argv) int32 r2; /* check unsigned addition */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; t1.i128 += (int128) (uint64) z; int128_add_uint64(&t2.I128, (uint64) z); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " + unsigned %016" PRIx64 "\n", x, y, z); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check signed addition */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; t1.i128 += (int128) z; int128_add_int64(&t2.I128, z); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " + signed %016" PRIx64 "\n", x, y, z); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check 128-bit signed addition */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; - t3.hl.hi = z; - t3.hl.lo = w; + t3.hi = z; + t3.lo = w; t1.i128 += t3.i128; int128_add_int128(&t2.I128, t3.I128); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " + " INT128_HEX_FORMAT "\n", x, y, z, w); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check unsigned subtraction */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; t1.i128 -= (int128) (uint64) z; int128_sub_uint64(&t2.I128, (uint64) z); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " - unsigned %016" PRIx64 "\n", x, y, z); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check signed subtraction */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; t1.i128 -= (int128) z; int128_sub_int64(&t2.I128, z); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " - signed %016" PRIx64 "\n", x, y, z); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check 64x64-bit multiply-add */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; t1.i128 += (int128) z * (int128) w; int128_add_int64_mul_int64(&t2.I128, z, w); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " + %016" PRIx64 " * %016" PRIx64 "\n", x, y, z, w); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check 64x64-bit multiply-subtract */ - t1.hl.hi = x; - t1.hl.lo = y; + t1.hi = x; + t1.lo = y; t2 = t1; t1.i128 -= (int128) z * (int128) w; int128_sub_int64_mul_int64(&t2.I128, z, w); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { printf(INT128_HEX_FORMAT " - %016" PRIx64 " * %016" PRIx64 "\n", x, y, z, w); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check 128/32-bit division */ - t3.hl.hi = x; - t3.hl.lo = y; + t3.hi = x; + t3.lo = y; t1.i128 = t3.i128 / z32; r1 = (int32) (t3.i128 % z32); t2 = t3; int128_div_mod_int32(&t2.I128, z32, &r2); - if (t1.hl.hi != t2.hl.hi || t1.hl.lo != t2.hl.lo) + if (t1.hi != t2.hi || t1.lo != t2.lo) { - printf(INT128_HEX_FORMAT " / signed %08X\n", t3.hl.hi, t3.hl.lo, z32); - printf("native = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("result = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf(INT128_HEX_FORMAT " / signed %08X\n", t3.hi, t3.lo, z32); + printf("native = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("result = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } if (r1 != r2) { - printf(INT128_HEX_FORMAT " %% signed %08X\n", t3.hl.hi, t3.hl.lo, z32); + printf(INT128_HEX_FORMAT " %% signed %08X\n", t3.hi, t3.lo, z32); printf("native = %08X\n", r1); printf("result = %08X\n", r2); return 1; } /* check comparison */ - t1.hl.hi = x; - t1.hl.lo = y; - t2.hl.hi = z; - t2.hl.lo = w; + t1.hi = x; + t1.lo = y; + t2.hi = z; + t2.lo = w; if (my_int128_compare(t1.i128, t2.i128) != int128_compare(t1.I128, t2.I128)) @@ -243,13 +243,13 @@ main(int argc, char **argv) printf("comparison failure: %d vs %d\n", my_int128_compare(t1.i128, t2.i128), int128_compare(t1.I128, t2.I128)); - printf("arg1 = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("arg2 = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("arg1 = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("arg2 = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } /* check case with identical hi parts; above will hardly ever hit it */ - t2.hl.hi = x; + t2.hi = x; if (my_int128_compare(t1.i128, t2.i128) != int128_compare(t1.I128, t2.I128)) @@ -257,8 +257,8 @@ main(int argc, char **argv) printf("comparison failure: %d vs %d\n", my_int128_compare(t1.i128, t2.i128), int128_compare(t1.I128, t2.I128)); - printf("arg1 = " INT128_HEX_FORMAT "\n", t1.hl.hi, t1.hl.lo); - printf("arg2 = " INT128_HEX_FORMAT "\n", t2.hl.hi, t2.hl.lo); + printf("arg1 = " INT128_HEX_FORMAT "\n", t1.hi, t1.lo); + printf("arg2 = " INT128_HEX_FORMAT "\n", t2.hi, t2.lo); return 1; } } -- 2.51.0