| 1 |
/* Copyright (C) 2004 Free Software Foundation. |
| 2 |
|
| 3 |
Verify that builtin math functions (with fixed point return types) |
| 4 |
are converted to smaller FP types correctly by the compiler. |
| 5 |
|
| 6 |
Written by Kaveh Ghazi, 2004-05-01. */ |
| 7 |
|
| 8 |
/* { dg-do link } */ |
| 9 |
/* { dg-options "-ffast-math" } */ |
| 10 |
|
| 11 |
#include "../builtins-config.h" |
| 12 |
|
| 13 |
#define PROTOTYPE1_RET(FN, RET) \ |
| 14 |
extern RET FN(double); \ |
| 15 |
extern RET FN##f(float); \ |
| 16 |
extern RET FN##l(long double); |
| 17 |
|
| 18 |
/* Test converting math builtins to narrower FP types based on if the |
| 19 |
argument is a narrower type (perhaps implicitly) cast to a wider |
| 20 |
one. */ |
| 21 |
#define INNER_CAST1(MATHFN, RET) \ |
| 22 |
PROTOTYPE1_RET (MATHFN, RET); \ |
| 23 |
extern void link_failure_inner_##MATHFN##l_##MATHFN(void); \ |
| 24 |
extern void link_failure_inner_##MATHFN##l_##MATHFN##f(void); \ |
| 25 |
extern void link_failure_inner_##MATHFN##_##MATHFN##f(void); \ |
| 26 |
if (sizeof (long double) > sizeof (double) \ |
| 27 |
&& MATHFN##l(d1) != MATHFN(d1)) \ |
| 28 |
link_failure_inner_##MATHFN##l_##MATHFN(); \ |
| 29 |
if (sizeof (long double) > sizeof (float) \ |
| 30 |
&& MATHFN##l(f1) != MATHFN##f(f1)) \ |
| 31 |
link_failure_inner_##MATHFN##l_##MATHFN##f(); \ |
| 32 |
if (sizeof (long double) > sizeof (float) \ |
| 33 |
&& MATHFN##l((double)f1) != MATHFN##f(f1)) \ |
| 34 |
link_failure_inner_##MATHFN##l_##MATHFN##f(); \ |
| 35 |
if (sizeof (double) > sizeof (float) \ |
| 36 |
&& MATHFN(f1) != MATHFN##f(f1)) \ |
| 37 |
link_failure_inner_##MATHFN##_##MATHFN##f() |
| 38 |
|
| 39 |
void __attribute__ ((__noinline__)) test (double d1, float f1) |
| 40 |
{ |
| 41 |
#ifdef __OPTIMIZE__ |
| 42 |
#ifdef HAVE_C99_RUNTIME |
| 43 |
/* We're converting to implicitly generated C99 functions. */ |
| 44 |
INNER_CAST1 (__builtin_lceil, long); |
| 45 |
INNER_CAST1 (__builtin_llceil, long long); |
| 46 |
INNER_CAST1 (__builtin_lfloor, long); |
| 47 |
INNER_CAST1 (__builtin_llfloor, long long); |
| 48 |
INNER_CAST1 (lround, long); |
| 49 |
INNER_CAST1 (llround, long long); |
| 50 |
INNER_CAST1 (lrint, long); |
| 51 |
INNER_CAST1 (llrint, long long); |
| 52 |
#endif /* HAVE_C99_RUNTIME */ |
| 53 |
#endif /* __OPTIMIZE__ */ |
| 54 |
} |
| 55 |
|
| 56 |
int main (void) |
| 57 |
{ |
| 58 |
test (1, 2); |
| 59 |
return 0; |
| 60 |
} |