12#include <rtl/math.hxx>
23 const std::string &sSymName,
SubArguments &vSubArguments)
27 ss <<
" int gid0=get_global_id(0);\n";
28 ss <<
" double tmp = CreateDoubleError(NOTAVAILABLE);\n";
29 ss <<
" double intermediate = DBL_MAX;\n";
30 ss <<
" int singleIndex = gid0;\n";
31 ss <<
" int rowNum = -1;\n";
36 int secondParaWidth = 1;
41 int indexArg = vSubArguments.size() - 2;
51 FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
53 const std::vector<VectorRefArray> items = pCurDVR->
GetArrays();
55 secondParaWidth = items.size();
57 if (index < 1 || index > secondParaWidth)
60 if (items[
index - 1].mpStringArray)
62 rtl_uString **pStrings = items[
index - 1].mpStringArray;
65 if (pStrings[
i] !=
nullptr)
73 arg += secondParaWidth;
76 if (vSubArguments.size() ==
static_cast<unsigned int>(3+(secondParaWidth-1)))
79 ss << 3+(secondParaWidth-1);
89 tmpCur = vSubArguments[1]->GetFormulaToken();
92 const int unrollSize = 8;
98 ss <<
"("<<nCurWindowSize<<
" - gid0)/";
99 ss << unrollSize<<
";\n";
103 ss <<
"("<<nCurWindowSize<<
" + gid0)/";
104 ss << unrollSize<<
";\n";
108 ss << nCurWindowSize<<
"/"<< unrollSize<<
";\n";
112 ss << 3+(secondParaWidth-1);
113 ss <<
" == 0) /* unsorted vlookup */\n";
116 for(
int sorted = 0; sorted < 2; ++sorted )
122 ss <<
" { /* sorted vlookup */ \n";
125 ss <<
" for ( int j = 0;j< loop; j++)\n";
130 ss <<
"gid0 + j * "<< unrollSize <<
";\n";
134 ss <<
"j * "<< unrollSize <<
";\n";
138 ss <<
" int doubleIndex = i+gid0;\n";
142 ss <<
" int doubleIndex = i;\n";
145 for (
int j = 0;j < unrollSize; j++)
151 ss <<
" if((tmp0 - tmp1)>=0 && intermediate > (tmp0 -tmp1))\n";
153 ss <<
" rowNum = doubleIndex;\n";
154 ss <<
" intermediate = tmp0 - tmp1;\n";
157 ss <<
" doubleIndex++;\n";
161 ss <<
" if(tmp0 == tmp1)\n";
163 ss <<
" rowNum = doubleIndex;\n";
167 ss <<
" doubleIndex++;\n";
174 ss <<
" if(rowNum!=-1)\n";
176 for (
int j = 0; j < secondParaWidth; j++)
179 ss << 2+(secondParaWidth-1);
184 vSubArguments[1+j]->GenDeclRef(ss);
187 ss <<
" return tmp;\n";
191 ss << 3+(secondParaWidth-1);
192 ss <<
" == 0) /* unsorted vlookup */\n";
195 for(
int sorted = 0; sorted < 2; ++sorted )
201 ss <<
" { /* sorted vlookup */ \n";
204 ss <<
" for (int i = ";
207 ss <<
"gid0 + loop *"<<unrollSize<<
"; i < ";
208 ss << nCurWindowSize <<
"; i++)\n";
212 ss <<
"0 + loop *"<<unrollSize<<
"; i < gid0+";
213 ss << nCurWindowSize <<
"; i++)\n";
217 ss <<
"0 + loop *"<<unrollSize<<
"; i < ";
218 ss << nCurWindowSize <<
"; i++)\n";
223 ss <<
" int doubleIndex = i+gid0;\n";
227 ss <<
" int doubleIndex = i;\n";
233 ss <<
" if((tmp0 - tmp1)>=0 && intermediate > (tmp0 -tmp1))\n";
235 ss <<
" rowNum = doubleIndex;\n";
236 ss <<
" intermediate = tmp0 - tmp1;\n";
241 ss <<
" if(tmp0 == tmp1)\n";
243 ss <<
" rowNum = doubleIndex;\n";
251 ss <<
" if(rowNum!=-1)\n";
254 for (
int j = 0; j < secondParaWidth; j++)
257 ss << 2+(secondParaWidth-1);
262 vSubArguments[1+j]->GenDeclRef(ss);
265 ss <<
" return tmp;\n";
271 ss <<
" if(tmp3 == 1)\n";
273 ss <<
" tmp = tmp1;\n";
276 ss <<
" if(tmp0 == tmp1)\n";
277 ss <<
" tmp = tmp1;\n";
280 ss <<
" return tmp;\n";
static void CheckSubArgumentIsNan(outputstream &ss, SubArguments &vSubArguments, int argumentNum)
static void GenTmpVariables(outputstream &ss, const SubArguments &vSubArguments)
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
void GenerateFunctionDeclaration(const std::string &sSymName, SubArguments &vSubArguments, outputstream &ss)
std::vector< DynamicKernelArgumentRef > SubArguments