xref: /openbmc/u-boot/post/lib_powerpc/fpu/20010114-2.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3a47a12beSStefan Roese  * Copyright (C) 2007
4a47a12beSStefan Roese  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5a47a12beSStefan Roese  */
6a47a12beSStefan Roese /*
7a47a12beSStefan Roese  * This file is originally a part of the GCC testsuite.
8a47a12beSStefan Roese  */
9a47a12beSStefan Roese 
10a47a12beSStefan Roese #include <common.h>
11a47a12beSStefan Roese 
12a47a12beSStefan Roese #include <post.h>
13a47a12beSStefan Roese 
14a47a12beSStefan Roese GNU_FPOST_ATTR
15a47a12beSStefan Roese 
16e009cdebSKumar Gala #if CONFIG_POST & CONFIG_SYS_POST_FPU
17e009cdebSKumar Gala 
rintf(float x)18a47a12beSStefan Roese static float rintf (float x)
19a47a12beSStefan Roese {
20a47a12beSStefan Roese 	volatile float TWO23 = 8388608.0;
21a47a12beSStefan Roese 
22a47a12beSStefan Roese 	if (__builtin_fabs (x) < TWO23)
23a47a12beSStefan Roese 	{
24a47a12beSStefan Roese 		if (x > 0.0)
25a47a12beSStefan Roese 		{
26a47a12beSStefan Roese 			x += TWO23;
27a47a12beSStefan Roese 			x -= TWO23;
28a47a12beSStefan Roese 		}
29a47a12beSStefan Roese 		else if (x < 0.0)
30a47a12beSStefan Roese 		{
31a47a12beSStefan Roese 			x = TWO23 - x;
32a47a12beSStefan Roese 			x = -(x - TWO23);
33a47a12beSStefan Roese 		}
34a47a12beSStefan Roese 	}
35a47a12beSStefan Roese 
36a47a12beSStefan Roese 	return x;
37a47a12beSStefan Roese }
38a47a12beSStefan Roese 
fpu_post_test_math2(void)39a47a12beSStefan Roese int fpu_post_test_math2 (void)
40a47a12beSStefan Roese {
41a47a12beSStefan Roese 	if (rintf (-1.5) != -2.0) {
42a47a12beSStefan Roese 		post_log ("Error in FPU math2 test\n");
43a47a12beSStefan Roese 		return -1;
44a47a12beSStefan Roese 	}
45a47a12beSStefan Roese 	return 0;
46a47a12beSStefan Roese }
47a47a12beSStefan Roese 
48a47a12beSStefan Roese #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */
49