1 |
298 |
jeremybenn |
/* Copyright (C) 2004 Free Software Foundation.
|
2 |
|
|
|
3 |
|
|
Verify that built-in math function conversion into integer rounding
|
4 |
|
|
functions is correctly performed by the compiler.
|
5 |
|
|
|
6 |
|
|
Written by Kaveh ghazi, 2004-04-26. */
|
7 |
|
|
|
8 |
|
|
/* { dg-do link } */
|
9 |
|
|
/* { dg-options "-ffast-math" } */
|
10 |
|
|
/* { dg-add-options c99_runtime } */
|
11 |
|
|
|
12 |
|
|
#include "../builtins-config.h"
|
13 |
|
|
|
14 |
|
|
/* Macro to do all FP type combinations. The second half tests
|
15 |
|
|
narrowing the FP type. */
|
16 |
|
|
#define TEST_FP2FIXED(FN1, FN2) \
|
17 |
|
|
extern void link_error_##FN1##_##FN2(void); \
|
18 |
|
|
extern void link_error_##FN1##f_##FN2##f(void); \
|
19 |
|
|
extern void link_error_##FN1##l_##FN2##l(void); \
|
20 |
|
|
extern void link_error_##FN1##_l##FN2(void); \
|
21 |
|
|
extern void link_error_##FN1##f_l##FN2##f(void); \
|
22 |
|
|
extern void link_error_##FN1##l_l##FN2##l(void); \
|
23 |
|
|
if ((long)__builtin_##FN1(d) != __builtin_##FN2(d)) \
|
24 |
|
|
link_error_##FN1##_##FN2(); \
|
25 |
|
|
if ((long)__builtin_##FN1##f(f) != __builtin_##FN2##f(f)) \
|
26 |
|
|
link_error_##FN1##f_##FN2##f(); \
|
27 |
|
|
if ((long)__builtin_##FN1##l(ld) != __builtin_##FN2##l(ld)) \
|
28 |
|
|
link_error_##FN1##l_##FN2##l(); \
|
29 |
|
|
if ((long long)__builtin_##FN1(d) != __builtin_l##FN2(d)) \
|
30 |
|
|
link_error_##FN1##_l##FN2(); \
|
31 |
|
|
if ((long long)__builtin_##FN1##f(f) != __builtin_l##FN2##f(f)) \
|
32 |
|
|
link_error_##FN1##f_l##FN2##f(); \
|
33 |
|
|
if ((long long)__builtin_##FN1##l(ld) != __builtin_l##FN2##l(ld)) \
|
34 |
|
|
link_error_##FN1##l_l##FN2##l(); \
|
35 |
|
|
extern void link_error_##FN1##_##FN2##f(void); \
|
36 |
|
|
extern void link_error_##FN1##l_##FN2(void); \
|
37 |
|
|
extern void link_error_##FN1##l_##FN2##f(void); \
|
38 |
|
|
extern void link_error_##FN1##_l##FN2##f(void); \
|
39 |
|
|
extern void link_error_##FN1##l_l##FN2(void); \
|
40 |
|
|
extern void link_error_##FN1##l_l##FN2##f(void); \
|
41 |
|
|
if (sizeof(double) > sizeof(float) \
|
42 |
|
|
&& (long)__builtin_##FN1(f) != __builtin_##FN2##f(f)) \
|
43 |
|
|
link_error_##FN1##_##FN2##f(); \
|
44 |
|
|
if (sizeof(long double) > sizeof(double) \
|
45 |
|
|
&& (long)__builtin_##FN1##l(d) != __builtin_##FN2(d)) \
|
46 |
|
|
link_error_##FN1##l_##FN2(); \
|
47 |
|
|
if (sizeof(long double) > sizeof(float) \
|
48 |
|
|
&& (long)__builtin_##FN1##l(f) != __builtin_##FN2##f(f)) \
|
49 |
|
|
link_error_##FN1##l_##FN2##f(); \
|
50 |
|
|
if (sizeof(double) > sizeof(float) \
|
51 |
|
|
&& (long long)__builtin_##FN1(f) != __builtin_l##FN2##f(f)) \
|
52 |
|
|
link_error_##FN1##_l##FN2##f(); \
|
53 |
|
|
if (sizeof(long double) > sizeof(double) \
|
54 |
|
|
&& (long long)__builtin_##FN1##l(d) != __builtin_l##FN2(d)) \
|
55 |
|
|
link_error_##FN1##l_l##FN2(); \
|
56 |
|
|
if (sizeof(long double) > sizeof(float) \
|
57 |
|
|
&& (long long)__builtin_##FN1##l(f) != __builtin_l##FN2##f(f)) \
|
58 |
|
|
link_error_##FN1##l_l##FN2##f()
|
59 |
|
|
|
60 |
|
|
void __attribute__ ((__noinline__)) foo (double d, float f, long double ld)
|
61 |
|
|
{
|
62 |
|
|
#ifdef __OPTIMIZE__
|
63 |
|
|
# ifdef HAVE_C99_RUNTIME
|
64 |
|
|
/* The resulting transformation functions are all C99. */
|
65 |
|
|
TEST_FP2FIXED (ceil, lceil);
|
66 |
|
|
TEST_FP2FIXED (floor, lfloor);
|
67 |
|
|
TEST_FP2FIXED (round, lround);
|
68 |
|
|
TEST_FP2FIXED (nearbyint, lrint);
|
69 |
|
|
TEST_FP2FIXED (rint, lrint);
|
70 |
|
|
# endif
|
71 |
|
|
#endif
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
int main()
|
75 |
|
|
{
|
76 |
|
|
foo (1.0, 2.0, 3.0);
|
77 |
|
|
return 0;
|
78 |
|
|
}
|