From 20ba50f04634dd38f002594213e0910a992294d6 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 21 Apr 2022 19:47:17 -0700 Subject: [PATCH] convert mulmnu.c tests to be easier to understand --- openpower/sv/biginteger/mulmnu.c | 50 +++++++++++++++----------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/openpower/sv/biginteger/mulmnu.c b/openpower/sv/biginteger/mulmnu.c index 0326a154d..c1a9480c3 100644 --- a/openpower/sv/biginteger/mulmnu.c +++ b/openpower/sv/biginteger/mulmnu.c @@ -77,41 +77,39 @@ void check(unsigned short result[], unsigned short u[], unsigned short v[], int main() { - static unsigned short test[] = { + static struct + { + int m, n; + unsigned short u[4], v[4], correct[8]; + } test[] = { // clang-format off - // m, n, u ..., v ..., result. - 1, 1, 7, 3, 21,0, - 1, 1, 2, 0xFFFF, 0xFFFE,0x0001, // 2*FFFF = 0001_FFFE. - 1, 1, 0xFFFF, 0xFFFF, 1,0xFFFE, - 1, 2, 7, 5, 6, 35,42,0, - 1, 2, 65000, 63000, 64000, 0xBDC0,0x8414,0xF7F5, - 1, 3, 65535, 31000, 32000, 33000, 0x86E8,0xFC17,0xFC17,0x80E7, - 2, 3, 400, 300, 500, 100, 200, 0x0D40,0xE633,0xADB2,0xEA61,0, - 2, 3, 400, 65535, 500, 100, 65534, 0x0D40,0x9A4F,0xFE70,0x01F5,0xFFFD, - 4, 4, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 1, 0, 0, 0, 65534, 65535, 65535, 65535, - 2, 2, 0xFF00,0xFF00, 0xFF00,0xFF00, 0,0xfe01,0xfc02,0xfe02 + {.m=1, .n=1, .u={7}, .v={3}, .correct={21, 0}}, + {.m=1, .n=1, .u={2}, .v={0xFFFF}, .correct={0xFFFE, 0x0001}}, // 2*FFFF = 0001_FFFE. + {.m=1, .n=1, .u={0xFFFF}, .v={0xFFFF}, .correct={1, 0xFFFE}}, + {.m=1, .n=2, .u={7}, .v={5, 6}, .correct={35, 42, 0}}, + {.m=1, .n=2, .u={65000}, .v={63000, 64000}, .correct={0xBDC0, 0x8414, 0xF7F5}}, + {.m=1, .n=3, .u={65535}, .v={31000, 32000, 33000}, .correct={0x86E8, 0xFC17, 0xFC17, 0x80E7}}, + {.m=2, .n=3, .u={400, 300}, .v={500, 100, 200}, .correct={0x0D40, 0xE633, 0xADB2, 0xEA61, 0}}, + {.m=2, .n=3, .u={400, 65535}, .v={500, 100, 65534}, .correct={0x0D40, 0x9A4F, 0xFE70, 0x01F5, 0xFFFD}}, + {.m=4, .n=4, .u={65535, 65535, 65535, 65535}, .v={65535, 65535, 65535, 65535}, + .correct={1, 0, 0, 0, 65534, 65535, 65535, 65535}}, + {.m=2, .n=2, .u={0xFF00, 0xFF00}, .v={0xFF00, 0xFF00}, .correct={0, 0xfe01, 0xfc02, 0xfe02}}, // clang-format on }; - int i, n, m, ncases; + const int ncases = sizeof(test) / sizeof(test[0]); unsigned short result[10]; - unsigned short *u, *v; printf("mulmnu:\n"); - i = 0; - ncases = 0; - while (i < sizeof(test) / 2) + for (int i = 0; i < ncases; i++) { - m = test[i]; - n = test[i + 1]; - u = &test[i + 2]; - v = &test[i + 2 + m]; + int m = test[i].m, n = test[i].n; + unsigned short *u = test[i].u; + unsigned short *v = test[i].v; + unsigned short *correct = test[i].correct; mulmnu(result, u, v, m, n); - check(result, u, v, m, n, &test[i + 2 + m + n]); + check(result, u, v, m, n, correct); mulmnu(result, v, u, n, m); // Interchange operands. - check(result, v, u, n, m, &test[i + 2 + m + n]); - i = i + 2 + 2 * (m + n); - ncases = ncases + 1; + check(result, v, u, n, m, correct); } if (errors == 0) -- 2.30.2