Debian Codegraph @

gcc/testsuite/gcc.target/i386/pr114659.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
3
4 int
5 my_totalorderf (float const *x, float const *y)
6 {
7 int xs = __builtin_signbit (*x);
8 int ys = __builtin_signbit (*y);
9 if (!xs != !ys)
10 return xs;
11
12 int xn = __builtin_isnan (*x);
13 int yn = __builtin_isnan (*y);
14 if (!xn != !yn)
15 return !xn == !xs;
16 if (!xn)
17 return *x <= *y;
18
19 unsigned int extended_sign = -!!xs;
20 union { unsigned int i; float f; } xu = {0}, yu = {0};
21 __builtin_memcpy (&xu.f, x, sizeof (float));
22 __builtin_memcpy (&yu.f, y, sizeof (float));
23 return (xu.i ^ extended_sign) <= (yu.i ^ extended_sign);
24 }
25
26 static float
27 positive_NaNf ()
28 {
29 float volatile nan = 0.0f / 0.0f;
30 return (__builtin_signbit (nan) ? - nan : nan);
31 }
32
33 typedef union { float value; unsigned int word[1]; } memory_float;
34
35 static memory_float
36 construct_memory_SNaNf (float quiet_value)
37 {
38 memory_float m;
39 m.value = quiet_value;
40 m.word[0] ^= (unsigned int) 1 << 22;
41 m.word[0] |= (unsigned int) 1;
42 return m;
43 }
44
45 memory_float x[7] =
46 {
47 { 0 },
48 { 1e-5 },
49 { 1 },
50 { 1e37 },
51 { 1.0f / 0.0f },
52 };
53
54 int
55 main ()
56 {
57 x[5] = construct_memory_SNaNf (positive_NaNf ());
58 x[6] = (memory_float) { positive_NaNf () };
59 if (! my_totalorderf (&x[5].value, &x[6].value))
60 __builtin_abort ();
61 return 0;
62 }