Update dgemm_kernel_4x8_haswell.S
[platform/upstream/openblas.git] / utest / test_rotmg.c
1 /*****************************************************************************
2 Copyright (c) 2011-2014, The OpenBLAS Project
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9    1. Redistributions of source code must retain the above copyright
10       notice, this list of conditions and the following disclaimer.
11
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the
15       distribution.
16    3. Neither the name of the OpenBLAS project nor the names of 
17       its contributors may be used to endorse or promote products 
18       derived from this software without specific prior written 
19       permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 **********************************************************************************/
33
34 #include "openblas_utest.h"
35
36 CTEST (drotmg,rotmg)
37 {
38         double te_d1, tr_d1;
39         double te_d2, tr_d2;
40         double te_x1, tr_x1;
41         double te_y1, tr_y1;
42         double te_param[5];
43         double tr_param[5];
44         int i=0;
45         // original test case for libGoto bug fixed by feb2014 rewrite
46         te_d1= 0.21149573940783739;
47         te_d2= 0.046892057172954082;
48         te_x1= -0.42272687517106533;
49         te_y1= 0.42211309121921659;
50
51
52         for(i=0; i<5; i++){
53           te_param[i]=tr_param[i]=0.0;
54         }
55
56         //reference values as calculated by netlib blas
57
58         tr_d1= 0.1732048;
59         tr_d2= 0.03840234;
60         tr_x1= -0.516180;
61         tr_y1= 0.422113;
62         tr_d1= 0.17320483687975;
63         tr_d2= 0.03840233915037;
64         tr_x1= -0.51618034832329;
65         tr_y1= 0.42211309121922;
66
67         tr_param[0]= 0.0;
68         tr_param[1]= 0.0;
69         tr_param[2]= 0.99854803659786; 
70         tr_param[3]= -0.22139439665872;
71         tr_param[4]= 0.0;
72
73         BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
74         ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
75         ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
76         ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
77         ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
78
79         for(i=0; i<5; i++){
80                 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
81         }
82 }
83
84 CTEST (drotmg,rotmg_issue1452)
85 {
86         double te_d1, tr_d1;
87         double te_d2, tr_d2;
88         double te_x1, tr_x1;
89         double te_y1, tr_y1;
90         double te_param[5];
91         double tr_param[5];
92         int i=0;
93
94         // from issue #1452
95         te_d1 = 5.9e-8;
96         te_d2 = 5.960464e-8;
97         te_x1 = 1.0;
98         te_y1 = 150.0;
99
100         for(i=0; i<5; i++){
101           te_param[i]=tr_param[i]=0.0;
102         }
103         te_param[3]=1./4096.;
104         //reference values as calculated by gonum blas with rotmg rewritten to Hopkins' algorithm
105         tr_d1= 0.99995592822897;
106         tr_d2= 0.98981219860583;
107         tr_x1= 0.03662270484346;
108         tr_y1= 150.000000000000;
109
110         tr_param[0]= -1.0;
111         tr_param[1]= 0.00000161109346;
112         tr_param[2]= -0.00024414062500;
113         tr_param[3]= 0.00024414062500;
114         tr_param[4]= 0.00000162760417;
115
116         //OpenBLAS
117         BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
118
119         ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
120         ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
121         ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
122         ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
123
124         for(i=0; i<5; i++){
125                 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
126         }
127
128 }
129
130 CTEST(drotmg, rotmg_D1eqD2_X1eqX2)
131 {
132         double te_d1, tr_d1;
133         double te_d2, tr_d2;
134         double te_x1, tr_x1;
135         double te_y1, tr_y1;
136         double te_param[5];
137         double tr_param[5];
138         int i=0;
139         te_d1= tr_d1=2.;
140         te_d2= tr_d2=2.;
141         te_x1= tr_x1=8.;
142         te_y1= tr_y1=8.;
143
144         for(i=0; i<5; i++){
145           te_param[i]=tr_param[i]=0.0;
146         }
147         
148         //reference values as calculated by netlib blas
149         tr_d1= 1.0;
150         tr_d2= 1.0;
151         tr_x1= 16.0;
152         tr_y1= 8.0;
153
154         tr_param[0]=1.0;
155         tr_param[1]=1.0;
156         tr_param[2]=0.0;
157         tr_param[3]=0.0;
158         tr_param[4]=1.0;
159
160         //OpenBLAS
161         BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
162
163         ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
164         ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
165         ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
166         ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
167
168         for(i=0; i<5; i++){
169                 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
170         }
171 }
172
173 CTEST(drotmg, drotmg_D1_big_D2_big_flag_zero)
174 {
175         double te_d1, tr_d1;
176         double te_d2, tr_d2;
177         double te_x1, tr_x1;
178         double te_y1, tr_y1;
179         double te_param[5]={1.,4096.,-4096.,1.,4096.};
180         double tr_param[5]={-1.,4096.,-3584.,1792.,4096.};
181         int i=0;
182         te_d1= tr_d1=1600000000.;
183         te_d2= tr_d2=800000000.;
184         te_x1= tr_x1=8.;
185         te_y1= tr_y1=7.;
186
187         
188         //reference values as calculated by gonum 
189         tr_d1= 68.96627824858757;
190         tr_d2= 34.483139124293785;
191         tr_x1= 45312.;
192         tr_y1= 7.0;
193
194
195         //OpenBLAS
196         BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
197
198         ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
199         ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
200         ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
201         ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
202
203         for(i=0; i<5; i++){
204                 ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
205         }
206 }