1
2 #ifndef l_fma_main
3 #define l_fma_main
4
5 #if DEBUG
6 #include <stdio.h>
7 #endif
8
9 TYPE m1[32] = {
10 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
11 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
12 };
13 TYPE m2[32] = {
14 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
15 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
16 };
17 TYPE m3[32] = {
18 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
20 };
21 TYPE m4[32];
22 int test_fails = 0;
23
24 void
compare_result(char * title,TYPE * res)25 compare_result(char *title, TYPE *res)
26 {
27 int i;
28 int good = 1;
29 for (i =0; i < 32; i++)
30 if (m4[i] != res[i])
31 {
32 if (good)
33 {
34 #if DEBUG
35 printf ("!!!! %s miscompare\n", title);
36 #endif
37 good = 0;
38 }
39 #if DEBUG
40 printf ("res[%d] = %d, must be %d\n", i, (int)res[i], (int) m4[i]);
41 #endif
42 }
43 if (!good)
44 test_fails = 1;
45 }
46
fma_test()47 static void fma_test ()
48 {
49 test_noneg_add_noneg_add (m1, m2, m3, m4, 32);
50 compare_result ("test0000", res_test0000);
51
52 test_noneg_add_noneg_sub (m1, m2, m3, m4, 32);
53 compare_result ("test0001", res_test0001);
54
55 test_noneg_add_neg_add (m1, m2, m3, m4, 32);
56 compare_result ("test0010", res_test0010);
57
58 test_noneg_add_neg_sub (m1, m2, m3, m4, 32);
59 compare_result ("test0011", res_test0011);
60
61 test_noneg_sub_noneg_add (m1, m2, m3, m4, 32);
62 compare_result ("test0100", res_test0100);
63
64 test_noneg_sub_noneg_sub (m1, m2, m3, m4, 32);
65 compare_result ("test0101", res_test0101);
66
67 test_noneg_sub_neg_add (m1, m2, m3, m4, 32);
68 compare_result ("test0110", res_test0110);
69
70 test_noneg_sub_neg_sub (m1, m2, m3, m4, 32);
71 compare_result ("test0111", res_test0111);
72
73 test_neg_add_noneg_add (m1, m2, m3, m4, 32);
74 compare_result ("test1000", res_test1000);
75
76 test_neg_add_noneg_sub (m1, m2, m3, m4, 32);
77 compare_result ("test1001", res_test1001);
78
79 test_neg_add_neg_add (m1, m2, m3, m4, 32);
80 compare_result ("test1010", res_test1010);
81
82 test_neg_add_neg_sub (m1, m2, m3, m4, 32);
83 compare_result ("test1011", res_test1011);
84
85 test_neg_sub_noneg_add (m1, m2, m3, m4, 32);
86 compare_result ("test1100", res_test1100);
87
88 test_neg_sub_noneg_sub (m1, m2, m3, m4, 32);
89 compare_result ("test1101", res_test1101);
90
91 test_neg_sub_neg_add (m1, m2, m3, m4, 32);
92 compare_result ("test1110", res_test1110);
93
94 test_neg_sub_neg_sub (m1, m2, m3, m4, 32);
95 compare_result ("test1111", res_test1111);
96
97 if (test_fails) abort ();
98 }
99
100 #endif
101