fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / opencl / op_spreadsheet.cxx
blob10ce77e14e83403cf945ba593c563ad37d4d371e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
19 #include <sstream>
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++)
32 if (i)
33 ss << ",";
34 vSubArguments[i]->GenSlidingWindowDecl(ss);
36 ss << ")\n {\n";
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);
44 int arg=0;
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)))
60 ss << " double tmp";
61 ss << 3+(secondParaWidth-1);
62 ss << "= 1;\n";
64 else
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() ;
74 int unrollSize = 8;
75 ss << " int loop;\n";
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";
88 else
90 ss << " loop = "<<nCurWindowSize<<"/"<< unrollSize<<";\n";
93 for (int i = 0; i < secondParaWidth; i++)
95 ss << " for ( int j = 0;j< loop; j++)\n";
96 ss << " {\n";
97 ss << " int i = ";
98 if (!pCurDVR->IsStartFixed()&& pCurDVR->IsEndFixed())
100 ss << "gid0 + j * "<< unrollSize <<";\n";
102 else
104 ss << "j * "<< unrollSize <<";\n";
106 if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
108 ss << " int doubleIndex = i+gid0;\n";
110 else
112 ss << " int doubleIndex = i;\n";
114 ss << " if(tmp";
115 ss << 3+(secondParaWidth-1);
116 ss << " == 1)\n";
117 ss << " {\n";
119 for (int j = 0;j < unrollSize; j++)
121 CheckSubArgumentIsNan(ss,vSubArguments,1+i);
123 ss << " if((tmp0 - tmp";
124 ss << 1+i;
125 ss << ")>=0 && intermediate > ( tmp0 -tmp";
126 ss << 1+i;
127 ss << "))\n";
128 ss << " {\n";
129 ss << " rowNum = doubleIndex;\n";
130 ss << " intermediate = tmp0 - tmp";
131 ss << 1+i;
132 ss << ";\n";
133 ss << " }\n";
134 ss << " i++;\n";
135 ss << " doubleIndex++;\n";
138 ss << " }else\n";
139 ss << " {\n";
140 for (int j = 0; j < unrollSize; j++)
142 CheckSubArgumentIsNan(ss,vSubArguments,1+i);
144 ss << " if(tmp0 == tmp";
145 ss << 1+i;
146 ss << " && rowNum == -1)\n";
147 ss << " {\n";
148 ss << " rowNum = doubleIndex;\n";
149 ss << " }\n";
150 ss << " i++;\n";
151 ss << " doubleIndex++;\n";
153 ss << " }\n\n";
155 ss << " }\n";
156 ss << " if(rowNum!=-1)\n";
157 ss << " {\n";
158 for (int j = 0; j < secondParaWidth; j++)
160 ss << " if(tmp";
161 ss << 2+(secondParaWidth-1);
162 ss << " == ";
163 ss << j+1;
164 ss << ")\n";
165 ss << " tmp = ";
166 vSubArguments[1+j]->GenDeclRef(ss);
167 ss << "[rowNum];\n";
169 ss << " return tmp;\n";
170 ss << " }\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";
182 else
184 ss << "0 + loop *"<<unrollSize<<"; i < ";
185 ss << nCurWindowSize <<"; i++)\n";
187 ss << " {\n";
188 if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
190 ss << " int doubleIndex = i+gid0;\n";
192 else
194 ss << " int doubleIndex = i;\n";
196 CheckSubArgumentIsNan(ss,vSubArguments,1+i);
197 ss << " if(tmp";
198 ss << 3+(secondParaWidth-1);
199 ss << " == 1)\n";
200 ss << " {\n";
201 ss << " if((tmp0 - tmp";
202 ss << 1+i;
203 ss << ")>=0 && intermediate > ( tmp0 -tmp";
204 ss << 1+i;
205 ss << "))\n";
206 ss << " {\n";
207 ss << " rowNum = doubleIndex;\n";
208 ss << " intermediate = tmp0 - tmp";
209 ss << 1+i;
210 ss << ";\n";
211 ss << " }\n";
212 ss << " }\n";
213 ss << " else\n";
214 ss << " {\n";
215 ss << " if(tmp0 == tmp";
216 ss << 1+i;
217 ss << " && rowNum == -1)\n";
218 ss << " {\n";
219 ss << " rowNum = doubleIndex;\n";
220 ss << " }\n";
221 ss << " }\n";
223 ss << " }\n\n";
224 ss << " if(rowNum!=-1)\n";
225 ss << " {\n";
227 for (int j = 0; j < secondParaWidth; j++)
229 ss << " if(tmp";
230 ss << 2+(secondParaWidth-1);
231 ss << " == ";
232 ss << j+1;
233 ss << ")\n";
234 ss << " tmp = ";
235 vSubArguments[1+j]->GenDeclRef(ss);
236 ss << "[rowNum];\n";
238 ss << " return tmp;\n";
239 ss << " }\n";
243 else
245 CheckSubArgumentIsNan(ss,vSubArguments,1);
246 ss << " if(tmp3 == 1)\n";
247 ss << " {\n";
248 ss << " tmp = tmp1;\n";
249 ss << " }else\n";
250 ss << " {\n";
251 ss << " if(tmp0 == tmp1)\n";
252 ss << " tmp = tmp1;\n";
253 ss << " }\n";
255 ss << " return tmp;\n";
256 ss << "}";
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */