1
2
3
4
5
6
7
8
9
10
11
12#include <common.h>
13
14#include <post.h>
15
16GNU_FPOST_ATTR
17
18#if CONFIG_POST & CONFIG_SYS_POST_FPU
19
20union uf
21{
22 unsigned int u;
23 float f;
24};
25
26static float
27u2f (unsigned int v)
28{
29 union uf u;
30 u.u = v;
31 return u.f;
32}
33
34static unsigned int
35f2u (float v)
36{
37 union uf u;
38 u.f = v;
39 return u.u;
40}
41
42static int ok = 1;
43
44static void
45tstmul (unsigned int ux, unsigned int uy, unsigned int ur)
46{
47 float x = u2f (ux);
48 float y = u2f (uy);
49
50 if (f2u (x * y) != ur)
51
52
53 ok = 0;
54}
55
56
57
58struct
59{
60 unsigned int p1, p2, res;
61} static volatile expected[] =
62{
63 {0xfff, 0x3f800400, 0xfff},
64 {0xf, 0x3fc88888, 0x17},
65 {0xf, 0x3f844444, 0xf}
66};
67
68int fpu_post_test_math7 (void)
69{
70 unsigned int i;
71
72 for (i = 0; i < ARRAY_SIZE(expected); i++)
73 {
74 tstmul (expected[i].p1, expected[i].p2, expected[i].res);
75 tstmul (expected[i].p2, expected[i].p1, expected[i].res);
76 }
77
78 if (!ok) {
79 post_log ("Error in FPU math7 test\n");
80 return -1;
81 }
82 return 0;
83}
84
85#endif
86