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