blob: 891aa95685fe8f2256c528a63024d933ce5983bb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sergei Poselenov3190dbe2007-07-05 08:17:37 +02002/*
3 * Copyright (C) 2007
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Sergei Poselenov3190dbe2007-07-05 08:17:37 +02005 */
6/*
7 * This file is originally a part of the GCC testsuite.
8 * Check that certain subnormal numbers (formerly known as denormalized
9 * numbers) are rounded to within 0.5 ulp. PR other/14354.
10 */
11
12#include <common.h>
13
Sergei Poselenov3190dbe2007-07-05 08:17:37 +020014#include <post.h>
15
Yuri Tikhonov7ed66f72008-12-20 14:54:21 +030016GNU_FPOST_ATTR
17
Tom Rini3dd5d4a2022-12-04 10:14:17 -050018#if CFG_POST & CFG_SYS_POST_FPU
Kumar Galafe6555b2011-01-25 03:00:08 -060019
Sergei Poselenov3190dbe2007-07-05 08:17:37 +020020union 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 /* Set a variable rather than aborting here, to simplify tracing when
52 several computations are wrong. */
53 ok = 0;
54}
55
56/* We don't want to make this const and static, or else we risk inlining
57 causing the test to fold as constants at compile-time. */
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
Mike Frysinger83a687b2011-05-10 07:28:35 +000072 for (i = 0; i < ARRAY_SIZE(expected); i++)
Sergei Poselenov3190dbe2007-07-05 08:17:37 +020073 {
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
Tom Rini3dd5d4a2022-12-04 10:14:17 -050085#endif /* CFG_POST & CFG_SYS_POST_FPU */