1 /* Copyright (C) 2004 Free Software Foundation.
3 Verify that integral FP expressions are optimized.
5 Written by Kaveh Ghazi, 2004-03-16. */
8 /* We need -ffinite-math-only so that we can fold "foo != foo", where
9 foo is a floating point expression. We need -fno-math-errno so
10 that various math functions are marked const/pure and can be
12 /* { dg-options "-ffinite-math-only -fno-math-errno" } */
14 extern int link_failure (int);
16 /* Test that the various FP truncation builtins detect integral
18 #define CHECK_FN(MATHFN) \
19 if (__builtin_##MATHFN(i1) != i1) link_failure (__LINE__); \
20 if (__builtin_##MATHFN##f(i1) != i1) link_failure (__LINE__); \
21 if (__builtin_##MATHFN##l(i1) != i1) link_failure (__LINE__);
23 #define CHECK_FN_RET(MATHFN, RET) \
24 if (__builtin_##MATHFN(i1) != (RET)(double)i1) link_failure (__LINE__); \
25 if (__builtin_##MATHFN##f(i1) != (RET)(float)i1) link_failure (__LINE__); \
26 if (__builtin_##MATHFN##l(i1) != (RET)(long double)i1) link_failure (__LINE__);
28 /* Check that various other integral expressions are detected. */
29 #define CHECK_EXPR(EXPR,NAME) \
30 if (__builtin_ceill(EXPR) != (EXPR)) link_failure (__LINE__); \
31 if (__builtin_lroundl(EXPR) != (long)(long double)(EXPR)) link_failure (__LINE__);
33 void __attribute__ ((__noinline__
)) test (int i1
, int i2
)
41 CHECK_FN_RET(lround
, long);
42 CHECK_FN_RET(llround
, long long);
43 CHECK_FN_RET(lrint
, long);
44 CHECK_FN_RET(llrint
, long long);
45 CHECK_FN_RET(lceil
, long);
46 CHECK_FN_RET(llceil
, long long);
47 CHECK_FN_RET(lfloor
, long);
48 CHECK_FN_RET(llfloor
, long long);
50 CHECK_EXPR (5.0, REAL_CST
);
51 CHECK_EXPR (5.0F
, REAL_CSTf
);
52 CHECK_EXPR (5.0L, REAL_CSTl
);
53 CHECK_EXPR ((double)i1
, FLOAT_EXPR
);
54 CHECK_EXPR ((float)i1
, FLOAT_EXPRf
);
55 CHECK_EXPR ((long double)i1
, FLOAT_EXPRl
);
56 CHECK_EXPR (__builtin_fabs(i1
), ABS_EXPR
);
57 CHECK_EXPR (__builtin_fabsf(i1
), ABS_EXPRf
);
58 CHECK_EXPR (__builtin_fabsl(i1
), ABS_EXPRl
);
59 CHECK_EXPR (((void)i1
,(double)i2
), COMPOUND_EXPR
);
60 CHECK_EXPR ((double)i1
+i2
, PLUS_EXPR
);
61 CHECK_EXPR ((double)i1
-i2
, MINUS_EXPR
);
62 CHECK_EXPR ((double)i1
*i2
, MULT_EXPR
);