Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 5 | */ |
| 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 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 12 | #include <config.h> |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 13 | |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 14 | #include <post.h> |
| 15 | |
Yuri Tikhonov | 7ed66f7 | 2008-12-20 14:54:21 +0300 | [diff] [blame] | 16 | GNU_FPOST_ATTR |
| 17 | |
Tom Rini | 3dd5d4a | 2022-12-04 10:14:17 -0500 | [diff] [blame] | 18 | #if CFG_POST & CFG_SYS_POST_FPU |
Kumar Gala | fe6555b | 2011-01-25 03:00:08 -0600 | [diff] [blame] | 19 | |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 20 | union uf |
| 21 | { |
| 22 | unsigned int u; |
| 23 | float f; |
| 24 | }; |
| 25 | |
| 26 | static float |
| 27 | u2f (unsigned int v) |
| 28 | { |
| 29 | union uf u; |
| 30 | u.u = v; |
| 31 | return u.f; |
| 32 | } |
| 33 | |
| 34 | static unsigned int |
| 35 | f2u (float v) |
| 36 | { |
| 37 | union uf u; |
| 38 | u.f = v; |
| 39 | return u.u; |
| 40 | } |
| 41 | |
| 42 | static int ok = 1; |
| 43 | |
| 44 | static void |
| 45 | tstmul (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. */ |
| 58 | struct |
| 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 | |
| 68 | int fpu_post_test_math7 (void) |
| 69 | { |
| 70 | unsigned int i; |
| 71 | |
Mike Frysinger | 83a687b | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 72 | for (i = 0; i < ARRAY_SIZE(expected); i++) |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 73 | { |
| 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 Rini | 3dd5d4a | 2022-12-04 10:14:17 -0500 | [diff] [blame] | 85 | #endif /* CFG_POST & CFG_SYS_POST_FPU */ |