sc/source/core/opencl/op_spreadsheet.cxx | 213 +++++++++++++++++-------------- 1 file changed, 120 insertions(+), 93 deletions(-)
New commits: commit 73f9048c4038707258ee42acaf1946d90df6270a Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Tue Aug 30 12:19:46 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Aug 30 15:52:21 2022 +0200 bail out in opencl unsorted vlookup as soon as a match is found Change-Id: Ic2eda985f93c4eac26e08251c5bdbc36d7c03708 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139028 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/source/core/opencl/op_spreadsheet.cxx b/sc/source/core/opencl/op_spreadsheet.cxx index 09ef4e65ef65..4679b2d01f30 100644 --- a/sc/source/core/opencl/op_spreadsheet.cxx +++ b/sc/source/core/opencl/op_spreadsheet.cxx @@ -165,9 +165,10 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss, } else { - ss << " if(tmp0 == tmp1 && rowNum == -1)\n"; + ss << " if(tmp0 == tmp1)\n"; ss << " {\n"; ss << " rowNum = doubleIndex;\n"; + ss << " break;\n"; ss << " }\n"; ss << " i++;\n"; ss << " doubleIndex++;\n"; @@ -244,9 +245,10 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss, } else { - ss << " if(tmp0 == tmp1 && rowNum == -1)\n"; + ss << " if(tmp0 == tmp1)\n"; ss << " {\n"; ss << " rowNum = doubleIndex;\n"; + ss << " break;\n"; ss << " }\n"; } ss << " }\n\n"; commit ad2b6f1623300d28723d66fa0ac40530498acc77 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Tue Aug 30 12:19:41 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Aug 30 15:52:05 2022 +0200 opencl vlookup, move constant condition out of a loop There's no need to check in every loop iteration if the vlookup should be sorted or unsorted, and this needless branching slows the execution. Change-Id: I4f3072ddeaf54269cfec51043e84adb2571f0f73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139027 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/source/core/opencl/op_spreadsheet.cxx b/sc/source/core/opencl/op_spreadsheet.cxx index d088b718b442..09ef4e65ef65 100644 --- a/sc/source/core/opencl/op_spreadsheet.cxx +++ b/sc/source/core/opencl/op_spreadsheet.cxx @@ -96,76 +96,85 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss, tmpCur = vSubArguments[1]->GetFormulaToken(); pCurDVR = static_cast<const formula::DoubleVectorRefToken *>(tmpCur); size_t nCurWindowSize = std::min(pCurDVR->GetArrayLength(), pCurDVR->GetRefRowSize()); - int unrollSize = 8; - ss << " int loop;\n"; + const int unrollSize = 8; + + ss << "\n"; + ss << " int loop = "; if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) { - ss << " loop = ("<<nCurWindowSize<<" - gid0)/"; + ss << "("<<nCurWindowSize<<" - gid0)/"; ss << unrollSize<<";\n"; - } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) { - ss << " loop = ("<<nCurWindowSize<<" + gid0)/"; + ss << "("<<nCurWindowSize<<" + gid0)/"; ss << unrollSize<<";\n"; - } else { - ss << " loop = "<<nCurWindowSize<<"/"<< unrollSize<<";\n"; + ss << nCurWindowSize<<"/"<< unrollSize<<";\n"; } - ss << " for ( int j = 0;j< loop; j++)\n"; - ss << " {\n"; - ss << " int i = "; - if (!pCurDVR->IsStartFixed()&& pCurDVR->IsEndFixed()) - { - ss << "gid0 + j * "<< unrollSize <<";\n"; - } - else - { - ss << "j * "<< unrollSize <<";\n"; - } - if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) - { - ss << " int doubleIndex = i+gid0;\n"; - } - else - { - ss << " int doubleIndex = i;\n"; - } - ss << " if(tmp"; + ss << " if(tmp"; ss << 3+(secondParaWidth-1); - ss << " == 1)\n"; - ss << " {\n"; + ss << " == 0) /* unsorted vlookup */\n"; + ss << " {\n"; - for (int j = 0;j < unrollSize; j++) + for( int sorted = 0; sorted < 2; ++sorted ) // sorted vs unsorted vlookup cases { - CheckSubArgumentIsNan(ss,vSubArguments,1); + if( sorted == 1 ) + { + ss << " }\n"; + ss << " else\n"; + ss << " { /* sorted vlookup */ \n"; + } - ss << " if((tmp0 - tmp1)>=0 && intermediate > (tmp0 -tmp1))\n"; - ss << " {\n"; - ss << " rowNum = doubleIndex;\n"; - ss << " intermediate = tmp0 - tmp1;\n"; - ss << " }\n"; - ss << " i++;\n"; - ss << " doubleIndex++;\n"; - } + ss << " for ( int j = 0;j< loop; j++)\n"; + ss << " {\n"; + ss << " int i = "; + if (!pCurDVR->IsStartFixed()&& pCurDVR->IsEndFixed()) + { + ss << "gid0 + j * "<< unrollSize <<";\n"; + } + else + { + ss << "j * "<< unrollSize <<";\n"; + } + if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) + { + ss << " int doubleIndex = i+gid0;\n"; + } + else + { + ss << " int doubleIndex = i;\n"; + } - ss << " }else\n"; - ss << " {\n"; - for (int j = 0; j < unrollSize; j++) - { - CheckSubArgumentIsNan(ss,vSubArguments,1); + for (int j = 0;j < unrollSize; j++) + { + CheckSubArgumentIsNan(ss,vSubArguments,1); - ss << " if(tmp0 == tmp1 && rowNum == -1)\n"; - ss << " {\n"; - ss << " rowNum = doubleIndex;\n"; - ss << " }\n"; - ss << " i++;\n"; - ss << " doubleIndex++;\n"; + if( sorted == 1 ) + { + ss << " if((tmp0 - tmp1)>=0 && intermediate > (tmp0 -tmp1))\n"; + ss << " {\n"; + ss << " rowNum = doubleIndex;\n"; + ss << " intermediate = tmp0 - tmp1;\n"; + ss << " }\n"; + ss << " i++;\n"; + ss << " doubleIndex++;\n"; + } + else + { + ss << " if(tmp0 == tmp1 && rowNum == -1)\n"; + ss << " {\n"; + ss << " rowNum = doubleIndex;\n"; + ss << " }\n"; + ss << " i++;\n"; + ss << " doubleIndex++;\n"; + } + } + ss << " }\n\n"; } - ss << " }\n\n"; ss << " }\n"; ss << " if(rowNum!=-1)\n"; @@ -183,51 +192,67 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss, } ss << " return tmp;\n"; ss << " }\n"; - ss << " for (int i = "; - if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) - { - ss << "gid0 + loop *"<<unrollSize<<"; i < "; - ss << nCurWindowSize <<"; i++)\n"; - } - else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) - { - ss << "0 + loop *"<<unrollSize<<"; i < gid0+"; - ss << nCurWindowSize <<"; i++)\n"; - } - else - { - ss << "0 + loop *"<<unrollSize<<"; i < "; - ss << nCurWindowSize <<"; i++)\n"; - } + + ss << " if(tmp"; + ss << 3+(secondParaWidth-1); + ss << " == 0) /* unsorted vlookup */\n"; ss << " {\n"; - if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) - { - ss << " int doubleIndex = i+gid0;\n"; - } - else + + for( int sorted = 0; sorted < 2; ++sorted ) // sorted vs unsorted vlookup cases { - ss << " int doubleIndex = i;\n"; + if( sorted == 1 ) + { + ss << " }\n"; + ss << " else\n"; + ss << " { /* sorted vlookup */ \n"; + } + + ss << " for (int i = "; + if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) + { + ss << "gid0 + loop *"<<unrollSize<<"; i < "; + ss << nCurWindowSize <<"; i++)\n"; + } + else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) + { + ss << "0 + loop *"<<unrollSize<<"; i < gid0+"; + ss << nCurWindowSize <<"; i++)\n"; + } + else + { + ss << "0 + loop *"<<unrollSize<<"; i < "; + ss << nCurWindowSize <<"; i++)\n"; + } + ss << " {\n"; + if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) + { + ss << " int doubleIndex = i+gid0;\n"; + } + else + { + ss << " int doubleIndex = i;\n"; + } + CheckSubArgumentIsNan(ss,vSubArguments,1); + + if( sorted == 1 ) + { + ss << " if((tmp0 - tmp1)>=0 && intermediate > (tmp0 -tmp1))\n"; + ss << " {\n"; + ss << " rowNum = doubleIndex;\n"; + ss << " intermediate = tmp0 - tmp1;\n"; + ss << " }\n"; + } + else + { + ss << " if(tmp0 == tmp1 && rowNum == -1)\n"; + ss << " {\n"; + ss << " rowNum = doubleIndex;\n"; + ss << " }\n"; + } + ss << " }\n\n"; } - CheckSubArgumentIsNan(ss,vSubArguments,1); - ss << " if(tmp"; - ss << 3+(secondParaWidth-1); - ss << " == 1)\n"; - ss << " {\n"; - ss << " if((tmp0 - tmp1)>=0 && intermediate > (tmp0 -tmp1))\n"; - ss << " {\n"; - ss << " rowNum = doubleIndex;\n"; - ss << " intermediate = tmp0 - tmp1;\n"; - ss << " }\n"; - ss << " }\n"; - ss << " else\n"; - ss << " {\n"; - ss << " if(tmp0 == tmp1 && rowNum == -1)\n"; - ss << " {\n"; - ss << " rowNum = doubleIndex;\n"; - ss << " }\n"; - ss << " }\n"; - - ss << " }\n\n"; + + ss << " }\n"; ss << " if(rowNum!=-1)\n"; ss << " {\n";