2018-05-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / fpprec-1.c
blob1c17c1d10a00bdbd4168be17e810ca5806734dc2
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fno-math-errno -fno-trapping-math -msse2 -mfpmath=sse" } */
3 /* { dg-require-effective-target sse2 } */
5 #include "sse2-check.h"
7 double x[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
8 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023, /* +-DBL_MAX */
9 -0x1p-52, 0x1p-52, /* +-DBL_EPSILON */
10 /* nextafter/before 0.5, 1.0 and 1.5 */
11 0x1.0000000000001p-1, 0x1.fffffffffffffp-2,
12 0x1.0000000000001p+0, 0x1.fffffffffffffp-1,
13 0x1.8000000000001p+0, 0x1.7ffffffffffffp+0,
14 -0.0, 0.0, -0.5, 0.5, -1.0, 1.0, -1.5, 1.5, -2.0, 2.0,
15 -2.5, 2.5 };
16 #define NUM (sizeof(x)/sizeof(double))
18 double expect_round[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
19 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
20 -0.0, 0.0,
21 1.0, 0.0, 1.0, 1.0, 2.0, 1.0,
22 -0.0, 0.0, -1.0, 1.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0,
23 -3.0, 3.0 };
25 double expect_rint[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
26 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
27 -0.0, 0.0,
28 1.0, 0.0, 1.0, 1.0, 2.0, 1.0,
29 -0.0, 0.0, -0.0, 0.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0,
30 -2.0, 2.0 };
32 double expect_floor[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
33 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
34 -1.0, 0.0,
35 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
36 -0.0, 0.0, -1.0, 0.0, -1.0, 1.0, -2.0, 1.0, -2.0, 2.0,
37 -3.0, 2.0 };
39 double expect_ceil[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
40 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
41 -0.0, 1.0,
42 1.0, 1.0, 2.0, 1.0, 2.0, 2.0,
43 -0.0, 0.0, -0.0, 1.0, -1.0, 1.0, -1.0, 2.0, -2.0, 2.0,
44 -2.0, 3.0 };
46 double expect_trunc[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
47 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
48 -0.0, 0.0,
49 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
50 -0.0, 0.0, -0.0, 0.0, -1.0, 1.0, -1.0, 1.0, -2.0, 2.0,
51 -2.0, 2.0 };
54 #define CHECK(fn) \
55 void check_ ## fn (void) \
56 { \
57 int i; \
58 for (i = 0; i < NUM; ++i) \
59 { \
60 double res = __builtin_ ## fn (x[i]); \
61 if (__builtin_memcmp (&res, &expect_ ## fn [i], sizeof(double)) != 0) \
62 printf( # fn " [%i]: %.18e %.18e\n", i, expect_ ## fn [i], res), abort (); \
63 } \
66 CHECK(round)
67 CHECK(rint)
68 CHECK(floor)
69 CHECK(ceil)
70 CHECK(trunc)
72 static void
73 sse2_test (void)
75 check_round ();
76 check_rint ();
77 check_floor ();
78 check_ceil ();
79 check_trunc ();