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 
fp_add(float a,float b)11 float fp_add (float a, float b) { return a + b; }
fp_sub(float a,float b)12 float fp_sub (float a, float b) { return a - b; }
fp_mul(float a,float b)13 float fp_mul (float a, float b) { return a * b; }
fp_div(float a,float b)14 float fp_div (float a, float b) { return a / b; }
fp_neg(float a)15 float fp_neg (float a) { return -a; }
16 
dp_add(double a,double b)17 double dp_add (double a, double b) { return a + b; }
dp_sub(double a,double b)18 double dp_sub (double a, double b) { return a - b; }
dp_mul(double a,double b)19 double dp_mul (double a, double b) { return a * b; }
dp_div(double a,double b)20 double dp_div (double a, double b) { return a / b; }
dp_neg(double a)21 double dp_neg (double a) { return -a; }
22 
fp_to_dp(float f)23 double fp_to_dp (float f) { return f; }
dp_to_fp(double d)24 float dp_to_fp (double d) { return d; }
25 
eqsf2(float a,float b)26 int eqsf2 (float a, float b) { return a == b; }
nesf2(float a,float b)27 int nesf2 (float a, float b) { return a != b; }
gtsf2(float a,float b)28 int gtsf2 (float a, float b) { return a > b; }
gesf2(float a,float b)29 int gesf2 (float a, float b) { return a >= b; }
ltsf2(float a,float b)30 int ltsf2 (float a, float b) { return a < b; }
lesf2(float a,float b)31 int lesf2 (float a, float b) { return a <= b; }
32 
eqdf2(double a,double b)33 int eqdf2 (double a, double b) { return a == b; }
nedf2(double a,double b)34 int nedf2 (double a, double b) { return a != b; }
gtdf2(double a,double b)35 int gtdf2 (double a, double b) { return a > b; }
gedf2(double a,double b)36 int gedf2 (double a, double b) { return a >= b; }
ltdf2(double a,double b)37 int ltdf2 (double a, double b) { return a < b; }
ledf2(double a,double b)38 int ledf2 (double a, double b) { return a <= b; }
39 
floatsisf(int i)40 float floatsisf (int i) { return i; }
floatsidf(int i)41 double floatsidf (int i) { return i; }
fixsfsi(float f)42 int fixsfsi (float f) { return f; }
fixdfsi(double d)43 int fixdfsi (double d) { return d; }
fixunssfsi(float f)44 unsigned int fixunssfsi (float f) { return f; }
fixunsdfsi(double d)45 unsigned int fixunsdfsi (double d) { return d; }
46 
47 int fail_count = 0;
48 
49 int
fail(char * msg)50 fail (char *msg)
51 {
52   fail_count++;
53   fprintf (stderr, "Test failed: %s\n", msg);
54 }
55 
56 int
main()57 main()
58 {
59   if (fp_add (1, 1) != 2) fail ("fp_add 1+1");
60   if (fp_sub (3, 2) != 1) fail ("fp_sub 3-2");
61   if (fp_mul (2, 3) != 6) fail ("fp_mul 2*3");
62   if (fp_div (3, 2) != 1.5) fail ("fp_div 3/2");
63   if (fp_neg (1) != -1) fail ("fp_neg 1");
64 
65   if (dp_add (1, 1) != 2) fail ("dp_add 1+1");
66   if (dp_sub (3, 2) != 1) fail ("dp_sub 3-2");
67   if (dp_mul (2, 3) != 6) fail ("dp_mul 2*3");
68   if (dp_div (3, 2) != 1.5) fail ("dp_div 3/2");
69   if (dp_neg (1) != -1) fail ("dp_neg 1");
70 
71   if (fp_to_dp (1.5) != 1.5) fail ("fp_to_dp 1.5");
72   if (dp_to_fp (1.5) != 1.5) fail ("dp_to_fp 1.5");
73 
74   if (floatsisf (1) != 1) fail ("floatsisf 1");
75   if (floatsidf (1) != 1) fail ("floatsidf 1");
76   if (fixsfsi (1.42) != 1) fail ("fixsfsi 1.42");
77   if (fixunssfsi (1.42) != 1) fail ("fixunssfsi 1.42");
78   if (fixdfsi (1.42) != 1) fail ("fixdfsi 1.42");
79   if (fixunsdfsi (1.42) != 1) fail ("fixunsdfsi 1.42");
80 
81   if (eqsf2 (1, 1) == 0) fail ("eqsf2 1==1");
82   if (eqsf2 (1, 2) != 0) fail ("eqsf2 1==2");
83   if (nesf2 (1, 2) == 0) fail ("nesf2 1!=1");
84   if (nesf2 (1, 1) != 0) fail ("nesf2 1!=1");
85   if (gtsf2 (2, 1) == 0) fail ("gtsf2 2>1");
86   if (gtsf2 (1, 1) != 0) fail ("gtsf2 1>1");
87   if (gtsf2 (0, 1) != 0) fail ("gtsf2 0>1");
88   if (gesf2 (2, 1) == 0) fail ("gesf2 2>=1");
89   if (gesf2 (1, 1) == 0) fail ("gesf2 1>=1");
90   if (gesf2 (0, 1) != 0) fail ("gesf2 0>=1");
91   if (ltsf2 (1, 2) == 0) fail ("ltsf2 1<2");
92   if (ltsf2 (1, 1) != 0) fail ("ltsf2 1<1");
93   if (ltsf2 (1, 0) != 0) fail ("ltsf2 1<0");
94   if (lesf2 (1, 2) == 0) fail ("lesf2 1<=2");
95   if (lesf2 (1, 1) == 0) fail ("lesf2 1<=1");
96   if (lesf2 (1, 0) != 0) fail ("lesf2 1<=0");
97 
98   if (fail_count != 0)
99     abort ();
100   exit (0);
101 }
102