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