Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 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 | |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 15 | #include <post.h> |
| 16 | |
Yuri Tikhonov | ce82ff0 | 2008-12-20 14:54:21 +0300 | [diff] [blame] | 17 | GNU_FPOST_ATTR |
| 18 | |
Kumar Gala | e009cde | 2011-01-25 03:00:08 -0600 | [diff] [blame] | 19 | #if CONFIG_POST & CONFIG_SYS_POST_FPU |
| 20 | |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 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 | |
Mike Frysinger | d239781 | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 73 | for (i = 0; i < ARRAY_SIZE(expected); i++) |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 86 | #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */ |