1 /* 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 
11 #include "../builtins-config.h"
12 
13 /* Macro to do all FP type combinations.  The second half tests
14    narrowing the FP type.  */
15 #define TEST_FP2FIXED(FN1, FN2) \
16   extern void link_error_##FN1##_##FN2(void); \
17   extern void link_error_##FN1##f_##FN2##f(void); \
18   extern void link_error_##FN1##l_##FN2##l(void); \
19   extern void link_error_##FN1##_l##FN2(void); \
20   extern void link_error_##FN1##f_l##FN2##f(void); \
21   extern void link_error_##FN1##l_l##FN2##l(void); \
22   if ((long)__builtin_##FN1(d) != __builtin_##FN2(d)) \
23     link_error_##FN1##_##FN2(); \
24   if ((long)__builtin_##FN1##f(f) != __builtin_##FN2##f(f)) \
25     link_error_##FN1##f_##FN2##f(); \
26   if ((long)__builtin_##FN1##l(ld) != __builtin_##FN2##l(ld)) \
27     link_error_##FN1##l_##FN2##l(); \
28   if ((long long)__builtin_##FN1(d) != __builtin_l##FN2(d)) \
29     link_error_##FN1##_l##FN2(); \
30   if ((long long)__builtin_##FN1##f(f) != __builtin_l##FN2##f(f)) \
31     link_error_##FN1##f_l##FN2##f(); \
32   if ((long long)__builtin_##FN1##l(ld) != __builtin_l##FN2##l(ld)) \
33     link_error_##FN1##l_l##FN2##l(); \
34   extern void link_error_##FN1##_##FN2##f(void); \
35   extern void link_error_##FN1##l_##FN2(void); \
36   extern void link_error_##FN1##l_##FN2##f(void); \
37   extern void link_error_##FN1##_l##FN2##f(void); \
38   extern void link_error_##FN1##l_l##FN2(void); \
39   extern void link_error_##FN1##l_l##FN2##f(void); \
40   if (sizeof(double) > sizeof(float) \
41       && (long)__builtin_##FN1(f) != __builtin_##FN2##f(f)) \
42     link_error_##FN1##_##FN2##f(); \
43   if (sizeof(long double) > sizeof(double) \
44       && (long)__builtin_##FN1##l(d) != __builtin_##FN2(d)) \
45     link_error_##FN1##l_##FN2(); \
46   if (sizeof(long double) > sizeof(float) \
47       && (long)__builtin_##FN1##l(f) != __builtin_##FN2##f(f)) \
48     link_error_##FN1##l_##FN2##f(); \
49   if (sizeof(double) > sizeof(float) \
50       && (long long)__builtin_##FN1(f) != __builtin_l##FN2##f(f)) \
51     link_error_##FN1##_l##FN2##f(); \
52   if (sizeof(long double) > sizeof(double) \
53       && (long long)__builtin_##FN1##l(d) != __builtin_l##FN2(d)) \
54     link_error_##FN1##l_l##FN2(); \
55   if (sizeof(long double) > sizeof(float) \
56       && (long long)__builtin_##FN1##l(f) != __builtin_l##FN2##f(f)) \
57     link_error_##FN1##l_l##FN2##f()
58 
foo(double d,float f,long double ld)59 void __attribute__ ((__noinline__)) foo (double d, float f, long double ld)
60 {
61 #ifdef __OPTIMIZE__
62 # ifdef HAVE_C99_RUNTIME
63   /* The resulting transformation functions are all C99.  */
64   TEST_FP2FIXED (ceil, lceil);
65   TEST_FP2FIXED (floor, lfloor);
66   TEST_FP2FIXED (round, lround);
67   TEST_FP2FIXED (nearbyint, lrint);
68   TEST_FP2FIXED (rint, lrint);
69 # endif
70 #endif
71 }
72 
main()73 int main()
74 {
75   foo (1.0, 2.0, 3.0);
76   return 0;
77 }
78