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