1 /* Copyright (C) 2004 Free Software Foundation.
3 Verify that built-in math function conversion into integer rounding
4 functions is correctly performed by the compiler.
6 Written by Kaveh ghazi, 2004-04-26. */
9 /* { dg-options "-ffast-math" } */
10 /* { dg-options "-ffast-math -mmacosx-version-min=10.3" { target powerpc-*-darwin* } } */
11 /* { dg-options "-ffast-math -std=c99" { target *-*-solaris2* } } */
13 #include "../builtins-config.h"
15 #define PROTOTYPE(FN) extern double FN(double); \
16 extern float FN##f(float); \
17 extern long double FN##l(long double);
18 #define PROTOTYPE_RET(FN, RET) extern RET FN(double); \
19 extern RET FN##f(float); \
20 extern RET FN##l(long double);
22 /* Macro to do all FP type combinations. The second half tests
23 narrowing the FP type. */
24 #define TEST_FP2FIXED(FN1, FN2) \
26 PROTOTYPE_RET(FN2, long) \
27 PROTOTYPE_RET(l##FN2, long long) \
28 extern void link_error_##FN1##_##FN2(void); \
29 extern void link_error_##FN1##f_##FN2##f(void); \
30 extern void link_error_##FN1##l_##FN2##l(void); \
31 extern void link_error_##FN1##_l##FN2(void); \
32 extern void link_error_##FN1##f_l##FN2##f(void); \
33 extern void link_error_##FN1##l_l##FN2##l(void); \
34 if ((long)FN1(d) != FN2(d)) \
35 link_error_##FN1##_##FN2(); \
36 if ((long)FN1##f(f) != FN2##f(f)) \
37 link_error_##FN1##f_##FN2##f(); \
38 if ((long)FN1##l(ld) != FN2##l(ld)) \
39 link_error_##FN1##l_##FN2##l(); \
40 if ((long long)FN1(d) != l##FN2(d)) \
41 link_error_##FN1##_l##FN2(); \
42 if ((long long)FN1##f(f) != l##FN2##f(f)) \
43 link_error_##FN1##f_l##FN2##f(); \
44 if ((long long)FN1##l(ld) != l##FN2##l(ld)) \
45 link_error_##FN1##l_l##FN2##l(); \
46 extern void link_error_##FN1##_##FN2##f(void); \
47 extern void link_error_##FN1##l_##FN2(void); \
48 extern void link_error_##FN1##l_##FN2##f(void); \
49 extern void link_error_##FN1##_l##FN2##f(void); \
50 extern void link_error_##FN1##l_l##FN2(void); \
51 extern void link_error_##FN1##l_l##FN2##f(void); \
52 if (sizeof(double) > sizeof(float) && (long)FN1(f) != FN2##f(f)) \
53 link_error_##FN1##_##FN2##f(); \
54 if (sizeof(long double) > sizeof(double) && (long)FN1##l(d) != FN2(d)) \
55 link_error_##FN1##l_##FN2(); \
56 if (sizeof(long double) > sizeof(float) && (long)FN1##l(f) != FN2##f(f)) \
57 link_error_##FN1##l_##FN2##f(); \
58 if (sizeof(double) > sizeof(float) && (long long)FN1(f) != l##FN2##f(f)) \
59 link_error_##FN1##_l##FN2##f(); \
60 if (sizeof(long double) > sizeof(double) && (long long)FN1##l(d) != l##FN2(d)) \
61 link_error_##FN1##l_l##FN2(); \
62 if (sizeof(long double) > sizeof(float) && (long long)FN1##l(f) != l##FN2##f(f)) \
63 link_error_##FN1##l_l##FN2##f()
65 void __attribute__ ((__noinline__)) foo (double d, float f, long double ld)
68 # ifdef HAVE_C99_RUNTIME
69 /* The resulting transformation functions are all C99. */
70 TEST_FP2FIXED (round, lround);
71 TEST_FP2FIXED (nearbyint, lrint);
72 TEST_FP2FIXED (rint, lrint);