1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * Copyright (C) 2007 4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 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 12#include <common.h> 13 14#include <post.h> 15 16GNU_FPOST_ATTR 17 18#if CFG_POST & CFG_SYS_POST_FPU 19 20union 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 72 for (i = 0; i < ARRAY_SIZE(expected); i++) 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 85#endif /* CFG_POST & CFG_SYS_POST_FPU */ 86