]>
Commit | Line | Data |
---|---|---|
b4489621 SP |
1 | /* |
2 | * Copyright (C) 2007 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
5 | * See file CREDITS for list of people who contributed to this | |
6 | * project. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License as | |
10 | * published by the Free Software Foundation; either version 2 of | |
11 | * the License, or (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | * MA 02111-1307 USA | |
22 | */ | |
23 | /* | |
24 | * This file is originally a part of the GCC testsuite. | |
25 | * Check that certain subnormal numbers (formerly known as denormalized | |
26 | * numbers) are rounded to within 0.5 ulp. PR other/14354. | |
27 | */ | |
28 | ||
29 | #include <common.h> | |
30 | ||
b4489621 SP |
31 | #include <post.h> |
32 | ||
6d0f6bcf | 33 | #if CONFIG_POST & CONFIG_SYS_POST_FPU |
b4489621 SP |
34 | |
35 | union uf | |
36 | { | |
37 | unsigned int u; | |
38 | float f; | |
39 | }; | |
40 | ||
41 | static float | |
42 | u2f (unsigned int v) | |
43 | { | |
44 | union uf u; | |
45 | u.u = v; | |
46 | return u.f; | |
47 | } | |
48 | ||
49 | static unsigned int | |
50 | f2u (float v) | |
51 | { | |
52 | union uf u; | |
53 | u.f = v; | |
54 | return u.u; | |
55 | } | |
56 | ||
57 | static int ok = 1; | |
58 | ||
59 | static void | |
60 | tstmul (unsigned int ux, unsigned int uy, unsigned int ur) | |
61 | { | |
62 | float x = u2f (ux); | |
63 | float y = u2f (uy); | |
64 | ||
65 | if (f2u (x * y) != ur) | |
66 | /* Set a variable rather than aborting here, to simplify tracing when | |
67 | several computations are wrong. */ | |
68 | ok = 0; | |
69 | } | |
70 | ||
71 | /* We don't want to make this const and static, or else we risk inlining | |
72 | causing the test to fold as constants at compile-time. */ | |
73 | struct | |
74 | { | |
75 | unsigned int p1, p2, res; | |
76 | } static volatile expected[] = | |
77 | { | |
78 | {0xfff, 0x3f800400, 0xfff}, | |
79 | {0xf, 0x3fc88888, 0x17}, | |
80 | {0xf, 0x3f844444, 0xf} | |
81 | }; | |
82 | ||
83 | int fpu_post_test_math7 (void) | |
84 | { | |
85 | unsigned int i; | |
86 | ||
87 | for (i = 0; i < sizeof (expected) / sizeof (expected[0]); i++) | |
88 | { | |
89 | tstmul (expected[i].p1, expected[i].p2, expected[i].res); | |
90 | tstmul (expected[i].p2, expected[i].p1, expected[i].res); | |
91 | } | |
92 | ||
93 | if (!ok) { | |
94 | post_log ("Error in FPU math7 test\n"); | |
95 | return -1; | |
96 | } | |
97 | return 0; | |
98 | } | |
99 | ||
6d0f6bcf | 100 | #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */ |