1 /* Copyright (C) 2004 Free Software Foundation.
3 Verify that integral FP expressions are optimized.
5 Written by Kaveh Ghazi, 2004-03-16. */
8 /* { dg-options "-ffast-math" } */
10 #define PROTOTYPE1(FN) extern double FN(double); extern float FN##f(float); \
11 extern long double FN##l(long double);
12 #define PROTOTYPE1_RET(FN, RET) extern RET FN(double); extern RET FN##f(float); \
13 extern RET FN##l(long double);
14 #define PROTOTYPE_LINK_FAILURE(FN) extern void link_failure_##FN(void); \
15 extern void link_failure_##FN##f(void); \
16 extern void link_failure_##FN##l(void); \
25 PROTOTYPE1_RET(lround
, long)
26 PROTOTYPE1_RET(llround
, long long)
27 PROTOTYPE1_RET(lrint
, long)
28 PROTOTYPE1_RET(llrint
, long long)
30 /* Test that the various FP truncation builtins detect integral
32 #define CHECK_FN(MATHFN) \
33 PROTOTYPE_LINK_FAILURE(MATHFN); \
34 if (MATHFN(i1) != i1) link_failure_##MATHFN(); \
35 if (MATHFN##f(i1) != i1) link_failure_##MATHFN##f(); \
36 if (MATHFN##l(i1) != i1) link_failure_##MATHFN##l();
38 #define CHECK_FN_RET(MATHFN, RET) \
39 PROTOTYPE_LINK_FAILURE(MATHFN); \
40 if (MATHFN(i1) != (RET)(double)i1) link_failure_##MATHFN(); \
41 if (MATHFN##f(i1) != (RET)(float)i1) link_failure_##MATHFN##f(); \
42 if (MATHFN##l(i1) != (RET)(long double)i1) link_failure_##MATHFN##l();
44 /* Check that various other integral expressions are detected. */
45 #define CHECK_EXPR(EXPR,NAME) \
46 extern void link_failure_FP_##NAME(void); \
47 extern void link_failure_fixed_##NAME(void); \
48 if (ceill(EXPR) != (EXPR)) link_failure_FP_##NAME(); \
49 if (lroundl(EXPR) != (long)(long double)(EXPR)) link_failure_fixed_##NAME();
51 void __attribute__ ((__noinline__
)) test (int i1
, int i2
)
59 CHECK_FN_RET(lround
, long);
60 CHECK_FN_RET(llround
, long long);
61 CHECK_FN_RET(lrint
, long);
62 CHECK_FN_RET(llrint
, long long);
64 CHECK_EXPR (5.0, REAL_CST
);
65 CHECK_EXPR (5.0F
, REAL_CSTf
);
66 CHECK_EXPR (5.0L, REAL_CSTl
);
67 CHECK_EXPR ((double)i1
, FLOAT_EXPR
);
68 CHECK_EXPR ((float)i1
, FLOAT_EXPRf
);
69 CHECK_EXPR ((long double)i1
, FLOAT_EXPRl
);
70 CHECK_EXPR (fabs(i1
), ABS_EXPR
);
71 CHECK_EXPR (fabsf(i1
), ABS_EXPRf
);
72 CHECK_EXPR (fabsl(i1
), ABS_EXPRl
);
73 CHECK_EXPR (((void)i1
,(double)i2
), COMPOUND_EXPR
);
74 CHECK_EXPR ((double)i1
+i2
, PLUS_EXPR
);
75 CHECK_EXPR ((double)i1
-i2
, MINUS_EXPR
);
76 CHECK_EXPR ((double)i1
*i2
, MULT_EXPR
);