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