arm: xlnx-zynqmp: Add xlnx-dp and xlnx-dpdma
[qemu/ar7.git] / tests / test-bitops.c
blobeb19a36a36cddb2a5e7f21910be122d5befecbd1
1 /*
2 * Test bitops routines
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.
7 */
9 #include "qemu/osdep.h"
10 #include "qemu/bitops.h"
12 typedef struct {
13 uint32_t value;
14 int start;
15 int length;
16 int32_t result;
17 } S32Test;
19 typedef struct {
20 uint64_t value;
21 int start;
22 int length;
23 int64_t result;
24 } S64Test;
26 static const S32Test test_s32_data[] = {
27 { 0x38463983, 4, 4, -8 },
28 { 0x38463983, 12, 8, 0x63 },
29 { 0x38463983, 0, 32, 0x38463983 },
32 static const S64Test test_s64_data[] = {
33 { 0x8459826734967223ULL, 60, 4, -8 },
34 { 0x8459826734967223ULL, 0, 64, 0x8459826734967223LL },
37 static void test_sextract32(void)
39 int i;
41 for (i = 0; i < ARRAY_SIZE(test_s32_data); i++) {
42 const S32Test *test = &test_s32_data[i];
43 int32_t r = sextract32(test->value, test->start, test->length);
45 g_assert_cmpint(r, ==, test->result);
49 static void test_sextract64(void)
51 int i;
53 for (i = 0; i < ARRAY_SIZE(test_s32_data); i++) {
54 const S32Test *test = &test_s32_data[i];
55 int64_t r = sextract64(test->value, test->start, test->length);
57 g_assert_cmpint(r, ==, test->result);
60 for (i = 0; i < ARRAY_SIZE(test_s64_data); i++) {
61 const S64Test *test = &test_s64_data[i];
62 int64_t r = sextract64(test->value, test->start, test->length);
64 g_assert_cmpint(r, ==, test->result);
68 int main(int argc, char **argv)
70 g_test_init(&argc, &argv, NULL);
71 g_test_add_func("/bitops/sextract32", test_sextract32);
72 g_test_add_func("/bitops/sextract64", test_sextract64);
73 return g_test_run();