Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/gofast.c

raw
1 /* { dg-skip-if "requires io" { freestanding } } */
2
3 /* Program to test gcc's usage of the gofast library. */
4
5 /* The main guiding themes are to make it trivial to add test cases over time
6 and to make it easy for a program to parse the output to see if the right
7 libcalls are being made. */
8
9 #include <stdio.h>
10
11 void abort (void);
12 void exit (int);
13
14 float fp_add (float a, float b) { return a + b; }
15 float fp_sub (float a, float b) { return a - b; }
16 float fp_mul (float a, float b) { return a * b; }
17 float fp_div (float a, float b) { return a / b; }
18 float fp_neg (float a) { return -a; }
19
20 double dp_add (double a, double b) { return a + b; }
21 double dp_sub (double a, double b) { return a - b; }
22 double dp_mul (double a, double b) { return a * b; }
23 double dp_div (double a, double b) { return a / b; }
24 double dp_neg (double a) { return -a; }
25
26 double fp_to_dp (float f) { return f; }
27 float dp_to_fp (double d) { return d; }
28
29 int eqsf2 (float a, float b) { return a == b; }
30 int nesf2 (float a, float b) { return a != b; }
31 int gtsf2 (float a, float b) { return a > b; }
32 int gesf2 (float a, float b) { return a >= b; }
33 int ltsf2 (float a, float b) { return a < b; }
34 int lesf2 (float a, float b) { return a <= b; }
35
36 int eqdf2 (double a, double b) { return a == b; }
37 int nedf2 (double a, double b) { return a != b; }
38 int gtdf2 (double a, double b) { return a > b; }
39 int gedf2 (double a, double b) { return a >= b; }
40 int ltdf2 (double a, double b) { return a < b; }
41 int ledf2 (double a, double b) { return a <= b; }
42
43 float floatsisf (int i) { return i; }
44 double floatsidf (int i) { return i; }
45 int fixsfsi (float f) { return f; }
46 int fixdfsi (double d) { return d; }
47 unsigned int fixunssfsi (float f) { return f; }
48 unsigned int fixunsdfsi (double d) { return d; }
49
50 int fail_count = 0;
51
52 int
53 fail (char *msg)
54 {
55 fail_count++;
56 fprintf (stderr, "Test failed: %s\n", msg);
57 }
58
59 int
60 main()
61 {
62 if (fp_add (1, 1) != 2) fail ("fp_add 1+1");
63 if (fp_sub (3, 2) != 1) fail ("fp_sub 3-2");
64 if (fp_mul (2, 3) != 6) fail ("fp_mul 2*3");
65 if (fp_div (3, 2) != 1.5) fail ("fp_div 3/2");
66 if (fp_neg (1) != -1) fail ("fp_neg 1");
67
68 if (dp_add (1, 1) != 2) fail ("dp_add 1+1");
69 if (dp_sub (3, 2) != 1) fail ("dp_sub 3-2");
70 if (dp_mul (2, 3) != 6) fail ("dp_mul 2*3");
71 if (dp_div (3, 2) != 1.5) fail ("dp_div 3/2");
72 if (dp_neg (1) != -1) fail ("dp_neg 1");
73
74 if (fp_to_dp (1.5) != 1.5) fail ("fp_to_dp 1.5");
75 if (dp_to_fp (1.5) != 1.5) fail ("dp_to_fp 1.5");
76
77 if (floatsisf (1) != 1) fail ("floatsisf 1");
78 if (floatsidf (1) != 1) fail ("floatsidf 1");
79 if (fixsfsi (1.42) != 1) fail ("fixsfsi 1.42");
80 if (fixunssfsi (1.42) != 1) fail ("fixunssfsi 1.42");
81 if (fixdfsi (1.42) != 1) fail ("fixdfsi 1.42");
82 if (fixunsdfsi (1.42) != 1) fail ("fixunsdfsi 1.42");
83
84 if (eqsf2 (1, 1) == 0) fail ("eqsf2 1==1");
85 if (eqsf2 (1, 2) != 0) fail ("eqsf2 1==2");
86 if (nesf2 (1, 2) == 0) fail ("nesf2 1!=1");
87 if (nesf2 (1, 1) != 0) fail ("nesf2 1!=1");
88 if (gtsf2 (2, 1) == 0) fail ("gtsf2 2>1");
89 if (gtsf2 (1, 1) != 0) fail ("gtsf2 1>1");
90 if (gtsf2 (0, 1) != 0) fail ("gtsf2 0>1");
91 if (gesf2 (2, 1) == 0) fail ("gesf2 2>=1");
92 if (gesf2 (1, 1) == 0) fail ("gesf2 1>=1");
93 if (gesf2 (0, 1) != 0) fail ("gesf2 0>=1");
94 if (ltsf2 (1, 2) == 0) fail ("ltsf2 1<2");
95 if (ltsf2 (1, 1) != 0) fail ("ltsf2 1<1");
96 if (ltsf2 (1, 0) != 0) fail ("ltsf2 1<0");
97 if (lesf2 (1, 2) == 0) fail ("lesf2 1<=2");
98 if (lesf2 (1, 1) == 0) fail ("lesf2 1<=1");
99 if (lesf2 (1, 0) != 0) fail ("lesf2 1<=0");
100
101 if (fail_count != 0)
102 abort ();
103 exit (0);
104 }