blob: 2815a3032e32e7efe4154763c44527b077a2c3dd [file] [log] [blame]
Sergei Poselenovb4489622007-07-05 08:17:37 +02001/*
2 * Copyright (C) 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Sergei Poselenovb4489622007-07-05 08:17:37 +02006 */
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
Sergei Poselenovb4489622007-07-05 08:17:37 +020015#include <post.h>
16
Yuri Tikhonovce82ff02008-12-20 14:54:21 +030017GNU_FPOST_ATTR
18
Kumar Galae009cde2011-01-25 03:00:08 -060019#if CONFIG_POST & CONFIG_SYS_POST_FPU
20
Sergei Poselenovb4489622007-07-05 08:17:37 +020021union 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 /* 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. */
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
Mike Frysingerd2397812011-05-10 07:28:35 +000073 for (i = 0; i < ARRAY_SIZE(expected); i++)
Sergei Poselenovb4489622007-07-05 08:17:37 +020074 {
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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020086#endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */