Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / u-boot / post / lib_powerpc / fpu / mul-subnormal-single-1.c
1 /*
2  * Copyright (C) 2007
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7 /*
8  * This file is originally a part of the GCC testsuite.
9  * Check that certain subnormal numbers (formerly known as denormalized
10  * numbers) are rounded to within 0.5 ulp.  PR other/14354.
11  */
12
13 #include <common.h>
14
15 #include <post.h>
16
17 GNU_FPOST_ATTR
18
19 #if CONFIG_POST & CONFIG_SYS_POST_FPU
20
21 union uf
22 {
23         unsigned int u;
24         float f;
25 };
26
27 static float
28 u2f (unsigned int v)
29 {
30         union uf u;
31         u.u = v;
32         return u.f;
33 }
34
35 static unsigned int
36 f2u (float v)
37 {
38         union uf u;
39         u.f = v;
40         return u.u;
41 }
42
43 static int ok = 1;
44
45 static void
46 tstmul (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         /* Set a variable rather than aborting here, to simplify tracing when
53            several computations are wrong.  */
54                 ok = 0;
55 }
56
57 /* We don't want to make this const and static, or else we risk inlining
58    causing the test to fold as constants at compile-time.  */
59 struct
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
69 int 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 /* CONFIG_POST & CONFIG_SYS_POST_FPU */