soc/amd/sabrina,vc/amd/fsp/sabrina: Add UART support for Sabrina
[coreboot.git] / tests / lib / libgcc-test.c
blob1a567e91c00e12305fd4f0570c29889f710ae477
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include "../lib/libgcc.c"
5 #include <tests/test.h>
6 #include <stdlib.h>
7 #include <string.h>
9 struct {
10 u32 value;
11 int expected_output;
12 } test_data[] = {
13 /* GCC documentation says, __clzsi2() has undefined result for zero as an input value,
14 but coreboot implementation can handle this. */
15 {.value = 0, .expected_output = 32},
17 {.value = 1, .expected_output = 31},
18 {.value = 2, .expected_output = 30},
19 {.value = 3, .expected_output = 30},
20 {.value = 4, .expected_output = 29},
21 {.value = 5, .expected_output = 29},
22 {.value = 6, .expected_output = 29},
23 {.value = 7, .expected_output = 29},
25 {.value = 0xF, .expected_output = 28},
26 {.value = 0x10, .expected_output = 27},
27 {.value = 0x25, .expected_output = 26},
28 {.value = 0x5D, .expected_output = 25},
29 {.value = 0xB7, .expected_output = 24},
31 {.value = 0x133, .expected_output = 23},
32 {.value = 0x3DC, .expected_output = 22},
33 {.value = 0x6F1, .expected_output = 21},
34 {.value = 0x897, .expected_output = 20},
36 {.value = 0x1FFF, .expected_output = 19},
37 {.value = 0x2222, .expected_output = 18},
38 {.value = 0x7BAD, .expected_output = 17},
39 {.value = 0xE708, .expected_output = 16},
41 {.value = 0x1DABD, .expected_output = 15},
42 {.value = 0x29876, .expected_output = 14},
43 {.value = 0x56665, .expected_output = 13},
44 {.value = 0xABCDE, .expected_output = 12},
46 {.value = 0x18365F, .expected_output = 11},
47 {.value = 0x3D0115, .expected_output = 10},
48 {.value = 0x4B07EB, .expected_output = 9},
49 {.value = 0xCCC74D, .expected_output = 8},
51 {.value = 0x17933ED, .expected_output = 7},
52 {.value = 0x2B00071, .expected_output = 6},
53 {.value = 0x4D4C1A5, .expected_output = 5},
54 {.value = 0xAD01FFF, .expected_output = 4},
56 {.value = 0x1C5A8057, .expected_output = 3},
57 {.value = 0x35AB23C3, .expected_output = 2},
58 {.value = 0x7017013B, .expected_output = 1},
59 {.value = 0xAD01EB15, .expected_output = 0},
61 {.value = 0xFFFFFFFF, .expected_output = 0},
62 {.value = 0x80000000, .expected_output = 0},
63 {.value = 0x7FFFFFFF, .expected_output = 1},
64 {.value = 0x30000000, .expected_output = 2},
65 {.value = 0x10000000, .expected_output = 3},
66 {.value = 0x0FFFFFFF, .expected_output = 4},
68 {.value = 0xFF000000, .expected_output = 0},
69 {.value = 0x00FF0000, .expected_output = 8},
70 {.value = 0x0000FF00, .expected_output = 16},
71 {.value = 0x000000FF, .expected_output = 24},
73 {.value = 0x8F000000, .expected_output = 0},
74 {.value = 0x008F0000, .expected_output = 8},
75 {.value = 0x00008F00, .expected_output = 16},
76 {.value = 0x0000008F, .expected_output = 24},
78 {.value = 0x7F000000, .expected_output = 1},
79 {.value = 0x007F0000, .expected_output = 9},
80 {.value = 0x00007F00, .expected_output = 17},
81 {.value = 0x0000007F, .expected_output = 25},
83 {.value = 0x3F000000, .expected_output = 2},
84 {.value = 0x003F0000, .expected_output = 10},
85 {.value = 0x00003F00, .expected_output = 18},
86 {.value = 0x0000003F, .expected_output = 26},
88 {.value = 0x1F000000, .expected_output = 3},
89 {.value = 0x001F0000, .expected_output = 11},
90 {.value = 0x00001F00, .expected_output = 19},
91 {.value = 0x0000001F, .expected_output = 27},
93 {.value = 0x0F000000, .expected_output = 4},
94 {.value = 0x000F0000, .expected_output = 12},
95 {.value = 0x00000F00, .expected_output = 20},
96 {.value = 0x0000000F, .expected_output = 28},
98 {.value = 0x08000000, .expected_output = 4},
99 {.value = 0x00080000, .expected_output = 12},
100 {.value = 0x00000800, .expected_output = 20},
101 {.value = 0x00000008, .expected_output = 28},
103 {.value = 0x07000000, .expected_output = 5},
104 {.value = 0x00070000, .expected_output = 13},
105 {.value = 0x00000700, .expected_output = 21},
106 {.value = 0x00000007, .expected_output = 29},
108 {.value = 0x03000000, .expected_output = 6},
109 {.value = 0x00030000, .expected_output = 14},
110 {.value = 0x00000300, .expected_output = 22},
111 {.value = 0x00000003, .expected_output = 30},
113 {.value = 0x01000000, .expected_output = 7},
114 {.value = 0x00010000, .expected_output = 15},
115 {.value = 0x00000100, .expected_output = 23},
116 {.value = 0x00000001, .expected_output = 31},
119 void test_clzsi2_with_data(void **state)
121 for (int i = 0; i < ARRAY_SIZE(test_data); ++i)
122 assert_int_equal(test_data[i].expected_output, __clzsi2(test_data[i].value));
125 int main(void)
127 const struct CMUnitTest tests[] = {
128 cmocka_unit_test(test_clzsi2_with_data),
131 return cb_run_group_tests(tests, NULL, NULL);