1*a47a12beSStefan Roese /* 2*a47a12beSStefan Roese * Copyright (C) 2007 3*a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4*a47a12beSStefan Roese * 5*a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 6*a47a12beSStefan Roese * project. 7*a47a12beSStefan Roese * 8*a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 9*a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 10*a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 11*a47a12beSStefan Roese * the License, or (at your option) any later version. 12*a47a12beSStefan Roese * 13*a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 14*a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*a47a12beSStefan Roese * GNU General Public License for more details. 17*a47a12beSStefan Roese * 18*a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 19*a47a12beSStefan Roese * along with this program; if not, write to the Free Software 20*a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*a47a12beSStefan Roese * MA 02111-1307 USA 22*a47a12beSStefan Roese */ 23*a47a12beSStefan Roese /* 24*a47a12beSStefan Roese * This file is originally a part of the GCC testsuite. 25*a47a12beSStefan Roese * Check that certain subnormal numbers (formerly known as denormalized 26*a47a12beSStefan Roese * numbers) are rounded to within 0.5 ulp. PR other/14354. 27*a47a12beSStefan Roese */ 28*a47a12beSStefan Roese 29*a47a12beSStefan Roese #include <common.h> 30*a47a12beSStefan Roese 31*a47a12beSStefan Roese #include <post.h> 32*a47a12beSStefan Roese 33*a47a12beSStefan Roese #if CONFIG_POST & CONFIG_SYS_POST_FPU 34*a47a12beSStefan Roese 35*a47a12beSStefan Roese GNU_FPOST_ATTR 36*a47a12beSStefan Roese 37*a47a12beSStefan Roese union uf 38*a47a12beSStefan Roese { 39*a47a12beSStefan Roese unsigned int u; 40*a47a12beSStefan Roese float f; 41*a47a12beSStefan Roese }; 42*a47a12beSStefan Roese 43*a47a12beSStefan Roese static float 44*a47a12beSStefan Roese u2f (unsigned int v) 45*a47a12beSStefan Roese { 46*a47a12beSStefan Roese union uf u; 47*a47a12beSStefan Roese u.u = v; 48*a47a12beSStefan Roese return u.f; 49*a47a12beSStefan Roese } 50*a47a12beSStefan Roese 51*a47a12beSStefan Roese static unsigned int 52*a47a12beSStefan Roese f2u (float v) 53*a47a12beSStefan Roese { 54*a47a12beSStefan Roese union uf u; 55*a47a12beSStefan Roese u.f = v; 56*a47a12beSStefan Roese return u.u; 57*a47a12beSStefan Roese } 58*a47a12beSStefan Roese 59*a47a12beSStefan Roese static int ok = 1; 60*a47a12beSStefan Roese 61*a47a12beSStefan Roese static void 62*a47a12beSStefan Roese tstmul (unsigned int ux, unsigned int uy, unsigned int ur) 63*a47a12beSStefan Roese { 64*a47a12beSStefan Roese float x = u2f (ux); 65*a47a12beSStefan Roese float y = u2f (uy); 66*a47a12beSStefan Roese 67*a47a12beSStefan Roese if (f2u (x * y) != ur) 68*a47a12beSStefan Roese /* Set a variable rather than aborting here, to simplify tracing when 69*a47a12beSStefan Roese several computations are wrong. */ 70*a47a12beSStefan Roese ok = 0; 71*a47a12beSStefan Roese } 72*a47a12beSStefan Roese 73*a47a12beSStefan Roese /* We don't want to make this const and static, or else we risk inlining 74*a47a12beSStefan Roese causing the test to fold as constants at compile-time. */ 75*a47a12beSStefan Roese struct 76*a47a12beSStefan Roese { 77*a47a12beSStefan Roese unsigned int p1, p2, res; 78*a47a12beSStefan Roese } static volatile expected[] = 79*a47a12beSStefan Roese { 80*a47a12beSStefan Roese {0xfff, 0x3f800400, 0xfff}, 81*a47a12beSStefan Roese {0xf, 0x3fc88888, 0x17}, 82*a47a12beSStefan Roese {0xf, 0x3f844444, 0xf} 83*a47a12beSStefan Roese }; 84*a47a12beSStefan Roese 85*a47a12beSStefan Roese int fpu_post_test_math7 (void) 86*a47a12beSStefan Roese { 87*a47a12beSStefan Roese unsigned int i; 88*a47a12beSStefan Roese 89*a47a12beSStefan Roese for (i = 0; i < sizeof (expected) / sizeof (expected[0]); i++) 90*a47a12beSStefan Roese { 91*a47a12beSStefan Roese tstmul (expected[i].p1, expected[i].p2, expected[i].res); 92*a47a12beSStefan Roese tstmul (expected[i].p2, expected[i].p1, expected[i].res); 93*a47a12beSStefan Roese } 94*a47a12beSStefan Roese 95*a47a12beSStefan Roese if (!ok) { 96*a47a12beSStefan Roese post_log ("Error in FPU math7 test\n"); 97*a47a12beSStefan Roese return -1; 98*a47a12beSStefan Roese } 99*a47a12beSStefan Roese return 0; 100*a47a12beSStefan Roese } 101*a47a12beSStefan Roese 102*a47a12beSStefan Roese #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */ 103