diff options
author | Richard Henderson <rth@twiddle.net> | 2013-02-16 12:47:01 -0800 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2013-02-17 14:28:58 +0000 |
commit | f4c0f986c061f34fd5b020c30e2aa8c37e17193b (patch) | |
tree | be64da62104e1d9b3096db65b669497f07659c9b /tests/test-mul64.c | |
parent | ff7a1eb0a1262f7d451cc1e70c65dd23771ce2a2 (diff) | |
download | qemu-f4c0f986c061f34fd5b020c30e2aa8c37e17193b.zip qemu-f4c0f986c061f34fd5b020c30e2aa8c37e17193b.tar.gz qemu-f4c0f986c061f34fd5b020c30e2aa8c37e17193b.tar.bz2 |
tests: Add unit tests for mulu64 and muls64
Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'tests/test-mul64.c')
-rw-r--r-- | tests/test-mul64.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test-mul64.c b/tests/test-mul64.c new file mode 100644 index 0000000..a0a17f7 --- /dev/null +++ b/tests/test-mul64.c @@ -0,0 +1,70 @@ +/* + * Test 64x64 -> 128 multiply subroutines + * + * This work is licensed under the terms of the GNU LGPL, version 2 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include <glib.h> +#include <stdint.h> +#include "qemu/host-utils.h" +#include "qemu/osdep.h" + + +typedef struct { + uint64_t a, b; + uint64_t rh, rl; +} Test; + +static const Test test_u_data[] = { + { 1, 1, 0, 1 }, + { 10000, 10000, 0, 100000000 }, + { 0xffffffffffffffffULL, 2, 1, 0xfffffffffffffffeULL }, + { 0xffffffffffffffffULL, 0xffffffffffffffffULL, + 0xfffffffffffffffeULL, 0x0000000000000001ULL }, + { 0x1122334455667788ull, 0x8877665544332211ull, + 0x092228fb777ae38full, 0x0a3e963337c60008ull }, +}; + +static const Test test_s_data[] = { + { 1, 1, 0, 1 }, + { 1, -1, -1, -1 }, + { -10, -10, 0, 100 }, + { 10000, 10000, 0, 100000000 }, + { -1, 2, -1, -2 }, + { 0x1122334455667788ULL, 0x1122334455667788ULL, + 0x01258f60bbc2975cULL, 0x1eace4a3c82fb840ULL }, +}; + +static void test_u(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) { + uint64_t rl, rh; + mulu64(&rl, &rh, test_u_data[i].a, test_u_data[i].b); + g_assert_cmpuint(rl, ==, test_u_data[i].rl); + g_assert_cmpuint(rh, ==, test_u_data[i].rh); + } +} + +static void test_s(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_s_data); ++i) { + uint64_t rl, rh; + muls64(&rl, &rh, test_s_data[i].a, test_s_data[i].b); + g_assert_cmpuint(rl, ==, test_s_data[i].rl); + g_assert_cmpint(rh, ==, test_s_data[i].rh); + } +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/host-utils/mulu64", test_u); + g_test_add_func("/host-utils/muls64", test_s); + return g_test_run(); +} |