1 |
689 |
jeremybenn |
/* Copyright (C) 2007 Free Software Foundation.
|
2 |
|
|
|
3 |
|
|
Verify that built-in folding of ldexp et al. is correctly performed
|
4 |
|
|
by the compiler.
|
5 |
|
|
|
6 |
|
|
Origin: Kaveh R. Ghazi, February 17, 2007. */
|
7 |
|
|
|
8 |
|
|
/* { dg-do link } */
|
9 |
|
|
/* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
|
10 |
|
|
|
11 |
|
|
extern void link_error(int);
|
12 |
|
|
|
13 |
|
|
/* Return TRUE if the sign of X != sign of Y. This is important when
|
14 |
|
|
comparing signed zeros. */
|
15 |
|
|
#define CKSGN_F(X,Y) \
|
16 |
|
|
(__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
|
17 |
|
|
#define CKSGN(X,Y) \
|
18 |
|
|
(__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
|
19 |
|
|
#define CKSGN_L(X,Y) \
|
20 |
|
|
(__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
|
21 |
|
|
|
22 |
|
|
/* Test that FUNC(ARG1,ARG2) == RES. Check the sign for -0.0. */
|
23 |
|
|
#define TESTIT(FUNC,ARG1,ARG2,RES) do { \
|
24 |
|
|
if (__builtin_##FUNC##f(ARG1##f,ARG2) != RES##f \
|
25 |
|
|
|| CKSGN_F(__builtin_##FUNC##f(ARG1##f,ARG2),RES##f)) \
|
26 |
|
|
link_error(__LINE__); \
|
27 |
|
|
if (__builtin_##FUNC(ARG1,ARG2) != RES \
|
28 |
|
|
|| CKSGN(__builtin_##FUNC(ARG1,ARG2),RES)) \
|
29 |
|
|
link_error(__LINE__); \
|
30 |
|
|
if (__builtin_##FUNC##l(ARG1##l,ARG2) != RES##l \
|
31 |
|
|
|| CKSGN_L(__builtin_##FUNC##l(ARG1##l,ARG2),RES##l)) \
|
32 |
|
|
link_error(__LINE__); \
|
33 |
|
|
} while (0)
|
34 |
|
|
|
35 |
|
|
/* Test that (long)FUNC(ARG1,ARG2) == (long)RES. The cast is
|
36 |
|
|
necessary when RES is not a constant. */
|
37 |
|
|
#define TESTIT2(FUNC,ARG1,ARG2,RES) do { \
|
38 |
|
|
if ((long)__builtin_##FUNC##f(ARG1##f,ARG2) != (long)RES##f) \
|
39 |
|
|
link_error(__LINE__); \
|
40 |
|
|
if ((long)__builtin_##FUNC(ARG1,ARG2) != (long)RES) \
|
41 |
|
|
link_error(__LINE__); \
|
42 |
|
|
if ((long)__builtin_##FUNC##l(ARG1##l,ARG2) != (long)RES##l) \
|
43 |
|
|
link_error(__LINE__); \
|
44 |
|
|
} while (0)
|
45 |
|
|
|
46 |
|
|
/* Test that FUNCRES(FUNC(NEG FUNCARG(ARGARG),ARG2)) is false. Check
|
47 |
|
|
the sign as well. */
|
48 |
|
|
#ifndef __SPU__
|
49 |
|
|
#define TESTIT3(FUNC,NEG,FUNCARG,ARGARG,ARG2,FUNCRES) do { \
|
50 |
|
|
if (!__builtin_##FUNCRES##f(__builtin_##FUNC##f(NEG __builtin_##FUNCARG##f(ARGARG),ARG2)) \
|
51 |
|
|
|| CKSGN_F(__builtin_##FUNC##f(NEG __builtin_##FUNCARG##f(ARGARG),ARG2), NEG __builtin_##FUNCARG##f(ARGARG))) \
|
52 |
|
|
link_error(__LINE__); \
|
53 |
|
|
if (!__builtin_##FUNCRES(__builtin_##FUNC(NEG __builtin_##FUNCARG(ARGARG),ARG2)) \
|
54 |
|
|
|| CKSGN(__builtin_##FUNC(NEG __builtin_##FUNCARG(ARGARG),ARG2), NEG __builtin_##FUNCARG(ARGARG))) \
|
55 |
|
|
link_error(__LINE__); \
|
56 |
|
|
if (!__builtin_##FUNCRES##l(__builtin_##FUNC##l(NEG __builtin_##FUNCARG##l(ARGARG),ARG2)) \
|
57 |
|
|
|| CKSGN_L(__builtin_##FUNC##l(NEG __builtin_##FUNCARG##l(ARGARG),ARG2), NEG __builtin_##FUNCARG##l(ARGARG))) \
|
58 |
|
|
link_error(__LINE__); \
|
59 |
|
|
} while (0)
|
60 |
|
|
#else
|
61 |
|
|
#define TESTIT3(FUNC,NEG,FUNCARG,ARGARG,ARG2,FUNCRES) do { \
|
62 |
|
|
/* SPU single-precision floating point format does not support Inf or Nan. */ \
|
63 |
|
|
if (!__builtin_##FUNCRES(__builtin_##FUNC(NEG __builtin_##FUNCARG(ARGARG),ARG2)) \
|
64 |
|
|
|| CKSGN(__builtin_##FUNC(NEG __builtin_##FUNCARG(ARGARG),ARG2), NEG __builtin_##FUNCARG(ARGARG))) \
|
65 |
|
|
link_error(__LINE__); \
|
66 |
|
|
if (!__builtin_##FUNCRES##l(__builtin_##FUNC##l(NEG __builtin_##FUNCARG##l(ARGARG),ARG2)) \
|
67 |
|
|
|| CKSGN_L(__builtin_##FUNC##l(NEG __builtin_##FUNCARG##l(ARGARG),ARG2), NEG __builtin_##FUNCARG##l(ARGARG))) \
|
68 |
|
|
link_error(__LINE__); \
|
69 |
|
|
} while (0)
|
70 |
|
|
#endif
|
71 |
|
|
|
72 |
|
|
/* Using foo==MIN/MAX float values, test that FUNC(foo,EXP) == foo*exp2(EXP),
|
73 |
|
|
and also that FUNC(foo,-EXP) == foo*exp2(-EXP). */
|
74 |
|
|
#define TESTIT4(FUNC,EXP) do { \
|
75 |
|
|
if (__builtin_##FUNC##f(__FLT_MIN__,EXP) != __FLT_MIN__*__builtin_exp2f(EXP)) \
|
76 |
|
|
link_error(__LINE__); \
|
77 |
|
|
if (__builtin_##FUNC##f(-__FLT_MIN__,EXP) != -__FLT_MIN__*__builtin_exp2f(EXP)) \
|
78 |
|
|
link_error(__LINE__); \
|
79 |
|
|
if (__builtin_##FUNC(__DBL_MIN__,EXP) != __DBL_MIN__*__builtin_exp2(EXP)) \
|
80 |
|
|
link_error(__LINE__); \
|
81 |
|
|
if (__builtin_##FUNC(-__DBL_MIN__,EXP) != -__DBL_MIN__*__builtin_exp2(EXP)) \
|
82 |
|
|
link_error(__LINE__); \
|
83 |
|
|
if (__builtin_##FUNC##l(__LDBL_MIN__,EXP) != __LDBL_MIN__*__builtin_exp2l(EXP)) \
|
84 |
|
|
link_error(__LINE__); \
|
85 |
|
|
if (__builtin_##FUNC##l(-__LDBL_MIN__,EXP) != -__LDBL_MIN__*__builtin_exp2l(EXP)) \
|
86 |
|
|
link_error(__LINE__); \
|
87 |
|
|
if (__builtin_##FUNC##f(__FLT_MAX__,-EXP) != __FLT_MAX__*__builtin_exp2f(-EXP)) \
|
88 |
|
|
link_error(__LINE__); \
|
89 |
|
|
if (__builtin_##FUNC##f(-__FLT_MAX__,-EXP) != -__FLT_MAX__*__builtin_exp2f(-EXP)) \
|
90 |
|
|
link_error(__LINE__); \
|
91 |
|
|
if (__builtin_##FUNC(__DBL_MAX__,-EXP) != __DBL_MAX__*__builtin_exp2(-EXP)) \
|
92 |
|
|
link_error(__LINE__); \
|
93 |
|
|
if (__builtin_##FUNC(-__DBL_MAX__,-EXP) != -__DBL_MAX__*__builtin_exp2(-EXP)) \
|
94 |
|
|
link_error(__LINE__); \
|
95 |
|
|
if (__builtin_##FUNC##l(__LDBL_MAX__,-EXP) != __LDBL_MAX__*__builtin_exp2l(-EXP)) \
|
96 |
|
|
link_error(__LINE__); \
|
97 |
|
|
if (__builtin_##FUNC##l(-__LDBL_MAX__,-EXP) != -__LDBL_MAX__*__builtin_exp2l(-EXP)) \
|
98 |
|
|
link_error(__LINE__); \
|
99 |
|
|
} while (0)
|
100 |
|
|
|
101 |
|
|
void __attribute__ ((__noinline__))
|
102 |
|
|
foo(float xf, double x, long double xl, int i, long l)
|
103 |
|
|
{
|
104 |
|
|
/* f(0.0, i) -> 0.0 and f(-0.0, i) -> -0.0. */
|
105 |
|
|
TESTIT (ldexp, 0.0, i, 0.0);
|
106 |
|
|
TESTIT (ldexp, -0.0, i, -0.0);
|
107 |
|
|
TESTIT (scalbn, 0.0, i, 0.0);
|
108 |
|
|
TESTIT (scalbn, -0.0, i, -0.0);
|
109 |
|
|
TESTIT (scalbln, 0.0, l, 0.0);
|
110 |
|
|
TESTIT (scalbln, -0.0, l, -0.0);
|
111 |
|
|
|
112 |
|
|
/* f(x,0) -> x. */
|
113 |
|
|
TESTIT2 (ldexp, x, 0, x);
|
114 |
|
|
TESTIT2 (scalbn, x, 0, x);
|
115 |
|
|
TESTIT2 (scalbln, x, 0, x);
|
116 |
|
|
|
117 |
|
|
/* f(Inf,i) -> Inf and f(NaN,i) -> NaN. */
|
118 |
|
|
TESTIT3 (ldexp, , inf, , i, isinf);
|
119 |
|
|
TESTIT3 (ldexp, -, inf, , i, isinf);
|
120 |
|
|
TESTIT3 (ldexp, , nan, "", i, isnan);
|
121 |
|
|
TESTIT3 (ldexp, -, nan, "", i, isnan);
|
122 |
|
|
|
123 |
|
|
TESTIT3 (scalbn, , inf, , i, isinf);
|
124 |
|
|
TESTIT3 (scalbn, -, inf, , i, isinf);
|
125 |
|
|
TESTIT3 (scalbn, , nan, "", i, isnan);
|
126 |
|
|
TESTIT3 (scalbn, -, nan, "", i, isnan);
|
127 |
|
|
|
128 |
|
|
TESTIT3 (scalbln, , inf, , i, isinf);
|
129 |
|
|
TESTIT3 (scalbln, -, inf, , i, isinf);
|
130 |
|
|
TESTIT3 (scalbln, , nan, "", i, isnan);
|
131 |
|
|
TESTIT3 (scalbln, -, nan, "", i, isnan);
|
132 |
|
|
|
133 |
|
|
/* Evaluate when both arguments are constant. */
|
134 |
|
|
TESTIT (ldexp, 5.0, 3, 40.0);
|
135 |
|
|
TESTIT (ldexp, -5.0, 3, -40.0);
|
136 |
|
|
TESTIT (ldexp, 5.0, -3, 0.625);
|
137 |
|
|
TESTIT (ldexp, -5.0, -3, -0.625);
|
138 |
|
|
|
139 |
|
|
TESTIT (ldexp, 1000.0, 5, 32000.0);
|
140 |
|
|
TESTIT (ldexp, -1000.0, 5, -32000.0);
|
141 |
|
|
TESTIT (ldexp, 1000.0, -5, 31.25);
|
142 |
|
|
TESTIT (ldexp, -1000.0, -5, -31.25);
|
143 |
|
|
|
144 |
|
|
/* f(x,N) -> x*exp2(N), using MIN/MAX constants for x and constant N. */
|
145 |
|
|
TESTIT4 (ldexp, 1);
|
146 |
|
|
TESTIT4 (ldexp, 2);
|
147 |
|
|
TESTIT4 (ldexp, 3);
|
148 |
|
|
TESTIT4 (ldexp, 5);
|
149 |
|
|
TESTIT4 (ldexp, 9);
|
150 |
|
|
TESTIT4 (ldexp, 10);
|
151 |
|
|
TESTIT4 (ldexp, 12);
|
152 |
|
|
TESTIT4 (ldexp, 18);
|
153 |
|
|
TESTIT4 (ldexp, 25);
|
154 |
|
|
TESTIT4 (ldexp, 50);
|
155 |
|
|
TESTIT4 (ldexp, 75);
|
156 |
|
|
TESTIT4 (ldexp, 100);
|
157 |
|
|
TESTIT4 (ldexp, 123);
|
158 |
|
|
|
159 |
|
|
/* These are folded when float radix is two. */
|
160 |
|
|
#if __FLT_RADIX__ == 2
|
161 |
|
|
TESTIT (scalbn, 5.0, 3, 40.0);
|
162 |
|
|
TESTIT (scalbn, -5.0, 3, -40.0);
|
163 |
|
|
TESTIT (scalbn, 5.0, -3, 0.625);
|
164 |
|
|
TESTIT (scalbn, -5.0, -3, -0.625);
|
165 |
|
|
|
166 |
|
|
TESTIT (scalbn, 1000.0, 5, 32000.0);
|
167 |
|
|
TESTIT (scalbn, -1000.0, 5, -32000.0);
|
168 |
|
|
TESTIT (scalbn, 1000.0, -5, 31.25);
|
169 |
|
|
TESTIT (scalbn, -1000.0, -5, -31.25);
|
170 |
|
|
|
171 |
|
|
TESTIT4 (scalbn, 1);
|
172 |
|
|
TESTIT4 (scalbn, 2);
|
173 |
|
|
TESTIT4 (scalbn, 3);
|
174 |
|
|
TESTIT4 (scalbn, 5);
|
175 |
|
|
TESTIT4 (scalbn, 9);
|
176 |
|
|
TESTIT4 (scalbn, 10);
|
177 |
|
|
TESTIT4 (scalbn, 12);
|
178 |
|
|
TESTIT4 (scalbn, 18);
|
179 |
|
|
TESTIT4 (scalbn, 25);
|
180 |
|
|
TESTIT4 (scalbn, 50);
|
181 |
|
|
TESTIT4 (scalbn, 75);
|
182 |
|
|
TESTIT4 (scalbn, 100);
|
183 |
|
|
TESTIT4 (scalbn, 123);
|
184 |
|
|
|
185 |
|
|
TESTIT (scalbln, 5.0, 3, 40.0);
|
186 |
|
|
TESTIT (scalbln, -5.0, 3, -40.0);
|
187 |
|
|
TESTIT (scalbln, 5.0, -3, 0.625);
|
188 |
|
|
TESTIT (scalbln, -5.0, -3, -0.625);
|
189 |
|
|
|
190 |
|
|
TESTIT (scalbln, 1000.0, 5, 32000.0);
|
191 |
|
|
TESTIT (scalbln, -1000.0, 5, -32000.0);
|
192 |
|
|
TESTIT (scalbln, 1000.0, -5, 31.25);
|
193 |
|
|
TESTIT (scalbln, -1000.0, -5, -31.25);
|
194 |
|
|
|
195 |
|
|
TESTIT4 (scalbln, 1);
|
196 |
|
|
TESTIT4 (scalbln, 2);
|
197 |
|
|
TESTIT4 (scalbln, 3);
|
198 |
|
|
TESTIT4 (scalbln, 5);
|
199 |
|
|
TESTIT4 (scalbln, 9);
|
200 |
|
|
TESTIT4 (scalbln, 10);
|
201 |
|
|
TESTIT4 (scalbln, 12);
|
202 |
|
|
TESTIT4 (scalbln, 18);
|
203 |
|
|
TESTIT4 (scalbln, 25);
|
204 |
|
|
TESTIT4 (scalbln, 50);
|
205 |
|
|
TESTIT4 (scalbln, 75);
|
206 |
|
|
TESTIT4 (scalbln, 100);
|
207 |
|
|
TESTIT4 (scalbln, 123);
|
208 |
|
|
#endif
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
int main()
|
212 |
|
|
{
|
213 |
|
|
foo (0, 0, 0, 0, 0);
|
214 |
|
|
|
215 |
|
|
return 0;
|
216 |
|
|
}
|