1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "op_spreadsheet.hxx"
12 #include "formulagroup.hxx"
13 #include "document.hxx"
14 #include "formulacell.hxx"
15 #include "tokenarray.hxx"
16 #include "compiler.hxx"
17 #include "interpre.hxx"
18 #include <formula/vectortoken.hxx>
21 using namespace formula
;
23 namespace sc
{ namespace opencl
{
25 void OpVLookup::GenSlidingWindowFunction(std::stringstream
&ss
,
26 const std::string
&sSymName
, SubArguments
&vSubArguments
)
28 ss
<< "\ndouble " << sSymName
;
29 ss
<< "_"<< BinFuncName() <<"(";
30 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
34 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
37 ss
<< " int gid0=get_global_id(0);\n";
38 ss
<< " double tmp = CreateDoubleError(NOTAVAILABLE);\n";
39 ss
<< " double intermediate = DBL_MAX;\n";
40 ss
<< " int singleIndex = gid0;\n";
41 ss
<< " int rowNum = -1;\n";
43 GenTmpVariables(ss
,vSubArguments
);
45 CheckSubArgumentIsNan(ss
,vSubArguments
,arg
++);
46 int secondParaWidth
= 1;
48 if (vSubArguments
[1]->GetFormulaToken()->GetType() == formula::svDoubleVectorRef
)
50 FormulaToken
*tmpCur
= vSubArguments
[1]->GetFormulaToken();
51 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const formula::DoubleVectorRefToken
*>(tmpCur
);
52 secondParaWidth
= pCurDVR
->GetArrays().size();
55 arg
+= secondParaWidth
;
56 CheckSubArgumentIsNan(ss
,vSubArguments
,arg
++);
58 if (vSubArguments
.size() == (unsigned int)(3+(secondParaWidth
-1)))
61 ss
<< 3+(secondParaWidth
-1);
66 CheckSubArgumentIsNan(ss
,vSubArguments
,arg
++);
69 if (vSubArguments
[1]->GetFormulaToken()->GetType() == formula::svDoubleVectorRef
)
71 FormulaToken
*tmpCur
= vSubArguments
[1]->GetFormulaToken();
72 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const formula::DoubleVectorRefToken
*>(tmpCur
);
73 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() < pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength() : pCurDVR
->GetRefRowSize() ;
76 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
78 ss
<< " loop = ("<<nCurWindowSize
<<" - gid0)/";
79 ss
<< unrollSize
<<";\n";
82 else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
84 ss
<< " loop = ("<<nCurWindowSize
<<" + gid0)/";
85 ss
<< unrollSize
<<";\n";
90 ss
<< " loop = "<<nCurWindowSize
<<"/"<< unrollSize
<<";\n";
93 for (int i
= 0; i
< secondParaWidth
; i
++)
95 ss
<< " for ( int j = 0;j< loop; j++)\n";
98 if (!pCurDVR
->IsStartFixed()&& pCurDVR
->IsEndFixed())
100 ss
<< "gid0 + j * "<< unrollSize
<<";\n";
104 ss
<< "j * "<< unrollSize
<<";\n";
106 if (!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
108 ss
<< " int doubleIndex = i+gid0;\n";
112 ss
<< " int doubleIndex = i;\n";
115 ss
<< 3+(secondParaWidth
-1);
119 for (int j
= 0;j
< unrollSize
; j
++)
121 CheckSubArgumentIsNan(ss
,vSubArguments
,1+i
);
123 ss
<< " if((tmp0 - tmp";
125 ss
<< ")>=0 && intermediate > ( tmp0 -tmp";
129 ss
<< " rowNum = doubleIndex;\n";
130 ss
<< " intermediate = tmp0 - tmp";
135 ss
<< " doubleIndex++;\n";
140 for (int j
= 0; j
< unrollSize
; j
++)
142 CheckSubArgumentIsNan(ss
,vSubArguments
,1+i
);
144 ss
<< " if(tmp0 == tmp";
146 ss
<< " && rowNum == -1)\n";
148 ss
<< " rowNum = doubleIndex;\n";
151 ss
<< " doubleIndex++;\n";
156 ss
<< " if(rowNum!=-1)\n";
158 for (int j
= 0; j
< secondParaWidth
; j
++)
161 ss
<< 2+(secondParaWidth
-1);
166 vSubArguments
[1+j
]->GenDeclRef(ss
);
169 ss
<< " return tmp;\n";
171 ss
<< " for (int i = ";
172 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
174 ss
<< "gid0 + loop *"<<unrollSize
<<"; i < ";
175 ss
<< nCurWindowSize
<<"; i++)\n";
177 else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
179 ss
<< "0 + loop *"<<unrollSize
<<"; i < gid0+";
180 ss
<< nCurWindowSize
<<"; i++)\n";
184 ss
<< "0 + loop *"<<unrollSize
<<"; i < ";
185 ss
<< nCurWindowSize
<<"; i++)\n";
188 if (!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
190 ss
<< " int doubleIndex = i+gid0;\n";
194 ss
<< " int doubleIndex = i;\n";
196 CheckSubArgumentIsNan(ss
,vSubArguments
,1+i
);
198 ss
<< 3+(secondParaWidth
-1);
201 ss
<< " if((tmp0 - tmp";
203 ss
<< ")>=0 && intermediate > ( tmp0 -tmp";
207 ss
<< " rowNum = doubleIndex;\n";
208 ss
<< " intermediate = tmp0 - tmp";
215 ss
<< " if(tmp0 == tmp";
217 ss
<< " && rowNum == -1)\n";
219 ss
<< " rowNum = doubleIndex;\n";
224 ss
<< " if(rowNum!=-1)\n";
227 for (int j
= 0; j
< secondParaWidth
; j
++)
230 ss
<< 2+(secondParaWidth
-1);
235 vSubArguments
[1+j
]->GenDeclRef(ss
);
238 ss
<< " return tmp;\n";
245 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
246 ss
<< " if(tmp3 == 1)\n";
248 ss
<< " tmp = tmp1;\n";
251 ss
<< " if(tmp0 == tmp1)\n";
252 ss
<< " tmp = tmp1;\n";
255 ss
<< " return tmp;\n";
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */