]> git.proxmox.com Git - mirror_qemu.git/blob - tests/test-mul64.c
Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20200407' into staging
[mirror_qemu.git] / tests / test-mul64.c
1 /*
2 * Test 64x64 -> 128 multiply subroutines
3 *
4 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
5 * See the COPYING.LIB file in the top-level directory.
6 *
7 */
8
9 #include "qemu/osdep.h"
10 #include "qemu/host-utils.h"
11
12
13 typedef struct {
14 uint64_t a, b;
15 uint64_t rh, rl;
16 } Test;
17
18 static const Test test_u_data[] = {
19 { 1, 1, 0, 1 },
20 { 10000, 10000, 0, 100000000 },
21 { 0xffffffffffffffffULL, 2, 1, 0xfffffffffffffffeULL },
22 { 0xffffffffffffffffULL, 0xffffffffffffffffULL,
23 0xfffffffffffffffeULL, 0x0000000000000001ULL },
24 { 0x1122334455667788ull, 0x8877665544332211ull,
25 0x092228fb777ae38full, 0x0a3e963337c60008ull },
26 };
27
28 static const Test test_s_data[] = {
29 { 1, 1, 0, 1 },
30 { 1, -1, -1, -1 },
31 { -10, -10, 0, 100 },
32 { 10000, 10000, 0, 100000000 },
33 { -1, 2, -1, -2 },
34 { 0x1122334455667788ULL, 0x1122334455667788ULL,
35 0x01258f60bbc2975cULL, 0x1eace4a3c82fb840ULL },
36 };
37
38 static void test_u(void)
39 {
40 int i;
41
42 for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) {
43 uint64_t rl, rh;
44 mulu64(&rl, &rh, test_u_data[i].a, test_u_data[i].b);
45 g_assert_cmpuint(rl, ==, test_u_data[i].rl);
46 g_assert_cmpuint(rh, ==, test_u_data[i].rh);
47 }
48 }
49
50 static void test_s(void)
51 {
52 int i;
53
54 for (i = 0; i < ARRAY_SIZE(test_s_data); ++i) {
55 uint64_t rl, rh;
56 muls64(&rl, &rh, test_s_data[i].a, test_s_data[i].b);
57 g_assert_cmpuint(rl, ==, test_s_data[i].rl);
58 g_assert_cmpint(rh, ==, test_s_data[i].rh);
59 }
60 }
61
62 int main(int argc, char **argv)
63 {
64 g_test_init(&argc, &argv, NULL);
65 g_test_add_func("/host-utils/mulu64", test_u);
66 g_test_add_func("/host-utils/muls64", test_s);
67 return g_test_run();
68 }