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