fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / opencl / op_logical.cxx
blob405ddc6839146b3d4bbc1aa4b738f69248ca2955
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_logical.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 {
24 void OpAnd::GenSlidingWindowFunction(std::stringstream &ss,
25 const std::string &sSymName, SubArguments &vSubArguments)
27 ss << "\ndouble " << sSymName;
28 ss << "_"<< BinFuncName() <<"(";
29 for (unsigned i = 0; i < vSubArguments.size(); i++)
31 if (i)
32 ss << ",";
33 vSubArguments[i]->GenSlidingWindowDecl(ss);
35 ss << ") {\n";
36 ss << " int gid0 = get_global_id(0);\n";
37 ss << " double t = 1,tmp=0;\n";
38 for(unsigned int j = 0; j< vSubArguments.size(); j++)
40 ss << " double tmp"<<j<<" = 1;\n";
41 FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
42 if(tmpCur0->GetType() == formula::svSingleVectorRef)
44 const formula::SingleVectorRefToken*pCurDVR= static_cast<const
45 formula::SingleVectorRefToken *>(tmpCur0);
46 ss<< " int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
47 ss<< ";\n";
48 ss <<" if(gid0 >= buffer_len"<<j<<" || isNan(";
49 ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
50 ss <<"))\n";
51 ss <<" tmp = 1;\n else\n";
52 ss <<" tmp = ";
53 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
54 ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
56 else if(tmpCur0->GetType() == formula::svDouble)
58 ss <<" tmp = ";
59 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
60 ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
62 else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
64 const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
65 formula::DoubleVectorRefToken *>(tmpCur0);
66 size_t nCurWindowSize = pCurDVR->GetArrayLength() <
67 pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
68 pCurDVR->GetRefRowSize() ;
69 ss << " for(int i = ";
70 if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
71 ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
73 else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
74 ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
76 else{
77 ss << "0; i < " << nCurWindowSize << "; i++) {\n";
79 if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
81 ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
82 ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
83 ss <<")\n";
84 ss <<" tmp = 1;\n else\n";
86 else
88 ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
89 ss <<")||i>="<<pCurDVR->GetArrayLength();
90 ss <<")\n";
91 ss <<" tmp = 1;\n else\n";
93 ss <<" tmp = ";
94 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
95 ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
96 ss <<" }\n";
98 else
100 ss <<" tmp"<<j<<" = ";
101 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
103 ss <<" t = t && tmp"<<j<<";\n";
105 ss << " return t;\n";
106 ss << "}\n";
109 void OpOr::GenSlidingWindowFunction(std::stringstream &ss,
110 const std::string &sSymName, SubArguments &vSubArguments)
112 ss << "\ndouble " << sSymName;
113 ss << "_"<< BinFuncName() <<"(";
114 for (unsigned i = 0; i < vSubArguments.size(); i++)
116 if (i)
117 ss << ",";
118 vSubArguments[i]->GenSlidingWindowDecl(ss);
120 ss << ") {\n";
121 ss << " int gid0 = get_global_id(0);\n";
122 ss << " double t = 0,tmp=0;\n";
123 for(unsigned int j = 0; j< vSubArguments.size(); j++)
125 ss << " double tmp"<<j<<" = 0;\n";
126 FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
127 if(tmpCur0->GetType() == formula::svSingleVectorRef)
129 const formula::SingleVectorRefToken*pCurDVR= static_cast<const
130 formula::SingleVectorRefToken *>(tmpCur0);
131 ss<< " int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
132 ss<< ";\n";
133 ss <<" if(gid0 >= buffer_len"<<j<<" || isNan(";
134 ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
135 ss <<"))\n";
136 ss <<" tmp = 0;\n else\n";
137 ss <<" tmp = ";
138 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
139 ss <<" tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
141 else if(tmpCur0->GetType() == formula::svDouble)
143 ss <<" tmp = ";
144 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
145 ss <<" tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
147 else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
149 const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
150 formula::DoubleVectorRefToken *>(tmpCur0);
151 size_t nCurWindowSize = pCurDVR->GetArrayLength() <
152 pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
153 pCurDVR->GetRefRowSize() ;
154 ss << " for(int i = ";
155 if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
156 ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
158 else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
159 ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
161 else{
162 ss << "0; i < " << nCurWindowSize << "; i++) {\n";
164 if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
166 ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
167 ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
168 ss <<")\n";
169 ss <<" tmp = 0;\n else\n";
171 else
173 ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
174 ss <<")||i>="<<pCurDVR->GetArrayLength();
175 ss <<")\n";
176 ss <<" tmp = 0;\n else\n";
178 ss <<" tmp = ";
179 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
180 ss <<" tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
181 ss <<" }\n";
183 ss <<" t = t || tmp"<<j<<";\n";
185 ss << " return t;\n";
186 ss << "}\n";
188 void OpNot::GenSlidingWindowFunction(std::stringstream &ss,
189 const std::string &sSymName, SubArguments &vSubArguments)
191 ss << "\ndouble " << sSymName;
192 ss << "_"<< BinFuncName() <<"(";
193 for (unsigned i = 0; i < vSubArguments.size(); i++)
195 if (i)
196 ss << ",";
197 vSubArguments[i]->GenSlidingWindowDecl(ss);
199 ss << ") {\n";
200 ss << " int gid0 = get_global_id(0);\n";
201 ss << " double tmp=0;\n";
202 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
203 if(tmpCur0->GetType() == formula::svSingleVectorRef)
205 const formula::SingleVectorRefToken*pCurDVR= static_cast<const
206 formula::SingleVectorRefToken *>(tmpCur0);
207 ss <<" if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
208 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
209 ss <<"))\n";
210 ss <<" tmp = 0;\n else\n";
211 ss <<" tmp = ";
212 ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
213 ss <<" tmp = (tmp == 0.0);\n";
215 else if(tmpCur0->GetType() == formula::svDouble)
217 ss <<" tmp = ";
218 ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
219 ss <<" tmp = (tmp == 0.0);\n";
221 ss << " return tmp;\n";
222 ss << "}\n";
225 void OpXor::GenSlidingWindowFunction(std::stringstream &ss,
226 const std::string &sSymName, SubArguments &vSubArguments)
228 ss << "\ndouble " << sSymName;
229 ss << "_"<< BinFuncName() <<"(";
230 for (unsigned i = 0; i < vSubArguments.size(); i++)
232 if (i)
233 ss << ",";
234 vSubArguments[i]->GenSlidingWindowDecl(ss);
236 ss << ") {\n";
237 ss << " int gid0 = get_global_id(0);\n";
238 ss << " int t = 0,tmp0 = 0;\n";
239 ss << " double tmp = 0;\n";
240 for(unsigned int j = 0; j< vSubArguments.size(); j++)
242 FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
243 if(tmpCur0->GetType() == formula::svSingleVectorRef)
245 const formula::SingleVectorRefToken*pCurDVR= static_cast<const
246 formula::SingleVectorRefToken *>(tmpCur0);
247 ss <<" if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
248 ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
249 ss <<"))\n";
250 ss <<" tmp = 0;\n else\n";
251 ss <<" tmp = ";
252 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
253 ss <<" tmp0 = (tmp != 0);\n";
254 ss <<" t = t ^tmp0;\n";
256 else if(tmpCur0->GetType() == formula::svDouble)
258 ss <<" tmp = ";
259 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
260 ss <<" tmp0 = (tmp != 0);\n";
261 ss <<" t = t ^tmp0;\n";
263 else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
265 const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
266 formula::DoubleVectorRefToken *>(tmpCur0);
267 size_t nCurWindowSize = pCurDVR->GetArrayLength() <
268 pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
269 pCurDVR->GetRefRowSize() ;
270 ss << " for(int i = ";
271 if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
272 ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
274 else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
275 ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
277 else{
278 ss << "0; i < " << nCurWindowSize << "; i++) {\n";
280 if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
282 ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
283 ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
284 ss <<")\n";
285 ss <<" tmp = 0;\n else\n";
287 else
289 ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
290 ss <<")||i>="<<pCurDVR->GetArrayLength();
291 ss <<")\n";
292 ss <<" tmp = 0;\n else\n";
294 ss <<" tmp = ";
295 ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
296 ss <<" tmp0 = (tmp != 0);\n";
297 ss <<" t = t ^tmp0;\n";
298 ss <<" }\n";
301 ss << " return t;\n";
302 ss << "}\n";
304 void OpIf::GenSlidingWindowFunction(std::stringstream &ss,
305 const std::string &sSymName, SubArguments &vSubArguments)
307 ss << "\ndouble " << sSymName;
308 ss << "_"<< BinFuncName() <<"(";
309 for (unsigned i = 0; i < vSubArguments.size(); i++)
311 if (i)
312 ss << ",";
313 vSubArguments[i]->GenSlidingWindowDecl(ss);
315 ss << ") {\n";
316 ss << " int gid0 = get_global_id(0);\n";
318 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
319 if(tmpCur0->GetType() == formula::svDoubleVectorRef)
321 throw UnhandledToken(tmpCur0, "unknown operand for ocPush");
323 else
325 if(vSubArguments.size()==3)
327 ss << " if(isNan(";
328 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
329 ss << ")|| ";
330 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
331 ss << " == 0)\n";
332 ss << " return ";
333 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
334 ss << ";\n";
335 ss << " else";
336 ss <<" return ";
337 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
338 ss <<";\n";
340 if(vSubArguments.size()==2)
342 ss << " if(isNan(";
343 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
344 ss << ")|| ";
345 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
346 ss << " == 0)\n";
347 ss << " return 0;\n";
348 ss << " else";
349 ss <<" return ";
350 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
351 ss <<";\n";
353 if(vSubArguments.size()==1)
355 ss << " if(isNan(";
356 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
357 ss << ")|| ";
358 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
359 ss << " == 0)\n";
360 ss << " return 0;\n";
361 ss << " else";
362 ss <<" return 1;\n";
365 ss << "}\n";
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */