1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/* Copyright (C) 2007 Free Software Foundation.
Verify that built-in folding of logb, ilogb and significand is
correctly performed by the compiler.
Origin: Kaveh R. Ghazi, February 22, 2007. */
/* { dg-do link } */
/* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
/* In order to fold algebraic exprs below, targets with "composite"
floating point formats need -funsafe-math-optimizations. */
/* { dg-require-effective-target inf } */
/* { dg-options "-funsafe-math-optimizations" { target powerpc*-*-* } } */
extern void link_error(int);
/* Return TRUE if the sign of X != sign of Y. This is important when
comparing signed zeros. */
#define CKSGN_F(X,Y) \
(__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
#define CKSGN(X,Y) \
(__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
#define CKSGN_L(X,Y) \
(__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
/* Test that FUNC(ARG) == RES. Check the sign in case we get -0.0. */
#define TESTIT(FUNC,ARG,RES) do { \
if (__builtin_##FUNC##f(ARG##f) != RES##f \
|| CKSGN_F(__builtin_##FUNC##f(ARG##f),RES##f)) \
link_error(__LINE__); \
if (__builtin_##FUNC(ARG) != RES \
|| CKSGN(__builtin_##FUNC(ARG),RES)) \
link_error(__LINE__); \
if (__builtin_##FUNC##l(ARG##l) != RES##l \
|| CKSGN_L(__builtin_##FUNC##l(ARG##l),RES##l)) \
link_error(__LINE__); \
} while (0)
/* Test that FUNC(ARG) == RES. RES is an int so it can't be -0.0. */
#define TESTIT2(FUNC,ARG,RES) do { \
if (__builtin_##FUNC##f(ARG##f) != RES) \
link_error(__LINE__); \
if (__builtin_##FUNC(ARG) != RES) \
link_error(__LINE__); \
if (__builtin_##FUNC##l(ARG##l) != RES) \
link_error(__LINE__); \
} while (0)
/* Test if FUNCRES(FUNC(NEG FUNCARG(ARGARG))) is false. Check the
sign as well. */
#define TESTIT3(FUNC,NEG,FUNCARG,ARGARG,FUNCRES,NEG2) do { \
if (!__builtin_##FUNCRES##f(__builtin_##FUNC(NEG __builtin_##FUNCARG##f(ARGARG))) \
|| CKSGN_F(__builtin_##FUNC##f(NEG __builtin_##FUNCARG##f(ARGARG)), NEG2 __builtin_##FUNCARG##f(ARGARG))) \
link_error(__LINE__); \
if (!__builtin_##FUNCRES(__builtin_##FUNC(NEG __builtin_##FUNCARG(ARGARG))) \
|| CKSGN(__builtin_##FUNC(NEG __builtin_##FUNCARG(ARGARG)), NEG2 __builtin_##FUNCARG(ARGARG))) \
link_error(__LINE__); \
if (!__builtin_##FUNCRES##l(__builtin_##FUNC##l(NEG __builtin_##FUNCARG##l(ARGARG))) \
|| CKSGN_L(__builtin_##FUNC##l(NEG __builtin_##FUNCARG##l(ARGARG)), NEG2 __builtin_##FUNCARG##l(ARGARG))) \
link_error(__LINE__); \
} while (0)
void __attribute__ ((__noinline__))
foo(void)
{
/* If radix == 2, test that logb(ARG2) -> ARG3. */
#if __FLT_RADIX__ == 2
TESTIT (logb, -0x1p40, 40.0);
TESTIT (logb, -0x1p30, 30.0);
TESTIT (logb, -0x1p20, 20.0);
TESTIT (logb, -0x1p10, 10.0);
TESTIT (logb, -0x1p5, 5.0);
TESTIT (logb, -100/3.0, 5.0);
TESTIT (logb, -2.0, 1.0);
TESTIT (logb, -1.5, 0.0);
TESTIT (logb, -1.0, 0.0);
TESTIT (logb, -1/3.0, -2.0);
TESTIT (logb, -1/9.0, -4.0);
TESTIT (logb, -0x1p-5, -5.0);
TESTIT (logb, -0x1p-10, -10.0);
TESTIT (logb, -0x1p-20, -20.0);
TESTIT (logb, -0x1p-30, -30.0);
TESTIT (logb, -0x1p-40, -40.0);
TESTIT (logb, 0x1p-40, -40.0);
TESTIT (logb, 0x1p-30, -30.0);
TESTIT (logb, 0x1p-20, -20.0);
TESTIT (logb, 0x1p-10, -10.0);
TESTIT (logb, 0x1p-5, -5.0);
TESTIT (logb, 1/9.0, -4.0);
TESTIT (logb, 1/3.0, -2.0);
TESTIT (logb, 1.0, 0.0);
TESTIT (logb, 1.5, 0.0);
TESTIT (logb, 2.0, 1.0);
TESTIT (logb, 100/3.0, 5.0);
TESTIT (logb, 0x1p5, 5.0);
TESTIT (logb, 0x1p10, 10.0);
TESTIT (logb, 0x1p20, 20.0);
TESTIT (logb, 0x1p30, 30.0);
TESTIT (logb, 0x1p40, 40.0);
#endif
/* If radix == 2, test that ilogb(ARG2) -> ARG3. */
#if __FLT_RADIX__ == 2
TESTIT2 (ilogb, -0x1p40, 40);
TESTIT2 (ilogb, -0x1p30, 30);
TESTIT2 (ilogb, -0x1p20, 20);
TESTIT2 (ilogb, -0x1p10, 10);
TESTIT2 (ilogb, -0x1p5, 5);
TESTIT2 (ilogb, -100/3.0, 5);
TESTIT2 (ilogb, -2.0, 1);
TESTIT2 (ilogb, -1.5, 0);
TESTIT2 (ilogb, -1.0, 0);
TESTIT2 (ilogb, -1/3.0, -2);
TESTIT2 (ilogb, -1/9.0, -4);
TESTIT2 (ilogb, -0x1p-5, -5);
TESTIT2 (ilogb, -0x1p-10, -10);
TESTIT2 (ilogb, -0x1p-20, -20);
TESTIT2 (ilogb, -0x1p-30, -30);
TESTIT2 (ilogb, -0x1p-40, -40);
TESTIT2 (ilogb, 0x1p-40, -40);
TESTIT2 (ilogb, 0x1p-30, -30);
TESTIT2 (ilogb, 0x1p-20, -20);
TESTIT2 (ilogb, 0x1p-10, -10);
TESTIT2 (ilogb, 0x1p-5, -5);
TESTIT2 (ilogb, 1/9.0, -4);
TESTIT2 (ilogb, 1/3.0, -2);
TESTIT2 (ilogb, 1.0, 0);
TESTIT2 (ilogb, 1.5, 0);
TESTIT2 (ilogb, 2.0, 1);
TESTIT2 (ilogb, 100/3.0, 5);
TESTIT2 (ilogb, 0x1p5, 5);
TESTIT2 (ilogb, 0x1p10, 10);
TESTIT2 (ilogb, 0x1p20, 20);
TESTIT2 (ilogb, 0x1p30, 30);
TESTIT2 (ilogb, 0x1p40, 40);
#endif
/* If radix == 2, test that significand(ARG2) -> ARG3. Zero always
folds regardless of the radix. */
TESTIT (significand, -0.0, -0.0);
TESTIT (significand, 0.0, 0.0);
#if __FLT_RADIX__ == 2
TESTIT (significand, -0x1p5, -1.0);
TESTIT (significand, -100/3.0, -100/96.0);
TESTIT (significand, -1.5, -1.5);
TESTIT (significand, -1.0, -1.0);
TESTIT (significand, -1/3.0, -4/3.0);
TESTIT (significand, -1/9.0, -16/9.0);
TESTIT (significand, -0x1p-5, -1.0);
TESTIT (significand, 0x1p-5, 1.0);
TESTIT (significand, 1/9.0, 16/9.0);
TESTIT (significand, 1/3.0, 4/3.0);
TESTIT (significand, 1.0, 1.0);
TESTIT (significand, 1.5, 1.5);
TESTIT (significand, 100/3.0, 100/96.0);
TESTIT (significand, 0x1p5, 1.0);
#endif
/* Test for f(+-Inf) -> +-Inf and f(+-NaN) -> +-NaN, regardless of
the radix. */
TESTIT3 (logb, ,inf, , isinf, );
TESTIT3 (logb, - ,inf, , isinf, );
TESTIT3 (logb, ,nan, "", isnan, );
TESTIT3 (logb, - ,nan, "", isnan, -);
TESTIT3 (significand, ,inf, , isinf, );
TESTIT3 (significand, - ,inf, , isinf, -);
TESTIT3 (significand, ,nan, "", isnan, );
TESTIT3 (significand, - ,nan, "", isnan, -);
}
int main()
{
foo ();
return 0;
}
|