1 /* Copyright (C) 2007 Free Software Foundation.
3 Verify that built-in folding of frexp is correctly performed by the
6 Origin: Kaveh R. Ghazi, February 21, 2007. */
9 /* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
10 /* In order to fold algebraic exprs below, targets with "composite"
11 floating point formats need -funsafe-math-optimizations. */
12 /* { dg-options "-funsafe-math-optimizations" { target mips*-*-irix6* powerpc*-*-* } } */
14 extern void link_error(int);
16 /* Return TRUE if the sign of X != sign of Y. This is important when
17 comparing signed zeros. */
18 #define CKSGN_F(X,Y) \
19 (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
21 (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
22 #define CKSGN_L(X,Y) \
23 (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
25 /* We can only check the exponent when optimizing since we rely on
26 other optimizations to propagate the value. TRUE means an error
29 #define CKEXP(X,Y) X != Y
34 /* Test that frexp(ARG,&i) == RES && i == EXP. Check the sign in
36 #define TESTIT_FREXP(ARG,RES,EXP) do { \
38 if (__builtin_frexpf(ARG##f,&i) != RES##f \
40 || CKSGN_F(__builtin_frexpf(ARG##f,&i),RES##f)) \
41 link_error(__LINE__); \
43 if (__builtin_frexp(ARG,&i) != RES \
45 || CKSGN(__builtin_frexp(ARG,&i),RES)) \
46 link_error(__LINE__); \
48 if (__builtin_frexpl(ARG##l,&i) != RES##l \
50 || CKSGN_L(__builtin_frexpl(ARG##l,&i),RES##l)) \
51 link_error(__LINE__); \
54 /* Test that FUNCRES(frexp(NEG FUNCARG(ARGARG),&i)) is false. Check
55 the sign as well. Ensure side-effects are evaluated in i. */
56 #define TESTIT_FREXP2(NEG,FUNCARG,ARGARG,FUNCRES) do { \
58 if (!__builtin_##FUNCRES##f(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),&i)) \
59 || CKSGN_F(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##f(ARGARG)) \
61 link_error(__LINE__); \
62 if (!__builtin_##FUNCRES(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),&i)) \
63 || CKSGN(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG(ARGARG)) \
65 link_error(__LINE__); \
66 if (!__builtin_##FUNCRES##l(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),&i)) \
67 || CKSGN_L(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##l(ARGARG)) \
69 link_error(__LINE__); \
72 void __attribute__ ((__noinline__
))
75 /* Test that frexp(ARG1,&i) -> ARG2 && i == ARG3. */
76 TESTIT_FREXP (-0x1p
40, -0.5, 41);
77 TESTIT_FREXP (-0x1p
30, -0.5, 31);
78 TESTIT_FREXP (-0x1p
20, -0.5, 21);
79 TESTIT_FREXP (-0x1p
10, -0.5, 11);
80 TESTIT_FREXP (-0x1p
5, -0.5, 6);
81 TESTIT_FREXP (-100/3.0, -100/192.0, 6);
82 TESTIT_FREXP (-1.5, -0.75, 1);
83 TESTIT_FREXP (-1.0, -0.5, 1);
84 TESTIT_FREXP (-1/3.0, -2/3.0, -1);
85 TESTIT_FREXP (-1/9.0, -8/9.0, -3);
86 TESTIT_FREXP (-0x1p
-5, -0.5, -4);
87 TESTIT_FREXP (-0x1p
-10, -0.5, -9);
88 TESTIT_FREXP (-0x1p
-20, -0.5, -19);
89 TESTIT_FREXP (-0x1p
-30, -0.5, -29);
90 TESTIT_FREXP (-0x1p
-40, -0.5, -39);
91 TESTIT_FREXP (-0.0, -0.0, 0);
92 TESTIT_FREXP (0.0, 0.0, 0);
93 TESTIT_FREXP (0x1p
-40, 0.5, -39);
94 TESTIT_FREXP (0x1p
-30, 0.5, -29);
95 TESTIT_FREXP (0x1p
-20, 0.5, -19);
96 TESTIT_FREXP (0x1p
-10, 0.5, -9);
97 TESTIT_FREXP (0x1p
-5, 0.5, -4);
98 TESTIT_FREXP (1/9.0, 8/9.0, -3);
99 TESTIT_FREXP (1/3.0, 2/3.0, -1);
100 TESTIT_FREXP (1.0, 0.5, 1);
101 TESTIT_FREXP (1.5, 0.75, 1);
102 TESTIT_FREXP (100/3.0, 100/192.0, 6);
103 TESTIT_FREXP (0x1p
5, 0.5, 6);
104 TESTIT_FREXP (0x1p
10, 0.5, 11);
105 TESTIT_FREXP (0x1p
20, 0.5, 21);
106 TESTIT_FREXP (0x1p
30, 0.5, 31);
107 TESTIT_FREXP (0x1p
40, 0.5, 41);
109 /* Test for frexp(+-Inf,&i) -> +-Inf and frexp(+-NaN,&i) -> +-NaN.
110 Exponent is left unspecified, but we test for side-effects. */
111 TESTIT_FREXP2 ( ,inf
, , isinf
);
112 TESTIT_FREXP2 (- ,inf
, , isinf
);
113 TESTIT_FREXP2 ( ,nan
, "", isnan
);
114 TESTIT_FREXP2 (- ,nan
, "", isnan
);