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 = NAN;\n";
39 ss
<< " double intermediate = DBL_MAX;\n";
40 ss
<< " int singleIndex = gid0;\n";
41 ss
<< " int rowNum = -1;\n";
42 GenTmpVariables(ss
,vSubArguments
);
44 CheckSubArgumentIsNan(ss
,vSubArguments
,arg
++);
45 int secondParaWidth
= 1;
46 if(vSubArguments
[1]->GetFormulaToken()->GetType() ==
47 formula::svDoubleVectorRef
)
49 FormulaToken
*tmpCur
= vSubArguments
[1]->GetFormulaToken();
50 const formula::DoubleVectorRefToken
*pCurDVR
= dynamic_cast<const
51 formula::DoubleVectorRefToken
*>(tmpCur
);
52 secondParaWidth
= pCurDVR
->GetArrays().size();
55 CheckSubArgumentIsNan(ss
,vSubArguments
,arg
++);
56 if(vSubArguments
.size() == (unsigned int)(3+(secondParaWidth
-1)))
59 ss
<< 3+(secondParaWidth
-1);
64 CheckSubArgumentIsNan(ss
,vSubArguments
,arg
++);
67 if(vSubArguments
[1]->GetFormulaToken()->GetType() ==
68 formula::svDoubleVectorRef
)
70 FormulaToken
*tmpCur
= vSubArguments
[1]->GetFormulaToken();
71 const formula::DoubleVectorRefToken
*pCurDVR
= dynamic_cast<const
72 formula::DoubleVectorRefToken
*>(tmpCur
);
73 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
74 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
75 pCurDVR
->GetRefRowSize() ;
78 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
79 ss
<< " loop = ("<<nCurWindowSize
<<" - gid0)/";
80 ss
<< unrollSize
<<";\n";
82 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
83 ss
<< " loop = ("<<nCurWindowSize
<<" + gid0)/";
84 ss
<< unrollSize
<<";\n";
87 ss
<< " loop = "<<nCurWindowSize
<<"/"<< unrollSize
<<";\n";
90 for(int i
=0;i
<secondParaWidth
;i
++)
93 ss
<< " for ( int j = 0;j< loop; j++)\n";
96 if (!pCurDVR
->IsStartFixed()&& pCurDVR
->IsEndFixed()) {
97 ss
<< "gid0 + j * "<< unrollSize
<<";\n";
99 ss
<< "j * "<< unrollSize
<<";\n";
101 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
103 ss
<< " int doubleIndex = i+gid0;\n";
106 ss
<< " int doubleIndex = i;\n";
109 ss
<< 3+(secondParaWidth
-1);
113 for(int j
=0;j
< unrollSize
;j
++)
115 CheckSubArgumentIsNan(ss
,vSubArguments
,1+i
);
117 ss
<< " if((tmp0 - tmp";
119 ss
<< ")>=0 && intermediate > ( tmp0 -tmp";
123 ss
<< " rowNum = doubleIndex;\n";
124 ss
<< " intermediate = tmp0 - tmp";
129 ss
<< " doubleIndex++;\n";
134 for(int j
=0;j
< unrollSize
;j
++)
136 CheckSubArgumentIsNan(ss
,vSubArguments
,1+i
);
138 ss
<< " if(tmp0 == tmp";
140 ss
<< " && rowNum == -1)\n";
142 ss
<< " rowNum = doubleIndex;\n";
145 ss
<< " doubleIndex++;\n";
150 ss
<< " if(rowNum!=-1)\n";
152 for(int j
=0;j
< secondParaWidth
; j
++)
156 ss
<< 2+(secondParaWidth
-1);
161 vSubArguments
[1+j
]->GenDeclRef(ss
);
165 ss
<< " return tmp;\n";
167 ss
<< " for (int i = ";
168 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
169 ss
<< "gid0 + loop *"<<unrollSize
<<"; i < ";
170 ss
<< nCurWindowSize
<<"; i++)\n";
171 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
172 ss
<< "0 + loop *"<<unrollSize
<<"; i < gid0+";
173 ss
<< nCurWindowSize
<<"; i++)\n";
175 ss
<< "0 + loop *"<<unrollSize
<<"; i < ";
176 ss
<< nCurWindowSize
<<"; i++)\n";
179 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
181 ss
<< " int doubleIndex = i+gid0;\n";
184 ss
<< " int doubleIndex = i;\n";
186 CheckSubArgumentIsNan(ss
,vSubArguments
,1+i
);
188 ss
<< 3+(secondParaWidth
-1);
191 ss
<< " if((tmp0 - tmp";
193 ss
<< ")>=0 && intermediate > ( tmp0 -tmp";
197 ss
<< " rowNum = doubleIndex;\n";
198 ss
<< " intermediate = tmp0 - tmp";
204 ss
<< " if(tmp0 == tmp";
206 ss
<< " && rowNum == -1)\n";
208 ss
<< " rowNum = doubleIndex;\n";
213 ss
<< " if(rowNum!=-1)\n";
216 for(int j
=0;j
< secondParaWidth
; j
++)
220 ss
<< 2+(secondParaWidth
-1);
225 vSubArguments
[1+j
]->GenDeclRef(ss
);
229 ss
<< " return tmp;\n";
237 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
238 ss
<< " if(tmp3 == 1)\n";
240 ss
<< " tmp = tmp1;\n";
243 ss
<< " if(tmp0 == tmp1)\n";
244 ss
<< " tmp = tmp1;\n";
247 ss
<< " return tmp;\n";
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */